Advertisement
Guest User

ble-less uart example nRF51822

a guest
Apr 19th, 2015
731
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. #include <stdbool.h>
  2. #include <stdint.h>
  3. #include <stdio.h>
  4. #include "app_uart.h"
  5. #include "app_error.h"
  6. #include "nrf_delay.h"
  7. #include "nrf.h"
  8. #include "bsp.h"
  9.  
  10. #define MAX_TEST_DATA_BYTES (15U) /**< max number of test bytes to be used for tx and rx. */
  11. #define UART_TX_BUF_SIZE 256 /**< UART TX buffer size. */
  12. #define UART_RX_BUF_SIZE 1 /**< UART RX buffer size. */
  13.  
  14. void uart_error_handle(app_uart_evt_t * p_event)
  15. {
  16. if (p_event->evt_type == APP_UART_COMMUNICATION_ERROR)
  17. {
  18. APP_ERROR_HANDLER(p_event->data.error_communication);
  19. }
  20. else if (p_event->evt_type == APP_UART_FIFO_ERROR)
  21. {
  22. APP_ERROR_HANDLER(p_event->data.error_code);
  23. }
  24. }
  25.  
  26. /**
  27. * @brief Function for main application entry.
  28. */
  29. int main(void)
  30. {
  31.  
  32. uint32_t err_code;
  33. const app_uart_comm_params_t
  34. comm_params =
  35. {
  36. 4,//RX_PIN_NUMBER,
  37. 6, //TX_PIN_NUMBER,
  38. RTS_PIN_NUMBER,
  39. CTS_PIN_NUMBER,
  40. APP_UART_FLOW_CONTROL_DISABLED, //APP_UART_FLOW_CONTROL_ENABLED,
  41. false,
  42. UART_BAUDRATE_BAUDRATE_Baud38400
  43. };
  44.  
  45. APP_UART_FIFO_INIT(&comm_params,
  46. UART_RX_BUF_SIZE,
  47. UART_TX_BUF_SIZE,
  48. uart_error_handle,
  49. APP_IRQ_PRIORITY_LOW,
  50. err_code);
  51.  
  52. APP_ERROR_CHECK(err_code);
  53.  
  54. printf("\n\rStart: \n\r");
  55.  
  56. while (true)
  57. {
  58. uint8_t cr;
  59. while(app_uart_get(&cr) != NRF_SUCCESS);
  60. while(app_uart_put(cr) != NRF_SUCCESS);
  61.  
  62. if (cr == 'q' || cr == 'Q')
  63. {
  64. printf(" \n\rExit!\n\r");
  65.  
  66. while (true)
  67. {
  68. // Do nothing.
  69. }
  70. }
  71. printf("Hit.\r\n");
  72. nrf_delay_ms(1000);
  73. }
  74.  
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement