Dear ,
I am using nrf 9160 DK,
and trying to send a package of data to UART.
For example my package is: "LONGITUDEx:10.123456,LATITUDE:59.012324,UTC:20190513095612"
I tried to use: uart_fifo_fill(struct device *dev, const u8_t *tx_data, int size) to send.
But I got the problem, the package is too long ( longer than u8_t ?!), so i just send 32bytes of my package: "LONGITUDE1:10.123456,LATITUDE:59"
I tried to split to 2small packages and send without delay between them. Result: only 1 package is sent! I lost another one
split to 2small packages, and added a delay between them, and send. It sent
I don't want the delay between them. I want to send a continuous package (more than 32bytes). How can I do it? Can you help me.
My code:
static u8_t uart_buf[1024]; static K_FIFO_DEFINE(fifo_uart_tx_data); static K_FIFO_DEFINE(fifo_uart_rx_data); struct uart_data_t { void *fifo_reserved; u8_t data[1024]; u16_t len; }; /********************************************/ void uart_cb(struct device *x) { uart_irq_update(x); int data_length = 0; if (uart_irq_rx_ready(x)) { data_length = uart_fifo_read(x, uart_buf, sizeof(uart_buf)); uart_buf[data_length] = 0; } printk("%s", uart_buf); if (uart_irq_tx_ready(x)) { struct uart_data_t *buf = k_fifo_get(&fifo_uart_tx_data, K_NO_WAIT); u16_t written = 0; /* Nothing in the FIFO, nothing to send */ if (!buf) { uart_irq_tx_disable(x); return; } while (buf->len > written) { written += uart_fifo_fill(x, &buf->data[written], buf->len - written); } while (!uart_irq_tx_complete(x)) { /* Wait for the last byte to get * shifted out of the module */ } if (k_fifo_is_empty(&fifo_uart_tx_data)) { uart_irq_tx_disable(x); } k_free(buf); } } void main (void) { struct device *uart_send= device_get_binding("UART_2"); uart_irq_callback_set(uart_send, uart_cb); printk("Testing1: \n"); uart_fifo_fill(uart_send, "LONGITUDE1:10.123456,LATITUDE:59.012324,UTC:20190513095612\r" ,sizeof("LONGITUDE:10.123456,LATITUDE:59.012324,UTC:20190513095612\r")); k_sleep(100); printk("Testing2: \n"); uart_fifo_fill(uart_send, "LONGITUDE2:10.123456,LATITUDE:5" ,sizeof("LONGITUDE:10.123456,LATITUDE:5")); uart_fifo_fill(uart_send, "9.012324,UTC:20190513095612\r" ,sizeof("9.012324,UTC:20190513095612\r")); k_sleep(100); printk("Testing3: \n"); uart_fifo_fill(uart_send, "LONGITUDE3:10.123456,LATITUDE:5" ,sizeof("LONGITUDE:10.123456,LATITUDE:5")); k_sleep(1); uart_fifo_fill(uart_send, "9.012324,UTC:20190513095612\r" ,sizeof("9.012324,UTC:20190513095612\r")); printk("Done testing\n"); while (1) { k_cpu_idle(); } }
Thanks so much
Hng