|
|
@@ -210,14 +210,12 @@ void Print_Register_Contents(uint8_t address)
|
|
210
|
210
|
|
|
211
|
211
|
uint8_t Read_NRF_Status_Register(void)
|
|
212
|
212
|
{
|
|
213
|
|
- NRF_CSN_PORT &= ~(1 << NRF_CSN_PIN); // Start the transmission
|
|
214
|
|
- SPDR = 0XFF;
|
|
215
|
|
-
|
|
216
|
|
- while(!(SPSR & (1<<SPIF))); // Wait for transmission complete
|
|
|
213
|
+ uint8_t registerContents;
|
|
217
|
214
|
|
|
218
|
|
- NRF_CSN_PORT |= (1 << NRF_CSN_PIN); // Stop the transmission
|
|
219
|
|
-
|
|
220
|
|
- return SPDR;
|
|
|
215
|
+ SPI_Start_Transmission(&NRF_CSN_PORT, NRF_CSN_PIN);
|
|
|
216
|
+ registerContents = SPI_Transfer_Byte(0x00);
|
|
|
217
|
+ SPI_Stop_Transmission(&NRF_CSN_PORT, NRF_CSN_PIN);
|
|
|
218
|
+ return registerContents;
|
|
221
|
219
|
}
|
|
222
|
220
|
|
|
223
|
221
|
uint8_t Read_NRF_Register(uint8_t address, uint8_t * registerContents)
|
|
|
@@ -236,68 +234,57 @@ uint8_t Read_NRF_Register(uint8_t address, uint8_t * registerContents)
|
|
236
|
234
|
}
|
|
237
|
235
|
|
|
238
|
236
|
/* First write the address */
|
|
239
|
|
- NRF_CSN_PORT &= ~(1 << NRF_CSN_PIN); // Start the transmission
|
|
240
|
|
- SPDR = address;
|
|
|
237
|
+ SPI_Start_Transmission(&NRF_CSN_PORT, NRF_CSN_PIN);
|
|
241
|
238
|
|
|
242
|
|
- while(!(SPSR & (1<<SPIF))); // Wait for transmission complete
|
|
|
239
|
+
|
|
|
240
|
+ SPI_Transfer_Byte(address);
|
|
243
|
241
|
|
|
244
|
242
|
/* Read the register bytes */
|
|
245
|
243
|
for (uint8_t i = 0; i < numberOfBytes; i++)
|
|
246
|
244
|
{
|
|
247
|
245
|
/* Write dummy data to shift in the register content */
|
|
248
|
|
- SPDR = 0x0;
|
|
249
|
|
- while(!(SPSR & (1<<SPIF))); // Wait for transmission complete
|
|
250
|
|
- registerContents[i] = SPDR;
|
|
|
246
|
+ registerContents[i] = SPI_Transfer_Byte(0x0);
|
|
251
|
247
|
}
|
|
252
|
248
|
|
|
253
|
|
- NRF_CSN_PORT |= (1 << NRF_CSN_PIN); // Stop the transmission
|
|
|
249
|
+ SPI_Stop_Transmission(&NRF_CSN_PORT, NRF_CSN_PIN);
|
|
254
|
250
|
|
|
255
|
|
- // TODO: registers with more than one byte
|
|
256
|
251
|
return numberOfBytes;
|
|
257
|
252
|
}
|
|
258
|
253
|
|
|
259
|
254
|
void Write_NRF_Register(uint8_t address, uint8_t registerContents)
|
|
260
|
255
|
{
|
|
261
|
256
|
/* First write the write command with the address */
|
|
262
|
|
- NRF_CSN_PORT &= ~(1 << NRF_CSN_PIN); // Start the transmission
|
|
263
|
|
- SPDR = address | 0x20;
|
|
264
|
|
-
|
|
265
|
|
- while(!(SPSR & (1<<SPIF))); // Wait for transmission complete
|
|
|
257
|
+ SPI_Start_Transmission(&NRF_CSN_PORT, NRF_CSN_PIN);
|
|
266
|
258
|
|
|
267
|
|
- /* Write the data byte */
|
|
268
|
|
- SPDR = registerContents;
|
|
|
259
|
+ SPI_Transfer_Byte(address | 0x20);
|
|
269
|
260
|
|
|
270
|
|
- while(!(SPSR & (1<<SPIF))); // Wait for transmission complete
|
|
|
261
|
+ /* Write the data byte */
|
|
|
262
|
+ SPI_Transfer_Byte(registerContents);
|
|
271
|
263
|
|
|
272
|
|
- NRF_CSN_PORT |= (1 << NRF_CSN_PIN); // Stop the transmission
|
|
|
264
|
+ SPI_Stop_Transmission(&NRF_CSN_PORT, NRF_CSN_PIN);
|
|
273
|
265
|
}
|
|
274
|
266
|
|
|
275
|
267
|
// TODO: clean up functions
|
|
276
|
268
|
void Send_Activate_Command(void)
|
|
277
|
269
|
{
|
|
278
|
270
|
/* First write the write command with the address */
|
|
279
|
|
- NRF_CSN_PORT &= ~(1 << NRF_CSN_PIN); // Start the transmission
|
|
280
|
|
- SPDR = 0x50;
|
|
281
|
|
-
|
|
282
|
|
- while(!(SPSR & (1<<SPIF))); // Wait for transmission complete
|
|
|
271
|
+ SPI_Start_Transmission(&NRF_CSN_PORT, NRF_CSN_PIN);
|
|
|
272
|
+ SPI_Transfer_Byte(0x50);
|
|
283
|
273
|
|
|
284
|
274
|
/* Write the data byte */
|
|
285
|
|
- SPDR = 0x73;
|
|
286
|
|
-
|
|
287
|
|
- while(!(SPSR & (1<<SPIF))); // Wait for transmission complete
|
|
|
275
|
+ SPI_Transfer_Byte(0x73);
|
|
288
|
276
|
|
|
289
|
|
- NRF_CSN_PORT |= (1 << NRF_CSN_PIN); // Stop the transmission
|
|
|
277
|
+ SPI_Stop_Transmission(&NRF_CSN_PORT, NRF_CSN_PIN);
|
|
290
|
278
|
}
|
|
291
|
279
|
|
|
292
|
280
|
void Send_TX_Flush_Command(void)
|
|
293
|
281
|
{
|
|
294
|
282
|
/* First write the write command with the address */
|
|
295
|
|
- NRF_CSN_PORT &= ~(1 << NRF_CSN_PIN); // Start the transmission
|
|
296
|
|
- SPDR = 0xE1;
|
|
297
|
|
-
|
|
298
|
|
- while(!(SPSR & (1<<SPIF))); // Wait for transmission complete
|
|
|
283
|
+ SPI_Start_Transmission(&NRF_CSN_PORT, NRF_CSN_PIN);
|
|
299
|
284
|
|
|
300
|
|
- NRF_CSN_PORT |= (1 << NRF_CSN_PIN); // Stop the transmission
|
|
|
285
|
+ SPI_Transfer_Byte(0xE1);
|
|
|
286
|
+
|
|
|
287
|
+ SPI_Stop_Transmission(&NRF_CSN_PORT, NRF_CSN_PIN);
|
|
301
|
288
|
}
|
|
302
|
289
|
|
|
303
|
290
|
|