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

Stuck application when implementing UART

Hi,

I have PCA10028 board, and I'm trying to implement UART send/receive. I've searched for the problem here but could not find a solution for it.

My uart init function is(most of the code is copy/paste):

static void uart_init(void)
{
    uint32_t				err_code;
		
		app_uart_comm_params_t params;
    memset(&params, 0, sizeof(params));
    
    params.baud_rate = UART_BAUDRATE_BAUDRATE_Baud115200;
    params.tx_pin_no = TX_PIN_NUMBER;
    params.rx_pin_no = RX_PIN_NUMBER;
    params.use_parity = false;
    params.flow_control = APP_UART_FLOW_CONTROL_DISABLED;
    
    static uint8_t rx_buffer[UART_RX_BUFFER_SIZE];
    static uint8_t tx_buffer[UART_TX_BUFFER_SIZE];
    app_uart_buffers_t buffers;
    buffers.rx_buf = rx_buffer;
    buffers.rx_buf_size = UART_RX_BUFFER_SIZE;
    buffers.tx_buf = tx_buffer;
    buffers.tx_buf_size = UART_TX_BUFFER_SIZE;
    
    err_code = app_uart_init(&params, &buffers, uart_event_handle, APP_IRQ_PRIORITY_LOW, NULL);
    APP_ERROR_CHECK(err_code);
}

This is event handler:

void uart_event_handle(app_uart_evt_t * p_event)
{
    static uint8_t data_array[BLE_MAX_DATA_LEN];
    static uint8_t index = 0;
    uint32_t       err_code;

    switch (p_event->evt_type)
    {
        case APP_UART_DATA_READY:
            UNUSED_VARIABLE(app_uart_get(&data_array[index]));
            index++;

            if ((data_array[index - 1] == '\n') || (index >= (BLE_MAX_DATA_LEN)))
            {
								// TODO: Check sending of data here
                //err_code = ble_nus_string_send(&m_nus, data_array, index);
                if (err_code != NRF_ERROR_INVALID_STATE)
                {
                    APP_ERROR_CHECK(err_code);
                }
                
                index = 0;
            }
            break;

        case APP_UART_COMMUNICATION_ERROR:
            APP_ERROR_HANDLER(p_event->data.error_communication);
            break;

        case APP_UART_FIFO_ERROR:
            APP_ERROR_HANDLER(p_event->data.error_code);
            break;

        default:
            break;
    }
}

And this is my write function:

void app_uart_put_string(const char* s)
{
    uint8_t len = strlen(s);
    for (uint8_t i = 0; i < len; i++)
    {
	while (app_uart_put(s[i]) != NRF_SUCCESS);
        //err_code = app_uart_put(s[i]);
        //APP_ERROR_CHECK(err_code);
    }
}

When this is used: err_code = app_uart_put(s[i]); APP_ERROR_CHECK(err_code); and while (app_uart_put(s[i]) != NRF_SUCCESS) is omitted, this function sends continuously bytes which are not in the char* s. If I send 1 byte it sends it normally and I can see it on the terminal, but when I try to send 2 bytes it sends gibberish continuously.

So I've searched for solution and found: while (app_uart_put(s[i]) != NRF_SUCCESS).

Unfortunately, I've used it and now my PCA board is stuck. I can't flash the new code, can't debug, can't erase with nrfjprog --eraseall and can't erase it in nRFgo Studio. It's not recognized at all.

1.) How can I "unstuck" my board? 2.) Is there an implementation of UART which works? I need a simple sending and receiving of bytes over UART, at higer speeds (baud 115200 or above). I've also found fifo implementation but can't get it to send or receive. I use S110.

Thank you!

Regards, Mladen

Parents
  • Hi. I have tried your code and both:

    for (uint8_t i = 0; i < len; i++)
    {
        //while (app_uart_put(s[i]) != NRF_SUCCESS);
        err_code = app_uart_put(s[i]);
        APP_ERROR_CHECK(err_code);
    }
    

    and

    for (uint8_t i = 0; i < len; i++)
    {
        while (app_uart_put(s[i]) != NRF_SUCCESS);
        //err_code = app_uart_put(s[i]);
        //APP_ERROR_CHECK(err_code);
    }
    

    seem to work fine. How have you defined UART_RX_BUFFER_SIZE, UART_TX_BUFFER_SIZE and BLE_MAX_DATA_LEN? Maybe you can post your main.c file?

Reply
  • Hi. I have tried your code and both:

    for (uint8_t i = 0; i < len; i++)
    {
        //while (app_uart_put(s[i]) != NRF_SUCCESS);
        err_code = app_uart_put(s[i]);
        APP_ERROR_CHECK(err_code);
    }
    

    and

    for (uint8_t i = 0; i < len; i++)
    {
        while (app_uart_put(s[i]) != NRF_SUCCESS);
        //err_code = app_uart_put(s[i]);
        //APP_ERROR_CHECK(err_code);
    }
    

    seem to work fine. How have you defined UART_RX_BUFFER_SIZE, UART_TX_BUFFER_SIZE and BLE_MAX_DATA_LEN? Maybe you can post your main.c file?

Children
No Data
Related