View previous topic :: View next topic |
Author |
Message |
davidmoran
Joined: 31 Dec 2019 Posts: 14
|
Posted: Thu May 19, 2022 2:10 am Post subject: Software UART and WAITKEY - Exit if no incoming data |
|
|
This may have been answered before, but I couldn't' find it in a search.
I guess I am looking for the best way to send and receive binary data over a software serial port.
I added a software UART to an ATMEGA2560 circuit on some unused pins using the OPEN COM...(#4) command. It works fine, and I can get my serial data in and out. However, the only BASCOM command to receive the input data from a software defined UART appears to be the WAITKEY command, and this will wait forever if there is no incoming serial data. I need to be able to exit the WAITKEY command if no data is received after I request it, after some timeout. Do any of the other serial commands like ISCHARWAITING work with the software UART?
I have done some testing, and it appears that if the software UART input is LOW, the WAITKEY will proceed, and return a value of $00, with or without the $TIMEOUT command. However, if the software UART input is HIGH, then the WAITKEY will hang forever. I have tried adding the $TIMEOUT = 1000000 command, but it does not seem to prevent this issue. Perhaps this is because of the Port Number I opened?
Using INKEY or GET instead of WAITKEY seems to give the same results. I cannot use INPUT, because the input is binary data, without CR or LF.
I looked at the newer SERIN and SEROUT commands, but they are only for Strings as well, and I'm not sure if they provide a timeout feature either. Also, the Baud rate calculation seems to be pretty far off, at least in version 2.0.8.2. Perhaps there is a way to use strings with binary data, but since $00 is in the data, I think that would terminate the string.
Any other ideas on how to accomplish this would be appreciated.
Thanks,
Dave
(BASCOM-AVR version : 2.0.8.2 , Latest : 2.0.8.5 ) |
|
Back to top |
|
|
EDC
Joined: 26 Mar 2014 Posts: 971
|
Posted: Thu May 19, 2022 5:13 am Post subject: |
|
|
From the Help: "$Timeout - Enable timeout on the hardware UART and software UART."
Works like a charm. Why don`t you upgrade Bascom into 2085?
BTW. All four USARTS from Mega2560 you have used already or this is unefficient design? |
|
Back to top |
|
|
davidmoran
Joined: 31 Dec 2019 Posts: 14
|
Posted: Thu Jun 02, 2022 6:14 pm Post subject: |
|
|
Thank you for the information. I am switching from a dumb sensor with a TTL logic interface to a smart sensor with a serial interface while using the same IO pins, that is why I need a software-defined UART. The other hardware UARTs are also all in use.
I was using the slightly older version of BASCOM because we have a development environment freeze on this project. I have experimented with the 2.0.8.5 version with similar results.
With the $TIMEOUT command added, I think it is indeed moving past the WAITKEY command with no data input, and with the serial input pin either HIGH or LOW. However, I still see some cases where it appears to hang up, so I am trying to resolve what is happening there. Thanks for the help. |
|
Back to top |
|
|
enniom
Joined: 20 Oct 2009 Posts: 537
|
Posted: Fri Jun 03, 2022 2:27 am Post subject: |
|
|
DavidMoran,
Difficult to answer your question without a Code Example from you that shows (or occasionally shows) the problem.
E |
|
Back to top |
|
|
|
|
You can post new topics in this forum You can reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|