关于UART的更多问题

⚠️
Hi there.. thanks for coming to the forums. Exciting news! we’re now in the process of moving to our new forum platform that will offer better functionality and is contained within the main Dialog website. All posts and accounts have been migrated. We’re now accepting traffic on the new forum only - please POST any new threads at//www.xmece.com/support. We’ll be fixing bugs / optimising the searching and tagging over the coming days.
3 posts / 0 new
Last post
Max44
Offline
最后一次露面:10 months 1 day ago
加入:2016-02-08 15:58
关于UART的更多问题

Hello Dialog,

I'm also trying to set up communications with an external MCU via UART. I'm trying to integrate this into a custom service based on the ble_app_peripheral example running on a DA14580. I'm using a basic DK for development and debug. Serial data rate is set to 115200 baud and I'm not using flow control. I'm using P0_4 as the Tx pin and P0_5 as the Rx pin. I added a pullup to the Rx pin. Waveforms look OK monitoring on a scope. I'm also able to run the SDK uart2_async example, so I know the UART and the DK work.

As others have recently reported, I'm able to send data from the DA to the MCU without any issues. So far, I'm unable to receive data transmitted from the MCU to the DA using the uart_read function. Initially I'm trying a small packet of 10 bytes. I seem to be getting a uart2_rec_data_avail_isr, but I don't see the data I'm transmitting appear in the receive buffer.

A few questions I initially have are:

Where should I put the initial uart2_read setup in the ble_app_peripheral code? I tried it in user_peripheral_setup.c at the end of peripheral_init().

Can I have a receive buffer of more than 16 bytes? From reading the previous posts, it seems the hardware FIFO might limit you to 16 bytes or less. Does the external MCU need to transmit in chunks of 16 bytes or less?

如果我曾经到了UART2_READ_COMPLETION_CB,我可以在那里放另一个uart2_read来查找来自MCU的另一个输入吗?其他帖子似乎意味着这不起作用,下一个读取应该在回调例程之外。

谢谢你,马克斯
.

Device:
mt_dialog.
Offline
最后一次露面:3个月16小时前
工作人员
加入:2015-06-08 11:34
Hi Max44,

Hi Max44,

1)在哪里可以放置UART2_READ()以期望来自UART的数据取决于您的应用程序,例如在初始化UART之后,请在Periph_init()函数中放置UART2_READ()函数的UART2_READ()函数(i假设这是您还放置了代码的地方)。因此,只需添加此UART2_READ((UINT8_T *)缓冲区,READ_CHAR_COUNT,UART2_READ_COMPLETION_CB);一旦我在我的缓冲区中拥有可用的字节编号,我就可以获得UART2_READ_COMPLETION_CB()。

2) Regarding the size of your receive buffer, yes you can have an application buffer larger than the actual hardware UART buffer, you can just read the data from the hw FIFO and place them in your application buffer, off course you should take care of the write and read indices in order to be aware which data are processed by your application and which data should be processed. Regarding the amount of data that the external MCU should send, you will have to make sure that the data that the 580 receives are read from your application, if the external MCU sends data and the application hasn't read them from the UART fifo then the remaining data in the FIFO will be overwritten. The h/w fifo has functionallities in order to inform the application regarding the amount of data available in the FIFO and also implements a automatic flow control scheme in order to notify the external MCU to flow off.

3) Yes, you can place an additional UART read in the completion callback in order to start a new read transaction, this is exactly what the DSPS application does, the uart_rx_callback() is the callback function that will be triggered when the device gets the desired amount of data, when that function is triggered a new transaction is initiated from that callback function using the uart_sps_read() which is equivalent with the uart2_read() function.

Some notations regarding the usage of the UART, be aware that when the device is in sleep all the peripherals including the UART are shut down, therefore there is not going to be any reception when the device is sleeping. Some examples that would help you in using the UART on the 580 are the DSPS project and the Codeless demo.

谢谢mt_dialog.

Max44
Offline
最后一次露面:10 months 1 day ago
加入:2016-02-08 15:58
公吨,

公吨,

Thanks for verifying that the UART function works as I had planned and the extra effort to run a quick test. Much appreciated!

After your feedback, I checked my jumper wire connections from the basic kit to the external MCU board and found I was not connected to the correct pins. After I got that straightened out, the uart_read() functioned correctly in my modified ble_app_peripheral code. I also verified that putting another uart_read() in the receive completed callback would allow me to receive multiple blocks of input data to the application. I also tried a larger block of data (256 bytes) and that worked fine as well. I was even able to take the data values received and add them to the database for my custom characteristics and read them on an Android tablet. Good to go here!

Thanks again for your help, Max