uart.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include "app_uart.h"
  2. #include "uart.h"
  3. #include "bsp.h"
  4. //#if defined(NRF_LOG_USES_UART) && NRF_LOG_USES_UART == 1
  5. //#define RX_PIN_NUMBER 9 // if you want to map these pin to other,HWFC must set false and APP_UART_FLOW_CONTROL_ENABLED turn to APP_UART_FLOW_CONTROL_DISABLED
  6. //#define TX_PIN_NUMBER 8 // and just map RX and TX only,because flow control is disable
  7. //#define CTS_PIN_NUMBER 17
  8. //#define RTS_PIN_NUMBER 16
  9. #define UART_TX_BUF_SIZE 256
  10. #define UART_RX_BUF_SIZE 256
  11. void uart_event_handle(app_uart_evt_t * p_event)
  12. {
  13. switch (p_event->evt_type)
  14. {
  15. case APP_UART_DATA_READY:
  16. break;
  17. default:
  18. break;
  19. }
  20. }
  21. void uart_init(void)
  22. {
  23. uint32_t err_code;
  24. const app_uart_comm_params_t comm_params =
  25. {
  26. RX_PIN_NUMBER,
  27. TX_PIN_NUMBER,
  28. RTS_PIN_NUMBER,
  29. CTS_PIN_NUMBER,
  30. APP_UART_FLOW_CONTROL_DISABLED,
  31. false,
  32. UART_BAUDRATE_BAUDRATE_Baud115200
  33. };
  34. APP_UART_FIFO_INIT( &comm_params,
  35. UART_RX_BUF_SIZE,
  36. UART_TX_BUF_SIZE,
  37. uart_event_handle,
  38. APP_IRQ_PRIORITY_LOW,
  39. err_code);
  40. APP_ERROR_CHECK(err_code);
  41. }
  42. //#endif