I'm using an application based on the MQTT_CLIENT example. Without any change, it worked fine.
Now I tried to add UART2 as a communication channel to another controller.
Following is my added code:
void uart_cb(struct device *x)
{
uart_irq_update(x);
int data_length = 0;
if (uart_irq_rx_ready(x))
{
if (uart_irq_update(x))
{
data_length = uart_fifo_read(x, uart_buf, sizeof(uart_buf));
uart_buf[data_length] = 0;
}
}
if (uart_irq_tx_ready(x))
{
//const struct uart_driver_api *api =(const struct uart_driver_api *)x->api;
//api->fifo_fill(x, uart_buf, 1);
//api->tx(dev, buf, len, timeout);
//uart_tx(x, uart_buf, 1,0);
}
//if (uart_irq_tx_ready(x))
//printk("%s", uart_buf);
}
and in main() function:
const struct device *uart2 = device_get_binding((const char *)"UART_2");
struct uart_config cfg;
cfg.baudrate = 115200;
cfg.parity = UART_CFG_PARITY_NONE;
cfg.stop_bits = UART_CFG_STOP_BITS_1;
cfg.data_bits = UART_CFG_DATA_BITS_8;
cfg.flow_ctrl = UART_CFG_FLOW_CTRL_NONE;
uart_configure(uart2, &cfg);
uart_irq_callback_set((const struct device *)uart2, (uart_irq_callback_user_data_t)uart_cb);
uart_irq_rx_enable(uart2);
uart_irq_tx_enable(uart2);
Any idea?
10x, Uri.