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

Write loop

Hi

I am using SDK15.2 and trying to do a loop of serial write.

The first write is ok, but all other writes fail.

This is the code I am using:

#include "nrf_serial.h"

#define d_NA 0

NRF_SERIAL_DRV_UART_CONFIG_DEF(m_uart0_drv_config,
                      Motor_Dir, Step_Pulse_PWM,
                      d_NA, d_NA,
                      NRF_UART_HWFC_DISABLED, NRF_UART_PARITY_EXCLUDED,
                      NRF_UART_BAUDRATE_115200,
                      UART_DEFAULT_CONFIG_IRQ_PRIORITY);

#define SERIAL_FIFO_TX_SIZE 32
#define SERIAL_FIFO_RX_SIZE 32

NRF_SERIAL_QUEUES_DEF(serial_queues, SERIAL_FIFO_TX_SIZE, SERIAL_FIFO_RX_SIZE);

#define SERIAL_BUFF_TX_SIZE 1
#define SERIAL_BUFF_RX_SIZE 1

NRF_SERIAL_BUFFERS_DEF(serial_buffs, SERIAL_BUFF_TX_SIZE, SERIAL_BUFF_RX_SIZE);

NRF_SERIAL_CONFIG_DEF(serial_config, NRF_SERIAL_MODE_IRQ,
                      &serial_queues, &serial_buffs, NULL, NULL);
NRF_SERIAL_UART_DEF(serial_uart, 0);
/*********************   Serial port definitions  **************************/

Status_Code SetSerialConnection(void)
{
    ret_code_t ret;

    // Free Pin 17 and Pin 19
    nrf_gpio_pin_write(Step_Pulse_PWM, Disable);    // Pin17 - Tx
    nrf_gpio_pin_write(Motor_Dir, Disable);         // Pin19 - RX

    ret = nrf_serial_init(&serial_uart, &m_uart0_drv_config, &serial_config);
    if (ret != NRF_SUCCESS)
    {
        printf("nrf_serial_init FAIL-%d\r\n", ret);
        return(e_Status_Fail);
    }
    else
    {
        #define d_TimeOutMs     100
        char l_cTxCommand[] = "Get Results\r\n";
        size_t l_iNumBytesWriten;

        printf("nrf_serial_init OK-%d\r\n", ret);

        while(1)
        {
            vTaskDelay( pdMS_TO_TICKS(15*1000));
            ret = nrf_serial_write(&serial_uart, l_cTxCommand, strlen(l_cTxCommand),
                                   &l_iNumBytesWriten, NRF_ERROR_TIMEOUT );
            if (ret != NRF_SUCCESS)
            {
                printf("nrf_serial_write FAIL-%d\r\n", ret);
                //return(e_Status_Fail);
            }
            else
            {
                printf("nrf_serial_write OK. Bytes writen-%d\r\n", l_iNumBytesWriten);
                //return(e_Status_OK);
            }
        }
    }
}

And these are the results:

Start UV calibration
nrf_serial_init OK-0
Start Consol
nrf_serial_write OK. Bytes writen-13
nrf_serial_write FAIL-8
nrf_serial_write FAIL-8nrf_serial_write FAIL-8
nrf_serial_write FAIL-8

It seems to me that the problem is with the creation of the timer.

What shell I do to make it to work?

Thanks

Arik

Parents
  • So nrf_serial_write returns 8 == NRF_ERROR_INVALID_STATE when you try to call it after the first time.

    I guess it is because the check inside nrf_serial_write:

    if (!(p_serial->p_ctx->flags & NRF_SERIAL_TX_ENABLED_FLAG))

    returns true. I can't see any obvious reason, but here are a few things you can check:

    1. Your log says "Start UV calibration" and "Start Consol", so I suspect that the snippet that you attached is a simplified snippet, since this doesn't print those lines? What do you do between nrf_serial_init() and nrf_serial_write()? Or are those prints from another thread?

    2. You use this delay, vTaskDelay(). Can it be that the UART doesn't get time to be processed? Perhaps you can try with another form of delay, like a timer or something to allow the UART to print in between the calls to nrf_serial_write?

    BR,

    Edvin

  • Hi,

    OK. Ifound the problem. the parameter NRF_ERROR_TIMEOUT  should be changed to NRF_SERIAL_MAX_TIMEOUT

    Thanks

Reply Children
No Data
Related