Hi Dialog,
I’m trying to build up an UART communication with a periphal device. Later, I’d like to transmit the received data via BLE to another device - I’ve chosen the ble_multi_link Demo to build on.
How is it possible to read out data from UART more than once? Is there any possibility to receive an interrupt when there is data at the rx input?
I've tried the following code, but it leads to recurring resets.
ble_multi_link_task(void*params) {
.
.
for(;;) {
uart_device dev;
int rx_data;
dev = ad_uart_open(SERIAL2);
ad_uart_bus_acquire(dev);
rx_data = ad_uart_read(dev, buf, 4, OS_EVENT_FOREVER);
ad_uart_bus_release(dev);
}
}
Thank you!
Device:
Hi Mario,
A few comments regarding the code that you ve pasted, the multilink is allready using the UART2 module in order to retarget the printf() functionallity ( the CONFIG_RETARGET is the definition that configures and redirects the printf() functionallity to the UART2), also this re-targeting doesn't use the adapters but the LLD drivers so as far as i can tell, you are accessing the same periheral by the Low level drivers and by the adapter, this wont oppose an issue at the moment but if the device gets stressed with data this might cause you problems.
Also you have placed the initialization code for starting the UART adapter in the for(;;) loop of the task, that means that each time this for(;;) executes you execute the same functions (this is not happening though since you are blocking the execution of the task with the UART timeout). Additionally i suppose that you have placed the snippet that you have attached before the watchdog functions execute (sys_watchdog_notify() and sys_watchdog_suspend()). That means that the watchdog is running and you wait forever until 4 bytes of data come to your UART, the code will end up in a watchdog_Handler() before having the chance to do anything.
I dont get exactly what you mean "read data from UART more than once", the ad_uart_read() will block the task until either the time elapses (in your case with the
OS_EVENT_FOREVER这不会发生)或者收到4个字节,此功能还不使用任何回调以通知您,因为该功能已阻止以来数据已到达。您还可以检查AD_UART_READ_ASYNC()函数不会阻止任务,并将等待要接收的指定数量的字节(请注意,在先前的事务完成之前无法连续调用此函数),此函数正在执行当预定义数量的数据到达时,回调。由于SDK使用适配器而不是LLD,适配器使用中断,因此需要一些努力,以便不使用适配器并使用低级驱动程序实现代码,因此使用中断。
The task which will trigger the UART interaction could be either an allready implemented task or a new task that will handle your UART, that depends on your implementation. Also you will have to be aware that when the device is in sleep mode all the peripherals including the UART are powered down, so while in sleep mode you wont be able to have UART interaction unless the device is awake. So you can either have the device allways awake or implement a scheme where before the external device sends data it wakes up the 68x first, that implies that you will have to use hardware flow control in order for the external device to wake up the 68x via the RTS pin.
Lets assume that you would like to read data from the UART one byte at a time and print it back to your terminal, a simple implementation of using the UART on the multilink could be the following.
Thanks MT_dialog
Thanks!
Thanks alot for your detailed reply. After reusing ad_uart_read_async () , i was able to read data from uart just like interrupt. Thanks ,, your detailed answer really helped me. :)