bsp_uart.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #include "bsp_uart.h"
  2. #define UART_RX_PIN_NUMBER 8
  3. #define UART_TX_PIN_NUMBER 6
  4. #define UART_CTS_PIN_NUMBER 7
  5. #define UART_RTS_PIN_NUMBER 5
  6. #define UART_HWFC APP_UART_FLOW_CONTROL_DISABLED
  7. #define UART_TX_BUF_SIZE 1024 /**< UART TX buffer size. */
  8. #define UART_RX_BUF_SIZE 1024 /**< UART RX buffer size. */
  9. extern void AABBCC_REC(unsigned char data);
  10. void uart_error_handle(app_uart_evt_t * p_event)
  11. {
  12. unsigned char data=0;
  13. unsigned int error_code=0;
  14. switch(p_event->evt_type)
  15. {
  16. case APP_UART_DATA_READY:
  17. error_code=app_uart_get(&data);
  18. if(error_code==NRF_SUCCESS)AABBCC_REC(data);
  19. else printf("uart_error_handle ->error=0x%x\n",error_code);
  20. break;
  21. case APP_UART_FIFO_ERROR:
  22. break;
  23. case APP_UART_COMMUNICATION_ERROR:
  24. break;
  25. case APP_UART_TX_EMPTY:
  26. break;
  27. case APP_UART_DATA:
  28. break;
  29. }
  30. }
  31. void bsp_uart_init(void)
  32. {
  33. uint32_t err_code;
  34. const app_uart_comm_params_t comm_params =
  35. {
  36. UART_RX_PIN_NUMBER,
  37. UART_TX_PIN_NUMBER,
  38. UART_RTS_PIN_NUMBER,
  39. UART_CTS_PIN_NUMBER,
  40. UART_HWFC,
  41. false,
  42. #if defined (UART_PRESENT)
  43. NRF_UART_BAUDRATE_115200
  44. #else
  45. NRF_UARTE_BAUDRATE_115200
  46. #endif
  47. };
  48. APP_UART_FIFO_INIT( &comm_params,
  49. UART_RX_BUF_SIZE,
  50. UART_TX_BUF_SIZE,
  51. uart_error_handle,
  52. APP_IRQ_PRIORITY_LOWEST,
  53. err_code);
  54. APP_ERROR_CHECK(err_code);
  55. printf("bsp_uart_init OK\r\n");
  56. }