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

Receiving only one char through uart interrupt in Serial_uartes

Hi there,

I'm using nrf52840 DK and Custom board, SDK 15.1.0, Segger Embedded Studio(SES v5.20)

my issue is when i receive data from uart interrupt based on serial uartes example, i can only receive one char at a time. that means if i store that data in a char variable and should add to the char array then its works fine, but i want to read the complete data on single shot, so how can i do that,? i'm i doing anything wrong.

void GSM_InterruptHandler(nrf_serial_t const *p_serial, nrf_serial_event_t event)
{
static uint8_t index1=0;
char bb;
switch (event)
  {
    case NRF_SERIAL_EVENT_RX_DATA:
      if((nrf_serial_read(&serial0_uarte, &bb, sizeof(bb), &readed_size, 500))==NRF_SUCCESS)
      {
      gsm_d.RxBuf[index1++] = bb;
      rx_done = true;
      }
      break;
    case NRF_SERIAL_EVENT_TX_DONE:
      tx_done = true;
      break;
    case NRF_SERIAL_EVENT_DRV_ERR:
      APP_ERROR_CHECK(nrf_serial_uninit(&serial0_uarte));
      APP_ERROR_CHECK(nrf_serial_init(&serial0_uarte, &m_uarte1_drv_config, &serial0_config));
      break;
    case NRF_SERIAL_EVENT_FIFO_ERR:
      break;
    default:
      break;
  }
}

Im reading the rx buff like this, but its triggers multiple times for every rx event, and i need like this

case NRF_SERIAL_EVENT_RX_DATA:
      if((nrf_serial_read(&serial0_uarte, &gsm_d.RxBuf, sizeof(gsm_d.RxBuf), &readed_size, NRF_SERIAL_MAX_TIMEOUT))==NRF_SUCCESS)
      {
      rx_done = true;
      }
      break;

so please help me

Thanks in advance

Best Regards

Raj

Parents
  • Rajender,

    I have now tested your latest project where you are testing nrf_libuarte.

    I have connected the pins for the uarte0 to the peer board that is transmitting this below thing in a loopback

    "Testing this exampple with UART example started.\r\n Loopback:\r\n";

    I have  breakpoint where the uart_event_handle processes the data. 

    Looking into the memory pointer of the received event, I can see that the length and data are correct and not a single char.

Reply
  • Rajender,

    I have now tested your latest project where you are testing nrf_libuarte.

    I have connected the pins for the uarte0 to the peer board that is transmitting this below thing in a loopback

    "Testing this exampple with UART example started.\r\n Loopback:\r\n";

    I have  breakpoint where the uart_event_handle processes the data. 

    Looking into the memory pointer of the received event, I can see that the length and data are correct and not a single char.

Children
  • I used a simple setup as below

    PCA10056 DK is running your project and the PCA10040 (nrf52832) is running below project

    6457.libuarte.zip

    So, I do not know why you are receiving only one character when the single transaction tested on your project without any changes shows that the RX event has multiple chars in it.

  • I could guess that rx timeout is too short:

        nrf_libuarte_async_config_t nrf_libuarte_async_config = {
                ...
                .timeout_us = 100,
        };

    Maybe increasing it to 1000 will help.

  • Hi Susheel,

    i have again tested my code with timeout_us=1000 as suggested by "Dmitry", and still i can receive only one byte at a time.

    i'm currently receiving this data from a energy meter using RS-485(UART) and i can see only 1st byte(one byte) when interrupts triggers.

    please guide us to come out of this issue

    Best Regards,

    Raj.

  • Have you tested your project again any other UART peer?  If not, I suggest you test that. I have used your project unedited and it works OK with the peer that is doing a multibyte transfer. 

    Could it be possible that your peer serial device is having spaces between each byte transfers? Do you have a logic analyzer or an oscilloscope to see the incoming transactions? Can you test your project against the peer I tested with (attached project in my previous reply tested on pca10040?

    The reason I am asking you to test this because I think your product/project handles reception correctly and it looks to me that the peer serial device does not transmit data continuously  If there are spaces between characters then the UART RX will get an interrupt for every single char it gets and the RX seems to be processed before the next char is received. Just my theory, since nothing else explains this behavior when i see different results with your unedited project

  • Hi Susheel,

    I have checked with the code with Serial terminal software and its working fine for even multi byte reading.

    after that i have also checked this same peer and code by increasing the timeout_us=10000;

    then this code is also working with multibyte reading. 

    finally i can say that its working fine as i intended to.

    Thanks for your help.

    Best Regards,

    Raj.

Related