I have a nRF9160 custom board. I am using 2 UARTs (UART0 and UART2). I need to have an RX interrupt on both UARTs. I have identical setups and configuration and code. The RX interrupt works for UART0 but not for UART2. polling of the RX works for UART2 but I do not see an RX interrupt on UART2. my setup and test code is shown below
my setup for the interrupts is shown below
/* enable Uart_0 interrupts so UART_0 */
uart_irq_callback_set(uart0_dev, uart2_cb);
uart_irq_rx_enable(uart0_dev);
uart_irq_tx_disable(uart0_dev);
/* enable Uart_2 interrupts so UART_2 */
uart_irq_callback_set(uart2_dev, uart2_cb);
uart_irq_rx_enable(uart2_dev);
uart_irq_tx_disable(uart2_dev);
my callbacks are the following
void uart0_cb(const struct device *dev, void *user_data)
{
uint8_t i;
int data_length = 0;
uint8_t temp_buf[16];
uart_irq_update(dev);
if (uart_irq_rx_ready(dev))
{
data_length = uart_fifo_read(dev, temp_buf, sizeof(temp_buf));
if(data_length > 0)
{
for(i=0; i < data_length; i++)
{
uartData.data[fifoPtr++] = temp_buf[i];
uartData.len = fifoPtr;
if(temp_buf[i] == '\r')
{
k_fifo_put(&fifo_uart_rx_data, &uartData);
fifoPtr = 0;
}
}
}
}
}
void uart2_cb(const struct device *dev, void *user_data)
{
uint8_t i;
int data_length = 0;
uint8_t temp_buf[16];
uart_irq_update(dev);
if (uart_irq_rx_ready(dev))
{
data_length = uart_fifo_read(dev, temp_buf, sizeof(temp_buf));
if(data_length > 0)
{
for(i=0; i < data_length; i++)
{
uart2Data.data[fifoPtr2++] = temp_buf[i];
uart2Data.len = fifoPtr2;
if(temp_buf[i] == '\r')
{
k_fifo_put(&fifo_uart2_rx_data, &uart2Data);
fifoPtr2 = 0;
}
}
}
}
}
my test is the following
#if 0
/* test of RX interrupt from UART0 */
struct uart_data_t *bufx;
uint8_t uart0In[30];
while(1)
{
printk("UART0 RX test\r\n");
bufx = k_fifo_get(&fifo_uart_rx_data, K_FOREVER); /* check if command line seen on UART */
if (bufx)
{
strncpy(uart0In,bufx->data,bufx->len);
uart0In[bufx->len] = '\n';
uart0In[bufx->len + 1] = '\0';
printk("Uart0In: %d %s",strlen(uart0In),uart0In);
}
}
#endif
#if 0
/* test of RX interrupt from UART2 */
struct uart_data_t *bufx;
uint8_t uart2In[30];
while(1)
{
printk("UART2 RX test\r\n");
bufx = k_fifo_get(&fifo_uart2_rx_data, K_FOREVER); /* check if command line seen on UART */
if (bufx)
{
strncpy(uart2In,bufx->data,bufx->len);
uart2In[bufx->len] = '\n';
uart2In[bufx->len + 1] = '\0';
printk("Uart2In: %d %s",strlen(uart2In),uart2In);
}
}
#endif