Hello,
This question has been asked many times I guess, but in a project I use the software UART (because the hardware UART is used by a USB/RS232 connection).
This means that the Arduino can't use the interrupt for data appearing on the digital inputs that are used for the software UART.
Enough said
The Arduino sends a package of data to a device via software UART.
This device immediately (45.5µs) responds with another data packet after it received all data from the Arduino.
I'm searching for a way that 100% sure catches the data that are send back by the device and put them into a circular buffer in the Arduino.
Not using an interrupt.
For some strange reason I've managed this in an earlier version of FC but not in FC8.
What is the best tactic to do this?
Catch incoming data without interrupt
Moderator: Benj
-
- Valued Contributor
- Posts: 1188
- Joined: Wed May 31, 2017 11:57 am
- Has thanked: 70 times
- Been thanked: 439 times
- Contact:
Re: Catch incoming data without interrupt
It's possible but not easy. You could busy wait watching the rx pin for a change of state and then receive - we managed this for the j1850 bus (effectively receiving data at 9600,baud) but timing was tight..
Use an Arduino mega. It has multiple tx/rx and this makes life much easier for debugging programs using comms.
Use a different interrupt - use a different pin for the Arduino to signal transmission start - pull a pin high.
Martin
Use an Arduino mega. It has multiple tx/rx and this makes life much easier for debugging programs using comms.
Use a different interrupt - use a different pin for the Arduino to signal transmission start - pull a pin high.
Martin
-
- Posts: 502
- Joined: Wed Nov 07, 2007 6:51 pm
- Location: Antwerp Belgium
- Has thanked: 121 times
- Been thanked: 108 times
- Contact:
Re: Catch incoming data without interrupt
Thank you Martin,mnf wrote: ↑Wed Sep 09, 2020 7:05 amIt's possible but not easy. You could busy wait watching the rx pin for a change of state and then receive - we managed this for the j1850 bus (effectively receiving data at 9600,baud) but timing was tight..
Use an Arduino mega. It has multiple tx/rx and this makes life much easier for debugging programs using comms.
Use a different interrupt - use a different pin for the Arduino to signal transmission start - pull a pin high.
Martin
I've followed a few of your suggestions.
I just have access to a Arduino Nano (168), but I've changed the setup so the software UART uses Port D2 as RX.
This is the INT0 on the chip. (TX of the UART is port D4 at this moment)
But either which setting I use for the interrupt, to read a byte from the UART and store it in the circular buffer.
Even with an interrupt.. there is no decent capturing of data from the RX pin.
I've had this problem before and I don't know why.
I start the interrupt on INT0 input: falling edge... there is an interrupt, but in the macro it calls it only tries to read a byte (receive char) and put this byte in the CB (put byte).
I've tried several ways to interrupt (rising edge .... and so on).
I don't know why, but I've had this problem in FC8 before, and I've managed it in FC7.
Why is working with CB in combination with an interrupt cursed for me?
Isn't it possible with this hardware? Is there still remaining timing problem? Is the chip too slow? Too fast?
The UART speed is 57600bps and this works fine with the hardware attached..
-
- Valued Contributor
- Posts: 1188
- Joined: Wed May 31, 2017 11:57 am
- Has thanked: 70 times
- Been thanked: 439 times
- Contact:
Re: Catch incoming data without interrupt
Try a slower speed - 57600 is pushing it for a software UART..
Can you get it to work at 9600 baud?
Can you post your code?
Martin
Can you get it to work at 9600 baud?
Can you post your code?
Martin
-
- Valued Contributor
- Posts: 1188
- Joined: Wed May 31, 2017 11:57 am
- Has thanked: 70 times
- Been thanked: 439 times
- Contact:
Re: Catch incoming data without interrupt
Another idea - use the CAL_UART component - there are Receive Array / String macros with a timeout. Just used with dfplayer and seem to work well...
-
- Posts: 502
- Joined: Wed Nov 07, 2007 6:51 pm
- Location: Antwerp Belgium
- Has thanked: 121 times
- Been thanked: 108 times
- Contact:
Re: Catch incoming data without interrupt
Thanks MNF..
I've tried (almost) all your suggestions, these and the suggestion from BenJ : https://www.matrixtsl.com/mmforums/view ... 44#p102744
But guess what, I can't seem to get the received data processed..
Even with the CAL component (which I implemented very fast after your suggestion), there seems something wrong.
Is it my chaotic brain? Something with the hardware? Can the CB be used with the Arduino Nano168?
If it's OK with you I will send via PM the latest chart and some screenshots from a logic analyser.
Have a happy weekend!