UART tx using thingy91

Hello,

I am using uart with thingy:91 to communicate between nrf52 SoC and nrf91 SiP, i am able to receive data from nrf52 but when i try to send data to nrf52 SoC the function uart_irq_tx_ready always returns 0 "UART TX is not ready", btw I am using uart0 for both nrf52 and nrf91 and for nrf91 I am using interrupt driven mode and for nrf52 I am using async api mode.

Here is my init code for nrf91 SiP and how i try to send data:

void uart_init(void)
{
    int ret;
  if (!uart_dev) {
    LOG_ERR("UART_0 failed");
    return;
  }
  ret = uart_irq_callback_user_data_set(uart_dev, uart_cb, NULL);
  if (ret < 0)
  {
    if (ret == -ENOTSUP)
    {
      LOG_ERR("Interrupt-driven UART API support not enabled\n");
    }
    else if (ret == -ENOSYS)
    {
      LOG_ERR("UART device does not support interrupt-driven API\n");
    }
    else
    {
      LOG_ERR("Error setting UART callback: %d\n", ret);
    }
    return 0;
  }
  uart_irq_rx_enable(uart_dev);
  LOG_INF("UART initialized");
}
void send_data_to_nrf52(int64_t timestamp_unix)
{
    int ret;
    uint8_t data[8];
    int64_to_uint8_array(data, timestamp_unix);
    LOG_DBG("Sending : %x | %x | %x | %x | %x | %x | %x | %x ", data[0],data[1],data[2],data[3],data[4],data[5],data[6],data[7]);
    uart_irq_tx_enable(uart_dev);
    if (!uart_irq_update(uart_dev)) {
    LOG_DBG("uart_irq_update failed");
    return;
    }
    if(uart_irq_tx_ready(uart_dev) == 0) // the issue is here always 0
    {
        LOG_ERR("UART TX not ready");
        uart_irq_tx_enable(uart_dev);
    }
    // Enable TX interrupt
   
    ret = uart_fifo_fill(uart_dev, data, sizeof(data));
    if(ret == ENOSYS || ret == ENOTSUP)
    {
        LOG_ERR("UART device does not support interrupt-driven API , error code : %d",ret);
    }
    else
    {
        LOG_INF("Data sent to nrf52 , number of bytes sent : %d",ret);
    }
    uart_irq_tx_disable(uart_dev); // disable the tx interrupt
}
  • Hi Torbjørn,

    I have disabled the UART console, but I am still encountering the same issue.

    Here is my prj.conf file:

    CONFIG_GPIO=y
    CONFIG_SERIAL=y
    #CONFIG_UART_INTERRUPT_DRIVEN=y
    CONFIG_LOG=y
    CONFIG_COREDUMP_DEVICE=y
    CONFIG_DEBUG_COREDUMP=y
    CONFIG_DEBUG_COREDUMP_BACKEND_LOGGING=y
    CONFIG_FPU=y
    CONFIG_UART_CONSOLE=n

    i tried also to disable CONFIG_SERIAL but the same problem.

    Best regards

    Youssef

  • Now, when i have activated uart0, so status = "okay" there's no error, but when i tried to send data over lpuart, the function uart_irq_handler returns 5 for the first time then it returns 0 bytes.

    here's my callback :

    static void uart_irq_handler(const struct device *dev, void *context)
    {
        uint8_t buf[] = {1, 2, 3, 4, 5};
        printk("uart_irq_handler\n");
        if (uart_irq_tx_ready(dev)) {
            int ret = uart_fifo_fill(dev, buf, sizeof(buf));
            printk("fill %d bytes\n", ret);
            uart_irq_tx_disable(dev);
        }

        if (uart_irq_rx_ready(dev)) {
            uint8_t buf[10];
            int len = uart_fifo_read(dev, buf, sizeof(buf));

            if (len) {
                printk("read %d bytes\n", len);
            }else{
                printk("no data %d bytes\n",len);
            }
        }
    }

    it returns : fill 5 bytes , then fill 0 bytes

    Best regards,

    Youssef

  • Hi Youssef

    I believe you need CONFIG_UART_INTERRUPT_DRIVEN and CONFIG_NRF_SW_LPUART_INT_DRIVEN enabled if you want to use these functions. 

    In many cases I think the ASYNC interface is more convenient. Have you tried to use this instead? 

    Best regards
    Torbjørn

  • Hi Torbjørn,

    I have already set CONFIG_UART_INTERRUPT_DRIVEN  and CONFIG_NRF_SW_LPUART_INT_DRIVEN but the same issue,

    the first image shows that the lpuart sends 8 bytes as expected for the first try, but then it sends only 0 as shown in the second image

    Send 8 bytes for the first time

    Send 0 bytes

    I have tried to use uart1 and uart 0 with async but it doesn't work, does lpuart supports async mode ?

    Best regards

    Youssef

  • Hi Torbjørn,

    Following your suggestion, I tried using UART1 in async mode for communication between the nRF52 and nRF91. However, I encountered some issues:

    1. On the nRF52 side, whenever I send data, the callback jumps to the UART_TX_ABORT case instead of UART_TX_DONE.
    2. On the nRF91 side, when I send data over UART1, the callback correctly calls UART_TX_DONE, but nothing is received on the nRF52.

    Best regards

    Youssef

Related