electrotwelve

nrf24l01 stm32 code snippet

Jan 26th, 2019
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.85 KB | None | 0 0
  1. /* USER CODE BEGIN PV */
  2.  
  3. uint64_t tx_address = 0x11223344AA;
  4. char buf[32] = "Hello World!";
  5. uint16_t tx_data[2] = {501, 502};
  6.  
  7. /* USER CODE END PV */
  8.  
  9. /* Private function prototypes -----------------------------------------------*/
  10. void SystemClock_Config(void);
  11. /* USER CODE BEGIN PFP */
  12.  
  13. /* USER CODE END PFP */
  14.  
  15. /* Private user code ---------------------------------------------------------*/
  16. /* USER CODE BEGIN 0 */
  17.  
  18. /* USER CODE END 0 */
  19.  
  20. /**
  21.   * @brief  The application entry point.
  22.   * @retval int
  23.   */
  24. int main(void)
  25. {
  26.   /* USER CODE BEGIN 1 */
  27.  
  28.   /* USER CODE END 1 */
  29.  
  30.   /* MCU Configuration--------------------------------------------------------*/
  31.  
  32.   /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  33.   HAL_Init();
  34.  
  35.   /* USER CODE BEGIN Init */
  36.  
  37.   /* USER CODE END Init */
  38.  
  39.   /* Configure the system clock */
  40.   SystemClock_Config();
  41.  
  42.   /* USER CODE BEGIN SysInit */
  43.  
  44.   /* USER CODE END SysInit */
  45.  
  46.   /* Initialize all configured peripherals */
  47.   MX_GPIO_Init();
  48.   MX_SPI1_Init();
  49.   MX_USART1_UART_Init();
  50.   /* USER CODE BEGIN 2 */
  51.   NRF24_begin(CE_GPIO_Port, CSN_Pin, CE_Pin, hspi1);
  52.   nrf24_DebugUART_Init(huart1);
  53.  
  54.   /* Transmit NO ACK */
  55.  
  56.   NRF24_stopListening();
  57.   NRF24_openWritingPipe(tx_address);
  58.   NRF24_setAutoAck(false);
  59.   NRF24_setChannel(52);
  60.   NRF24_setPayloadSize(32);
  61.  
  62.   printRadioSettings();
  63.  
  64.   /* USER CODE END 2 */
  65.  
  66.   /* Infinite loop */
  67.   /* USER CODE BEGIN WHILE */
  68.   while (1)
  69.   {
  70.     /* USER CODE END WHILE */
  71.  
  72.     /* USER CODE BEGIN 3 */
  73.  
  74.     if(NRF24_write(buf, 32))
  75.     {
  76.         HAL_UART_Transmit(&huart1, (uint8_t *)"Transmitted Successfully\r\n", strlen("Transmitted Successfully\r\n"), 10);
  77.     }
  78.     else
  79.     {
  80.         HAL_UART_Transmit(&huart1, (uint8_t *)"Error\r\n", strlen("Error\r\n"), 10);
  81.     }
  82.     HAL_Delay(2000);
  83.   }
  84.   /* USER CODE END 3 */
  85. }
Add Comment
Please, Sign In to add comment