Page 1 of 1
UART send command to one device and receive in another
Posted: Tue Feb 28, 2023 1:03 am
by flowcode-developer
Hi,
I am new here. Using the AVR chipset. I was wondering why this could does not work the way I want it to? The objective is to send a command from AVR2560 to a device then receive the info from that device and send to the PC. I added my code below.
Re: UART send command to one device and receive in another
Posted: Tue Feb 28, 2023 7:25 am
by mnfisher
You need to look at using a receive interrupt to get the message.
It is rarely successful to use receive string - timing is not on your side.
Martin
Re: UART send command to one device and receive in another
Posted: Wed Mar 01, 2023 12:27 am
by flowcode-developer
I tried interrupts and I do not understand them for UART. I do not understand why I need to make a macro for the interrupt. I made a macro where I put in the receivestring. I must be doing something wrong.
Re: UART send command to one device and receive in another
Posted: Wed Mar 01, 2023 12:05 pm
by BenR
Hello,
Here is a slightly reworked version of your program.
In this we initialise the two UARTs and then output a string every 3 seconds to UART 1.
For UART 2 we have enabled an interrupt to catch any incoming data and this data is then fed into the Circular Buffer component. This allows you to check for what has been received as part of your main loop and ensures you don't miss any data (assuming there is still room in the buffer).
Hope this helps.
Re: UART send command to one device and receive in another
Posted: Wed Mar 08, 2023 10:16 pm
by flowcode-developer
Found an explanation of interrupts that helped my understanding of them.
https://www.youtube.com/watch?v=pOsyUyLcqHU