Guest User

Untitled

a guest
Jan 16th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. #include <stdbool.h>
  2. #include <stdint.h>
  3. #include <stddef.h>
  4. #include <stdio.h>
  5.  
  6. #include "nrf_drv_systick.h"
  7. #include "nrf_delay.h"
  8. #include "boards.h"
  9.  
  10. #include "nrf_drv_clock.h"
  11.  
  12. #include "radio_config.h"
  13.  
  14. static uint32_t packet; /**< Packet to transmit. */
  15.  
  16. uint32_t read_packet()
  17. {
  18. uint32_t result = 0;
  19.  
  20. NRF_RADIO->EVENTS_READY = 0U;
  21. NRF_RADIO->TASKS_RXEN = 1U; // Enable radio and wait for ready
  22. while (NRF_RADIO->EVENTS_READY == 0U) ;
  23. NRF_RADIO->EVENTS_END = 0U;
  24. NRF_RADIO->TASKS_START = 1U; // Start listening and wait for address received event
  25. while (NRF_RADIO->EVENTS_END == 0U) ; // Wait for end of packet or buttons state changed
  26.  
  27. if (NRF_RADIO->CRCSTATUS == 1U) { result = packet; }
  28.  
  29. NRF_RADIO->EVENTS_DISABLED = 0U;
  30. NRF_RADIO->TASKS_DISABLE = 1U; // Disable radio
  31. while (NRF_RADIO->EVENTS_DISABLED == 0U) ;
  32. return result;
  33. }
  34.  
  35.  
  36. void LED_Control(uint8_t led_idx)
  37. {
  38. switch(led_idx)
  39. {
  40. case 0:
  41.  
  42. bsp_board_led_on(0);
  43. bsp_board_led_off(1);
  44. bsp_board_led_off(2);
  45. bsp_board_led_off(3);
  46.  
  47. break;
  48.  
  49. case 1:
  50.  
  51. bsp_board_led_off(0);
  52. bsp_board_led_on(1);
  53. bsp_board_led_off(2);
  54. bsp_board_led_off(3);
  55.  
  56.  
  57. break;
  58.  
  59.  
  60. case 2:
  61.  
  62. bsp_board_led_off(0);
  63. bsp_board_led_off(1);
  64. bsp_board_led_on(2);
  65. bsp_board_led_off(3);
  66.  
  67.  
  68. break;
  69.  
  70. case 3:
  71.  
  72. bsp_board_led_off(0);
  73. bsp_board_led_off(1);
  74. bsp_board_led_off(2);
  75. bsp_board_led_on(3);
  76.  
  77.  
  78. break;
  79.  
  80. }
  81.  
  82.  
  83. }
  84.  
  85.  
  86. int main(void)
  87. {
  88. bsp_board_init(BSP_INIT_LEDS);
  89.  
  90. ///start clock set mandatory for USB CDC
  91. nrf_drv_clock_init();
  92. nrf_drv_clock_hfclk_request(NULL); // for HF 32MHz external X-tal
  93. while(!nrf_drv_clock_hfclk_is_running()) ; // Just waiting
  94. nrf_drv_clock_lfclk_request(NULL); // for LF 32.768kHz external X-tal
  95. while(!nrf_drv_clock_lfclk_is_running()) ;
  96. /// end clock set
  97.  
  98. /// for radio receiver
  99. radio_configure();
  100. NRF_RADIO->PACKETPTR = (uint32_t)&packet;
  101.  
  102.  
  103. while(true)
  104. {
  105. uint32_t received = read_packet(); // received data from RADIO
  106.  
  107. LED_Control(received-1);
  108.  
  109. }
  110. }
Add Comment
Please, Sign In to add comment