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
}
Parents
  • Update

    I've modified the callback function. After enabling the transmission and attempting to send 8 bytes, the uart_fill_fifo function correctly returns 8 bytes. However, when I check if the transfer is complete using the uart_irq_tx_complete function, it does not return 1 as expected.

    if (!(uart_irq_rx_ready(uart_dev) || uart_irq_tx_ready(uart_dev)))
        {
            LOG_DBG("spurious interrupt");
        }
        if (uart_irq_tx_ready(uart_dev))
        {
            int tx_sent = uart_fifo_fill(uart_dev, (uint8_t *)tx_buf, tx_data_length);
            printf("tx_sent: %u\n", tx_sent);
            printf("Data to be sent length = %u\n",tx_data_length);
            if (tx_sent <= 0)
            {
                printf("Error %d sending data over UART1 bus\n", tx_sent);
                return;
            }

            while (uart_irq_tx_complete(uart_dev) != 1)
            {
                printf("Wait for UART0 data transmition complete\n");
            }
            printf("UART0 data transmitted\n");
            uart_irq_tx_disable(uart_dev);
            k_sem_give(&tx_sem);
        }
Reply
  • Update

    I've modified the callback function. After enabling the transmission and attempting to send 8 bytes, the uart_fill_fifo function correctly returns 8 bytes. However, when I check if the transfer is complete using the uart_irq_tx_complete function, it does not return 1 as expected.

    if (!(uart_irq_rx_ready(uart_dev) || uart_irq_tx_ready(uart_dev)))
        {
            LOG_DBG("spurious interrupt");
        }
        if (uart_irq_tx_ready(uart_dev))
        {
            int tx_sent = uart_fifo_fill(uart_dev, (uint8_t *)tx_buf, tx_data_length);
            printf("tx_sent: %u\n", tx_sent);
            printf("Data to be sent length = %u\n",tx_data_length);
            if (tx_sent <= 0)
            {
                printf("Error %d sending data over UART1 bus\n", tx_sent);
                return;
            }

            while (uart_irq_tx_complete(uart_dev) != 1)
            {
                printf("Wait for UART0 data transmition complete\n");
            }
            printf("UART0 data transmitted\n");
            uart_irq_tx_disable(uart_dev);
            k_sem_give(&tx_sem);
        }
Children
No Data
Related