bsp_uart.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #include "bsp_uart.h"
  2. #include "app_uart.h"
  3. #if defined (UART_PRESENT)
  4. #include "nrf_uart.h"
  5. #endif
  6. #if defined (UARTE_PRESENT)
  7. #include "nrf_uarte.h"
  8. #endif
  9. #define UART_RX_PIN_NUMBER 8
  10. #define UART_TX_PIN_NUMBER 6
  11. #define UART_CTS_PIN_NUMBER 7
  12. #define UART_RTS_PIN_NUMBER 5
  13. #define UART_HWFC APP_UART_FLOW_CONTROL_DISABLED
  14. #define UART_TX_BUF_SIZE 256 /**< UART TX buffer size. */
  15. #define UART_RX_BUF_SIZE 256 /**< UART RX buffer size. */
  16. void uart_error_handle(app_uart_evt_t * p_event)
  17. {
  18. if (p_event->evt_type == APP_UART_COMMUNICATION_ERROR){
  19. APP_ERROR_HANDLER(p_event->data.error_communication);
  20. }
  21. else if (p_event->evt_type == APP_UART_FIFO_ERROR){
  22. APP_ERROR_HANDLER(p_event->data.error_code);
  23. }
  24. }
  25. void bsp_uart_init(void)
  26. {
  27. uint32_t err_code;
  28. const app_uart_comm_params_t comm_params =
  29. {
  30. UART_RX_PIN_NUMBER,
  31. UART_TX_PIN_NUMBER,
  32. UART_RTS_PIN_NUMBER,
  33. UART_CTS_PIN_NUMBER,
  34. UART_HWFC,
  35. false,
  36. #if defined (UART_PRESENT)
  37. NRF_UART_BAUDRATE_115200
  38. #else
  39. NRF_UARTE_BAUDRATE_115200
  40. #endif
  41. };
  42. APP_UART_FIFO_INIT( &comm_params,
  43. UART_RX_BUF_SIZE,
  44. UART_TX_BUF_SIZE,
  45. uart_error_handle,
  46. APP_IRQ_PRIORITY_LOWEST,
  47. err_code);
  48. APP_ERROR_CHECK(err_code);
  49. #if DEBUG_EN
  50. printf("bsp_uart_init OK\r\n");
  51. #endif
  52. }