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

nrf52832 UART send multiple bytes

Hi all,

    I am trying to send a command to the sensor so that the sensor will response with sending something back for acknowledgement, via UART.

    Let say, I want to send a command "SEND" to sensor, and the sensor will send its data back. However, I don't know how to modify the example code in 

    nRF5_SDK_14.2.0_17b948a\examples\peripheral\uart

    so that the code are fetching the FIFO when the '\n' is met, instead of response in every character. Right now the example is doing this for single character.

    I am not sure how to change from the example to achieve, it seems rx/tx are having independent fifo buffer, how they operate and connected?

    m_rx_fifo, m_tx_fifo

    tx_buffer[], rx_buffer[]

    nrf_drv_uart_rx(), nrf_drv_uart_tx()

    app_uart_get(), app_uart_put()

Please share your thoughts if you have any idea. Thanks Slight smile

  • No you shouldn't worry about it.

    You can modify my first exemple to transmit "SEND" in sendAction(), and modify the handler to process the 2 bytes response with a counter or somthing like that. I think you'll be fine with the default fifo buffer size.

    const char * send_cmd = "SEND";
    char rsp[2];
    uint8_t cmdIndex = 0;
    ...
    void sendAction()
    {
        uint8_t i;
        for(i = 0; i < sizeof(send_cmd); i++)
        {
            while (app_uart_put(send_cmd[i]) != NRF_SUCCESS);
        }
    }
    void uart_handle(app_uart_evt_t * p_event)
    {
        ...
        else if (p_event->evt_type == APP_UART_DATA_READY)
        {
            
            while (app_uart_get(&cr) != NRF_SUCCESS);
            rsp[cmdIndex++] =  cr;
     
            if(cmdIndex == 2)
            {
                printf("Sensor Value : 0x%02X%02x\r\n", rsp[0],rsp[1]);
                
                cmdIndex = 0;
            }
        }
    }

  • May I ask why I can get correct response from sensor when I input command "SEND" on PuTTY but no response by using sendAction()?

    If I connect UART to nothing, the command is correctly shown on PuTTY. It means the sendAction() has no problem.

    int main(void) {
        ...
        while (true)
        {
        	sendAction();
    		nrf_delay_ms(500);
    		app_uart_flush();
    	}
    }

    But when I connect the uart serial communication betweem nrf and sensor, there is no response unless I input command by keyboard, and then the console shows temperature value.

  • What sensor are you using? Have you tried with 

    const char * send_cmd = "SEND\n";

    Also check you have the right UART configuration (baudrate, flow control, parity). The best would be to use a logic analyser to see what happens.

Related