Hello,
Why I can not use UART? I can send data but can not receive it. Can you help?
Can not run UART
-
- Posts: 143
- http://meble-kuchenne.info.pl
- Joined: Tue Oct 19, 2021 9:31 am
- Has thanked: 73 times
- Been thanked: 5 times
-
- Valued Contributor
- Posts: 998
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 106 times
- Been thanked: 517 times
Re: Can not run UART
You'll need to use an interrupt to catch the data - ReceiveString needs to have the right timing (and probably impossible without using an interrupt handler)
There are several examples dotted around - try viewtopic.php?f=5&t=1788&hilit=uart%5D for an example from Ben.
Martin
There are several examples dotted around - try viewtopic.php?f=5&t=1788&hilit=uart%5D for an example from Ben.
Martin
-
- Valued Contributor
- Posts: 1188
- Joined: Thu Dec 03, 2020 10:57 am
- Has thanked: 289 times
- Been thanked: 418 times
Re: Can not run UART
Hi
The MAX232 is only a driver/receiver chip that enables a microcontroller to handle the voltages typically used in RS232. Take a look at the datasheet, particularly the pinouts for usage. It does not provide any "intelligence".
https://www.ti.com/lit/ds/symlink/max23 ... co.uk%252F
Four-wire flowcontrol is only used to inform the "far end", which could be a modem interface, that the receiver is able and ready to receive data and is irrelevant to your issue.
As Martin said in a previous post you need to use interrupts.
It looks like you have used an Arduino sketch found here https://docs.arduino.cc/tutorials/commu ... alExample/ and near the beginning of the code example it warns that not all pins of the intended chip can be used as not all pins support interrupt on change (IOC)
"Note:
Not all pins on the Mega and Mega 2560 support change interrupts"
So you see even your Arduino sketch is using interrupts to receive data, whereas you are not and are relying on luck that there will be data to receive at the exact time you look.
If you add the RS232 component, then right click it and select "help" you will be taken to the WiKi page for the component and there you will find a good explanation of the component, how to use it and also examples.
This link to the WiKi will explain interrupts
https://www.flowcode.co.uk/wiki/index.p ... Interrupts
Regards
The MAX232 is only a driver/receiver chip that enables a microcontroller to handle the voltages typically used in RS232. Take a look at the datasheet, particularly the pinouts for usage. It does not provide any "intelligence".
https://www.ti.com/lit/ds/symlink/max23 ... co.uk%252F
Four-wire flowcontrol is only used to inform the "far end", which could be a modem interface, that the receiver is able and ready to receive data and is irrelevant to your issue.
As Martin said in a previous post you need to use interrupts.
It looks like you have used an Arduino sketch found here https://docs.arduino.cc/tutorials/commu ... alExample/ and near the beginning of the code example it warns that not all pins of the intended chip can be used as not all pins support interrupt on change (IOC)
"Note:
Not all pins on the Mega and Mega 2560 support change interrupts"
So you see even your Arduino sketch is using interrupts to receive data, whereas you are not and are relying on luck that there will be data to receive at the exact time you look.
If you add the RS232 component, then right click it and select "help" you will be taken to the WiKi page for the component and there you will find a good explanation of the component, how to use it and also examples.
This link to the WiKi will explain interrupts
https://www.flowcode.co.uk/wiki/index.p ... Interrupts
Regards