More questions on UART read

⚠️
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
Last seen:10个月s 14 hours ago
加入:2016-02-08 15:58
More questions on UART read

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,可以I just put another uart2_read there to look for another input from the MCU? Other posts seem to imply this doesn't work and the next read should be outside of the callback routine.

谢谢你,马克斯
.

Device:
MT_dialog
Offline
Last seen:3 months 3 hours ago
Staff
加入:2015-06-08 11:34
Hi Max44,

Hi Max44,

1) Where you could place the uart2_read() in order to expect data from the UART depends on your application, for example for a quick test i ve placed the uart2_read() function in the periph_init() function right after initializing the UART (i suppose that this is where you also placed the code). So by just adding this uart2_read((uint8_t *)buffer, READ_CHAR_COUNT, uart2_read_completion_cb); i could get the uart2_read_completion_cb() triggered as soon as i have the available byte number in my buffer.

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.

Thanks MT_dialog

Max44
Offline
Last seen:10个月s 14 hours ago
加入:2016-02-08 15:58
MT,

MT,

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