LibDriver NRF905
Loading...
Searching...
No Matches
driver_nrf905_send_receive_test.c
Go to the documentation of this file.
1
36
38
39static nrf905_handle_t gs_handle;
40static volatile uint8_t gs_rx_done;
41
50{
51 if (nrf905_irq_handler(&gs_handle) != 0)
52 {
53 return 1;
54 }
55 else
56 {
57 return 0;
58 }
59}
60
68static void a_callback(uint8_t type, uint8_t *buf, uint8_t len)
69{
70 switch (type)
71 {
72 case NRF905_STATUS_AM :
73 {
74 nrf905_interface_debug_print("nrf905: address match.\n");
75
76 break;
77 }
79 {
80 nrf905_interface_debug_print("nrf905: tx done.\n");
81
82 break;
83 }
85 {
86 uint8_t i;
87
88 nrf905_interface_debug_print("nrf905: irq receive with length %d.\n", len);
89 for (i = 0; i < len; i++)
90 {
91 nrf905_interface_debug_print("0x%02X ", buf[i]);
92 }
94 gs_rx_done = 1;
95
96 break;
97 }
98 default :
99 {
100 nrf905_interface_debug_print("nrf905: unknown code.\n");
101
102 break;
103 }
104 }
105}
106
114uint8_t nrf905_send_test(void)
115{
116 uint8_t i;
117 uint8_t res;
118 uint16_t reg;
119 uint8_t addr[4] = {0xE7, 0xE7, 0xE7, 0xE7};
120 uint8_t buffer[32];
121 nrf905_info_t info;
122
123 /* link function */
142
143 /* get information */
144 res = nrf905_info(&info);
145 if (res != 0)
146 {
147 nrf905_interface_debug_print("nrf905: get info failed.\n");
148
149 return 1;
150 }
151 else
152 {
153 /* print chip info */
154 nrf905_interface_debug_print("nrf905: chip is %s.\n", info.chip_name);
155 nrf905_interface_debug_print("nrf905: manufacturer is %s.\n", info.manufacturer_name);
156 nrf905_interface_debug_print("nrf905: interface is %s.\n", info.interface);
157 nrf905_interface_debug_print("nrf905: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
158 nrf905_interface_debug_print("nrf905: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
159 nrf905_interface_debug_print("nrf905: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
160 nrf905_interface_debug_print("nrf905: max current is %0.2fmA.\n", info.max_current_ma);
161 nrf905_interface_debug_print("nrf905: max temperature is %0.1fC.\n", info.temperature_max);
162 nrf905_interface_debug_print("nrf905: min temperature is %0.1fC.\n", info.temperature_min);
163 }
164
165 /* start send test */
166 nrf905_interface_debug_print("nrf905: start send test.\n");
167
168 /* init */
169 res = nrf905_init(&gs_handle);
170 if (res != 0)
171 {
172 nrf905_interface_debug_print("nrf905: init failed.\n");
173
174 return 1;
175 }
176
177 /* power up the chip */
178 res = nrf905_set_power_up(&gs_handle, NRF905_BOOL_TRUE);
179 if (res != 0)
180 {
181 nrf905_interface_debug_print("nrf905: power up failed.\n");
182 (void)nrf905_deinit(&gs_handle);
183
184 return 1;
185 }
186
187 /* disable the chip */
188 res = nrf905_set_enable(&gs_handle, NRF905_BOOL_FALSE);
189 if (res != 0)
190 {
191 nrf905_interface_debug_print("nrf905: set enable failed.\n");
192 (void)nrf905_deinit(&gs_handle);
193
194 return 1;
195 }
196
197 /* set pll mode 433MHz */
199 if (res != 0)
200 {
201 nrf905_interface_debug_print("nrf905: set pll mode failed.\n");
202 (void)nrf905_deinit(&gs_handle);
203
204 return 1;
205 }
206
207 /* set +10dBm */
209 if (res != 0)
210 {
211 nrf905_interface_debug_print("nrf905: set output power failed.\n");
212 (void)nrf905_deinit(&gs_handle);
213
214 return 1;
215 }
216
217 /* normal rx mode */
218 res = nrf905_set_rx_mode(&gs_handle, NRF905_RX_MODE_NORMAL);
219 if (res != 0)
220 {
221 nrf905_interface_debug_print("nrf905: set rx mode failed.\n");
222 (void)nrf905_deinit(&gs_handle);
223
224 return 1;
225 }
226
227 /* disable the auto retransmit */
229 if (res != 0)
230 {
231 nrf905_interface_debug_print("nrf905: set auto retransmit failed.\n");
232 (void)nrf905_deinit(&gs_handle);
233
234 return 1;
235 }
236
237 /* set 4 byte */
239 if (res != 0)
240 {
241 nrf905_interface_debug_print("nrf905: set rx address width failed.\n");
242 (void)nrf905_deinit(&gs_handle);
243
244 return 1;
245 }
246
247 /* set 4 byte */
249 if (res != 0)
250 {
251 nrf905_interface_debug_print("nrf905: set tx address width failed.\n");
252 (void)nrf905_deinit(&gs_handle);
253
254 return 1;
255 }
256
257 /* 32 bytes */
258 res = nrf905_set_rx_payload_width(&gs_handle, 32);
259 if (res != 0)
260 {
261 nrf905_interface_debug_print("nrf905: set rx payload width failed.\n");
262 (void)nrf905_deinit(&gs_handle);
263
264 return 1;
265 }
266
267 /* 32 bytes */
268 res = nrf905_set_tx_payload_width(&gs_handle, 32);
269 if (res != 0)
270 {
271 nrf905_interface_debug_print("nrf905: set tx payload width failed.\n");
272 (void)nrf905_deinit(&gs_handle);
273
274 return 1;
275 }
276
277 /* set the rx address */
278 res = nrf905_set_rx_address(&gs_handle, addr);
279 if (res != 0)
280 {
281 nrf905_interface_debug_print("nrf905: set rx address failed.\n");
282 (void)nrf905_deinit(&gs_handle);
283
284 return 1;
285 }
286
287 /* set 500KHz */
289 if (res != 0)
290 {
291 nrf905_interface_debug_print("nrf905: set output clock frequency failed.\n");
292 (void)nrf905_deinit(&gs_handle);
293
294 return 1;
295 }
296
297 /* disable the output clock */
299 if (res != 0)
300 {
301 nrf905_interface_debug_print("nrf905: set output clock failed.\n");
302 (void)nrf905_deinit(&gs_handle);
303
304 return 1;
305 }
306
307 /* 16MHz */
309 if (res != 0)
310 {
311 nrf905_interface_debug_print("nrf905: set crystal oscillator frequency failed.\n");
312 (void)nrf905_deinit(&gs_handle);
313
314 return 1;
315 }
316
317 /* enable the crc */
318 res = nrf905_set_crc(&gs_handle, NRF905_BOOL_TRUE);
319 if (res != 0)
320 {
321 nrf905_interface_debug_print("nrf905: set crc failed.\n");
322 (void)nrf905_deinit(&gs_handle);
323
324 return 1;
325 }
326
327 /* set crc mode 8 */
328 res = nrf905_set_crc_mode(&gs_handle, NRF905_CRC_MODE_8);
329 if (res != 0)
330 {
331 nrf905_interface_debug_print("nrf905: set crc mode failed.\n");
332 (void)nrf905_deinit(&gs_handle);
333
334 return 1;
335 }
336
337 /* 433 MHz */
338 res = nrf905_frequency_convert_to_register(&gs_handle, 433.2f, &reg);
339 if (res != 0)
340 {
341 nrf905_interface_debug_print("nrf905: frequency convert to register failed.\n");
342 (void)nrf905_deinit(&gs_handle);
343
344 return 1;
345 }
346
347 /* set the frequency */
348 res = nrf905_set_frequency(&gs_handle, reg);
349 if (res != 0)
350 {
351 nrf905_interface_debug_print("nrf905: set frequency failed.\n");
352 (void)nrf905_deinit(&gs_handle);
353
354 return 1;
355 }
356
357 /* write the conf */
358 res = nrf905_write_conf(&gs_handle);
359 if (res != 0)
360 {
361 nrf905_interface_debug_print("nrf905: write conf failed.\n");
362 (void)nrf905_deinit(&gs_handle);
363
364 return 1;
365 }
366
367 /* set tx address */
368 res = nrf905_set_tx_address(&gs_handle, addr, 4);
369 if (res != 0)
370 {
371 nrf905_interface_debug_print("nrf905: set tx address failed.\n");
372 (void)nrf905_deinit(&gs_handle);
373
374 return 1;
375 }
376
377 /* send data */
378 for (i = 0; i < 32; i++)
379 {
380 buffer[i] = i;
381 }
382 res = nrf905_send(&gs_handle, buffer, 32);
383 if (res != 0)
384 {
385 nrf905_interface_debug_print("nrf905: send failed.\n");
386 (void)nrf905_deinit(&gs_handle);
387
388 return 1;
389 }
390 else
391 {
392 nrf905_interface_debug_print("nrf905: send successful.\n");
393 }
394
395 /* finish send test */
396 nrf905_interface_debug_print("nrf905: finish send test.\n");
397 (void)nrf905_deinit(&gs_handle);
398
399 return 0;
400}
401
410{
411 uint8_t res;
412 uint16_t reg;
413 uint32_t timeout;
414 uint8_t addr[4] = {0xE7, 0xE7, 0xE7, 0xE7};
415 nrf905_info_t info;
416
417 /* link function */
435 DRIVER_NRF905_LINK_RECEIVE_CALLBACK(&gs_handle, a_callback);
436
437 /* get information */
438 res = nrf905_info(&info);
439 if (res != 0)
440 {
441 nrf905_interface_debug_print("nrf905: get info failed.\n");
442
443 return 1;
444 }
445 else
446 {
447 /* print chip info */
448 nrf905_interface_debug_print("nrf905: chip is %s.\n", info.chip_name);
449 nrf905_interface_debug_print("nrf905: manufacturer is %s.\n", info.manufacturer_name);
450 nrf905_interface_debug_print("nrf905: interface is %s.\n", info.interface);
451 nrf905_interface_debug_print("nrf905: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
452 nrf905_interface_debug_print("nrf905: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
453 nrf905_interface_debug_print("nrf905: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
454 nrf905_interface_debug_print("nrf905: max current is %0.2fmA.\n", info.max_current_ma);
455 nrf905_interface_debug_print("nrf905: max temperature is %0.1fC.\n", info.temperature_max);
456 nrf905_interface_debug_print("nrf905: min temperature is %0.1fC.\n", info.temperature_min);
457 }
458
459 /* start receive test */
460 nrf905_interface_debug_print("nrf905: start receive test.\n");
461
462 /* init */
463 res = nrf905_init(&gs_handle);
464 if (res != 0)
465 {
466 nrf905_interface_debug_print("nrf905: init failed.\n");
467
468 return 1;
469 }
470
471 /* power up the chip */
472 res = nrf905_set_power_up(&gs_handle, NRF905_BOOL_TRUE);
473 if (res != 0)
474 {
475 nrf905_interface_debug_print("nrf905: power up failed.\n");
476 (void)nrf905_deinit(&gs_handle);
477
478 return 1;
479 }
480
481 /* disable the chip */
482 res = nrf905_set_enable(&gs_handle, NRF905_BOOL_FALSE);
483 if (res != 0)
484 {
485 nrf905_interface_debug_print("nrf905: set enable failed.\n");
486 (void)nrf905_deinit(&gs_handle);
487
488 return 1;
489 }
490
491 /* set pll mode 433MHz */
493 if (res != 0)
494 {
495 nrf905_interface_debug_print("nrf905: set pll mode failed.\n");
496 (void)nrf905_deinit(&gs_handle);
497
498 return 1;
499 }
500
501 /* set +10dBm */
503 if (res != 0)
504 {
505 nrf905_interface_debug_print("nrf905: set output power failed.\n");
506 (void)nrf905_deinit(&gs_handle);
507
508 return 1;
509 }
510
511 /* normal rx mode */
512 res = nrf905_set_rx_mode(&gs_handle, NRF905_RX_MODE_NORMAL);
513 if (res != 0)
514 {
515 nrf905_interface_debug_print("nrf905: set rx mode failed.\n");
516 (void)nrf905_deinit(&gs_handle);
517
518 return 1;
519 }
520
521 /* disable the auto retransmit */
523 if (res != 0)
524 {
525 nrf905_interface_debug_print("nrf905: set auto retransmit failed.\n");
526 (void)nrf905_deinit(&gs_handle);
527
528 return 1;
529 }
530
531 /* set 4 byte */
533 if (res != 0)
534 {
535 nrf905_interface_debug_print("nrf905: set rx address width failed.\n");
536 (void)nrf905_deinit(&gs_handle);
537
538 return 1;
539 }
540
541 /* set 4 byte */
543 if (res != 0)
544 {
545 nrf905_interface_debug_print("nrf905: set tx address width failed.\n");
546 (void)nrf905_deinit(&gs_handle);
547
548 return 1;
549 }
550
551 /* 32 bytes */
552 res = nrf905_set_rx_payload_width(&gs_handle, 32);
553 if (res != 0)
554 {
555 nrf905_interface_debug_print("nrf905: set rx payload width failed.\n");
556 (void)nrf905_deinit(&gs_handle);
557
558 return 1;
559 }
560
561 /* 32 bytes */
562 res = nrf905_set_tx_payload_width(&gs_handle, 32);
563 if (res != 0)
564 {
565 nrf905_interface_debug_print("nrf905: set tx payload width failed.\n");
566 (void)nrf905_deinit(&gs_handle);
567
568 return 1;
569 }
570
571 /* set the rx address */
572 res = nrf905_set_rx_address(&gs_handle, addr);
573 if (res != 0)
574 {
575 nrf905_interface_debug_print("nrf905: set rx address failed.\n");
576 (void)nrf905_deinit(&gs_handle);
577
578 return 1;
579 }
580
581 /* set 500KHz */
583 if (res != 0)
584 {
585 nrf905_interface_debug_print("nrf905: set output clock frequency failed.\n");
586 (void)nrf905_deinit(&gs_handle);
587
588 return 1;
589 }
590
591 /* disable the output clock */
593 if (res != 0)
594 {
595 nrf905_interface_debug_print("nrf905: set output clock failed.\n");
596 (void)nrf905_deinit(&gs_handle);
597
598 return 1;
599 }
600
601 /* 16MHz */
603 if (res != 0)
604 {
605 nrf905_interface_debug_print("nrf905: set crystal oscillator frequency failed.\n");
606 (void)nrf905_deinit(&gs_handle);
607
608 return 1;
609 }
610
611 /* enable the crc */
612 res = nrf905_set_crc(&gs_handle, NRF905_BOOL_TRUE);
613 if (res != 0)
614 {
615 nrf905_interface_debug_print("nrf905: set crc failed.\n");
616 (void)nrf905_deinit(&gs_handle);
617
618 return 1;
619 }
620
621 /* set crc mode 8 */
622 res = nrf905_set_crc_mode(&gs_handle, NRF905_CRC_MODE_8);
623 if (res != 0)
624 {
625 nrf905_interface_debug_print("nrf905: set crc mode failed.\n");
626 (void)nrf905_deinit(&gs_handle);
627
628 return 1;
629 }
630
631 /* 433 MHz */
632 res = nrf905_frequency_convert_to_register(&gs_handle, 433.2f, &reg);
633 if (res != 0)
634 {
635 nrf905_interface_debug_print("nrf905: frequency convert to register failed.\n");
636 (void)nrf905_deinit(&gs_handle);
637
638 return 1;
639 }
640
641 /* set the frequency */
642 res = nrf905_set_frequency(&gs_handle, reg);
643 if (res != 0)
644 {
645 nrf905_interface_debug_print("nrf905: set frequency failed.\n");
646 (void)nrf905_deinit(&gs_handle);
647
648 return 1;
649 }
650
651 /* write the conf */
652 res = nrf905_write_conf(&gs_handle);
653 if (res != 0)
654 {
655 nrf905_interface_debug_print("nrf905: write conf failed.\n");
656 (void)nrf905_deinit(&gs_handle);
657
658 return 1;
659 }
660
661 /* set tx address */
662 res = nrf905_set_tx_address(&gs_handle, addr, 4);
663 if (res != 0)
664 {
665 nrf905_interface_debug_print("nrf905: set tx address failed.\n");
666 (void)nrf905_deinit(&gs_handle);
667
668 return 1;
669 }
670
671 /* set rx mode */
672 res = nrf905_set_mode(&gs_handle, NRF905_MODE_RX);
673 if (res != 0)
674 {
675 nrf905_interface_debug_print("nrf905: set mode failed.\n");
676 (void)nrf905_deinit(&gs_handle);
677
678 return 1;
679 }
680
681 /* clear rx done */
682 timeout = 10 * 1000;
683 gs_rx_done = 0;
684 res = nrf905_set_enable(&gs_handle, NRF905_BOOL_TRUE);
685 if (res != 0)
686 {
687 nrf905_interface_debug_print("nrf905: set enable failed.\n");
688 (void)nrf905_deinit(&gs_handle);
689
690 return 1;
691 }
692
693 /* waiting */
694 while ((timeout != 0) && (gs_rx_done == 0))
695 {
697 timeout--;
698 }
699
700 /* check timeout */
701 if ((timeout == 0) && (gs_rx_done == 0))
702 {
703 nrf905_interface_debug_print("nrf905: receive timeout.\n");
704 (void)nrf905_deinit(&gs_handle);
705
706 return 1;
707 }
708
709 /* finish receive test */
710 nrf905_interface_debug_print("nrf905: finish receive test.\n");
711 (void)nrf905_deinit(&gs_handle);
712
713 return 0;
714}
driver nrf905 send receive test header file
uint8_t nrf905_set_output_clock(nrf905_handle_t *handle, nrf905_bool_t enable)
enable or disable the output clock
uint8_t nrf905_set_frequency(nrf905_handle_t *handle, uint16_t freq)
set the frequency
uint8_t nrf905_set_tx_payload_width(nrf905_handle_t *handle, uint8_t width)
set the tx payload width
uint8_t nrf905_init(nrf905_handle_t *handle)
initialize the chip
uint8_t nrf905_frequency_convert_to_register(nrf905_handle_t *handle, float mhz, uint16_t *reg)
convert the frequency to the register raw data
uint8_t nrf905_set_crc_mode(nrf905_handle_t *handle, nrf905_crc_mode_t mode)
set the crc mode
uint8_t nrf905_set_pll_mode(nrf905_handle_t *handle, nrf905_pll_mode_t mode)
set the pll mode
uint8_t nrf905_set_output_power(nrf905_handle_t *handle, nrf905_output_power_t output_power)
set the output power
uint8_t nrf905_set_enable(nrf905_handle_t *handle, nrf905_bool_t enable)
enable or disable the chip
struct nrf905_info_s nrf905_info_t
nrf905 information structure definition
uint8_t nrf905_set_rx_payload_width(nrf905_handle_t *handle, uint8_t width)
set the rx payload width
uint8_t nrf905_set_power_up(nrf905_handle_t *handle, nrf905_bool_t enable)
set the power up
uint8_t nrf905_set_rx_address_width(nrf905_handle_t *handle, nrf905_address_width_t width)
set the rx address width
uint8_t nrf905_send(nrf905_handle_t *handle, uint8_t *buf, uint8_t len)
send data
uint8_t nrf905_set_crystal_oscillator_frequency(nrf905_handle_t *handle, nrf905_crystal_oscillator_frequency_t freq)
set the crystal oscillator frequency
uint8_t nrf905_set_rx_address(nrf905_handle_t *handle, uint8_t addr[4])
set the rx address
uint8_t nrf905_info(nrf905_info_t *info)
get chip's information
uint8_t nrf905_set_tx_address_width(nrf905_handle_t *handle, nrf905_address_width_t width)
set the tx address width
uint8_t nrf905_set_tx_address(nrf905_handle_t *handle, uint8_t *addr, uint8_t len)
set the tx address
uint8_t nrf905_set_rx_mode(nrf905_handle_t *handle, nrf905_rx_mode_t mode)
set the rx mode
uint8_t nrf905_write_conf(nrf905_handle_t *handle)
write the conf
uint8_t nrf905_irq_handler(nrf905_handle_t *handle)
irq handler
uint8_t nrf905_set_auto_retransmit(nrf905_handle_t *handle, nrf905_bool_t enable)
enable or disable the auto retransmit
uint8_t nrf905_set_output_clock_frequency(nrf905_handle_t *handle, nrf905_output_clock_frequency_t freq)
set the output clock frequency
uint8_t nrf905_set_mode(nrf905_handle_t *handle, nrf905_mode_t mode)
set the mode
struct nrf905_handle_s nrf905_handle_t
nrf905 handle structure definition
uint8_t nrf905_set_crc(nrf905_handle_t *handle, nrf905_bool_t enable)
enable or disable the crc
uint8_t nrf905_deinit(nrf905_handle_t *handle)
close the chip
@ NRF905_ADDRESS_WIDTH_4_BYTE
@ NRF905_OUTPUT_CLOCK_FREQUENCY_500KHZ
@ NRF905_CRYSTAL_OSCILLATOR_FREQUENCY_16MHZ
@ NRF905_CRC_MODE_8
@ NRF905_OUTPUT_POWER_10_DBM
@ NRF905_MODE_RX
@ NRF905_STATUS_AM
@ NRF905_STATUS_RX_DONE
@ NRF905_STATUS_TX_DONE
@ NRF905_PLL_MODE_433_MHZ
@ NRF905_RX_MODE_NORMAL
@ NRF905_BOOL_FALSE
@ NRF905_BOOL_TRUE
uint8_t nrf905_interface_spi_deinit(void)
interface spi bus deinit
uint8_t nrf905_interface_spi_init(void)
interface spi bus init
uint8_t nrf905_interface_spi_transmit(uint8_t *tx, uint8_t *rx, uint16_t len)
interface spi bus transmit
void nrf905_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t nrf905_interface_ce_gpio_init(void)
interface ce gpio init
uint8_t nrf905_interface_spi_write(uint8_t reg, uint8_t *buf, uint16_t len)
interface spi bus write
uint8_t nrf905_interface_pwr_up_gpio_init(void)
interface pwr up gpio init
void nrf905_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t nrf905_interface_pwr_up_gpio_write(uint8_t data)
interface pwr up gpio write
uint8_t nrf905_interface_tx_en_gpio_write(uint8_t data)
interface tx en gpio write
uint8_t nrf905_interface_pwr_up_gpio_deinit(void)
interface pwr up gpio deinit
uint8_t nrf905_interface_ce_gpio_write(uint8_t data)
interface ce gpio write
uint8_t nrf905_interface_spi_read(uint8_t reg, uint8_t *buf, uint16_t len)
interface spi bus read
uint8_t nrf905_interface_tx_en_gpio_init(void)
interface tx en gpio init
uint8_t nrf905_interface_ce_gpio_deinit(void)
interface ce gpio deinit
void nrf905_interface_receive_callback(uint8_t type, uint8_t *buf, uint8_t len)
interface receive callback
uint8_t nrf905_interface_tx_en_gpio_deinit(void)
interface tx en gpio deinit
uint8_t nrf905_interrupt_test_irq_handler(void)
nrf905 interrupt test irq
uint8_t nrf905_receive_test(void)
receive test
uint8_t nrf905_send_test(void)
send test
float supply_voltage_max_v
uint32_t driver_version
char manufacturer_name[32]
float supply_voltage_min_v
char chip_name[32]