This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Not be able to enable uart

Here is my problem. I want to disable uart when there is no data coming into MCU. I used IO LotoHi event to enable uart Rx. After finish data receiving, I disable Uart. And before I send data via uart, I enable UART. After sending, I disable it. But based on devzone.nordicsemi.com/.../ Things just do not work well.

void in_pin_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action){
    BLE_LOG("IO INT\r\n");
    **NRF_UART0->TASKS_STARTRX = 1;**
}

In the uart_event_handler function, at the end of data receiving, I disabled Rx

void uart_init(void)
{
    uint32_t err_code;

    const app_uart_comm_params_t comm_params =
  {
    .rx_pin_no    = RX_PIN_NUMBER,
    .tx_pin_no    = TX_PIN_NUMBER,
    .rts_pin_no   = RTS_PIN_NUMBER,
    .cts_pin_no   = CTS_PIN_NUMBER,
    .flow_control = APP_UART_FLOW_CONTROL_DISABLED,
    .use_parity   = false,
    .baud_rate    = UART_BAUDRATE_BAUDRATE_Baud9600
  };

    APP_UART_FIFO_INIT(&comm_params,
                    UART_BUF_SIZE,
                    UART_BUF_SIZE,
                    uart_event_handler,
                    APP_IRQ_PRIORITY_LOW,
                    err_code);


    APP_ERROR_CHECK(err_code);
}
void uart_event_handler(app_uart_evt_t *p_app_uart_event){
    uint8_t temp;
    static uint8_t index = 0;
    static uint8_t msg[UART_BUF_SIZE + 1] = {0x00};
    switch(p_app_uart_event->evt_type)
    {
        case APP_UART_DATA_READY:
            UNUSED_VARIABLE(app_uart_get(&msg[index]));
            index++;

            if ((msg[index - 1] == '\n') || (index >= (UART_BUF_SIZE)))
            {
                memset(uart_msg, 0, sizeof(uint8_t) * (UART_BUF_SIZE + 1));
                memcpy(uart_msg, msg, index);  
                uart_len = index - 1;  
                index = 0;
                is_uart_ok = true;
                **NRF_UART0->TASKS_STOPRX = 1;**

            }
            break;
            ......

this did not work normally.

If I use app_uart_close() to replace NRF_UART0->TASKS_STOPRX = 1 and uart_init() to replace NRF_UART0->TASKS_STARTRX = 1 MCU just restart.

Parents Reply Children
No Data
Related