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

app_uart_get more than 1 byte

Hi,

I'm using app_uart for communication between different mcu. I can send more than 1 byte like "0x3917015623"  through  changing tx_buffer[0] to tx_buffer[5]. Unfortunately i couldn't recieve the slave devicess message "0x2917013607". I can only get the first byte "0x07". My configuration are the same as uart example. How can i recieve all the message ?. I tried to use serial library but i couldn't initialize. (It gave ERROR 6 NRF_ERROR_NOT_SUPPORTED).

Slave device is sending me a message every second. And i'm calling app_uart_get function every 500 miliseconds.

Here is my uart init;

void uart_error_handle(app_uart_evt_t * p_event)
{
    if (p_event->evt_type == APP_UART_COMMUNICATION_ERROR)
    {
        APP_ERROR_HANDLER(p_event->data.error_communication);
    }
    else if (p_event->evt_type == APP_UART_FIFO_ERROR)
    {
        APP_ERROR_HANDLER(p_event->data.error_code);
    }    
}

void uart_init(void)
{
    uint32_t err_code;
    const app_uart_comm_params_t comm_params =
        {
            RX_PIN_NUMBER,
            TX_PIN_NUMBER,
            RTS_PIN_NUMBER,
            CTS_PIN_NUMBER,
            UART_HWFC,
            false,
  #if defined (UART_PRESENT)
            NRF_UART_BAUDRATE_115200
  #else
            NRF_UARTE_BAUDRATE_9600
  #endif
        };
//    const app_uart_buffers_t m_buffers =
//      {
//        &rx_buffer_s,
//        sizeof(rx_buffer_s),
//        &tx_buffer_s,
//        sizeof(tx_buffer_s)
//      }
      APP_UART_FIFO_INIT(&comm_params,
                           UART_RX_BUF_SIZE,
                           UART_TX_BUF_SIZE,
                           uart_error_handle,
                           APP_IRQ_PRIORITY_LOWEST,
                           err_code);

      APP_ERROR_CHECK(err_code);
//      err_code = app_uart_init(&comm_params, &m_buffers, uart_error_handle, APP_IRQ_PRIORITY_LOW);
//      APP_ERROR_CHECK(err_code);
  
}

Regards,

  • You will get the NRF_SERIAL_EVENT_RX_DATA event when RX data is available. The nrf_serial module will call the event handler function passed as the _ev_handler argument to the NRF_SERIAL_CONFIG_DEF macro, which is called at the start of main.c.

  • I added this function above the NRF_SERIAL_CONFIG_DEF and set third parameter of it. I ser a breakpoint on  case NRF_SERIAL_EVENT_RX_DATA  but program is not going to the event handler. Did i miss something ?

    static void serial_event_handler(struct nrf_serial_s const * p_serial,
    nrf_serial_event_t event) 
    {
        switch (event)
    	{
    	case NRF_SERIAL_EVENT_TX_DONE:
    	    break;
    	case NRF_SERIAL_EVENT_RX_DATA:
    	    
                    
                  err_code = request_next_event_earliest();
                  if (err_code != NRF_SUCCESS)
                  {
                      (void)sd_radio_session_close();
                      return err_code;
                  }
    
    	    break;
    	case NRF_SERIAL_EVENT_DRV_ERR:
    	    break;
    	case NRF_SERIAL_EVENT_FIFO_ERR:
    	    break;
    	default:
    	    break;
    	}
    	
    }

  • Hmm, can you set a breakpoint  at the NRF_DRV_UART_EVT_RX_DONE case in the uart_event_handler() in nrf_serial.c and see if you hit it?

    static void uart_event_handler(nrf_drv_uart_event_t * p_event, void * p_context)
    {
        uint32_t ret;
        nrf_serial_t const * p_serial = p_context;
    
        switch (p_event->type)
        {
            case NRF_DRV_UART_EVT_RX_DONE:
            {
                nrf_queue_t const * p_rxq =
                        p_serial->p_ctx->p_config->p_queues->p_rxq;
                size_t len = nrf_queue_in(p_rxq,
                                          p_event->data.rxtx.p_data,
                                          p_event->data.rxtx.bytes);
    
                if (len < p_event->data.rxtx.bytes)
                {
                    event_handler(p_serial, NRF_SERIAL_EVENT_FIFO_ERR);
                    break;
                }
    
                if (p_event->data.rxtx.bytes)
                {
                    event_handler(p_serial, NRF_SERIAL_EVENT_RX_DATA);
                }
                nrf_serial_buffers_t const * p_buffs =
                        p_serial->p_ctx->p_config->p_buffers;
    
                ret = nrf_drv_uart_rx(&p_serial->instance,
                                      p_buffs->p_rxb,
                                      p_buffs->rx_size);
                ASSERT(ret == NRF_SUCCESS);
                break;
            }
            case NRF_DRV_UART_EVT_ERROR:
            {
                event_handler(p_serial, NRF_SERIAL_EVENT_DRV_ERR);
                break;
            }
            case NRF_DRV_UART_EVT_TX_DONE:
            {
                nrf_queue_t const * p_txq =
                        p_serial->p_ctx->p_config->p_queues->p_txq;
                nrf_serial_buffers_t const * p_buffs =
                        p_serial->p_ctx->p_config->p_buffers;
    
                event_handler(p_serial, NRF_SERIAL_EVENT_TX_DONE);
                size_t len = nrf_queue_out(p_txq, p_buffs->p_txb, p_buffs->tx_size);
                if (len == 0)
                {
                    break;
                }
    
                ret = nrf_drv_uart_tx(&p_serial->instance, p_buffs->p_txb, len);
                ASSERT(ret == NRF_SUCCESS);
                break;
            }
            default:
                break;
        }
    }

    Best regards

    Bjørn

  • I did,  the program is not going there. How can i receive data without events ? The program never hits the uart event handler.

    Edit 1 : After some changes, the program is hitting uart_event_handler in nrf_serial.c.

  • Hi Mehmet, 

    Ok, so you're now getting the NRF_DRV_UART_EVT_RX_DONE in the uart_event_handler(), which in turn triggers the NRF_SERIAL_EVENT_RX_DATA event in the serial_event_handler()?

    Best regards

    Bjørn

Related