Page 1 of 1
UART string variable question (quick question)
Posted: Sun Jun 30, 2019 12:39 am
by MJU
I have a string variable "mytext"
In Flowcode I fill this with text=>
Code: Select all
mytext= "This My Text I want to transmit"
The I send it as a string via the UART (which works).
On the receiver side the text becomes gibberish.
When I send the text without using the variable, the RX receives it well.
Code: Select all
UART1 send string "This My Text I want to transmit"
How can I use variable text to send with the UART?
Re: UART string variable question (quick question)
Posted: Sun Jun 30, 2019 6:17 am
by chipfryer27
Hi
Following on from previous posts I assume you are using the E32 LoRa modules and an Arduino. I don't yet use an Arduino (but have just acquired a Nano) so I can't help with anything chip specific, therefore I just set up using a PIC.
LoRa set up as broadcast (default values) and a String variable called Test created in FC. In a calculation I set Test = "Test-2" and I have a loop with two buttons
Button - 1 uses the command UART SendString("Test-1")
Button - 2 uses the command UART SendString (Test)
- Switch.JPG (26.14 KiB) Viewed 2875 times
Button - 2 therefore sends my variable called Test and I can set this to whatever I want.
This PIC connects directly to a LoRa module.
Another LoRa module connects to a PC running Terminal (free terminal program) and can display either in Hex or ascii. In tests pushing either button successfully sends the data to the other module and displays correctly in Terminal.
In the attached you will see the results of pushing Button-1 then Button-2.
- Terminal.jpg (85.85 KiB) Viewed 2875 times
So as the units /UART are sending correctly perhaps look at how you are receiving on the Arduino? Maybe check with your analyser what is happening on the Arduino Rx pin?
Hope this is of some small help.
Regards
Re: UART string variable question (quick question)
Posted: Sun Jun 30, 2019 2:06 pm
by MJU
Thanks Chipfryer,
You are right about the hardware I'm using and testing.
Strange thing is that, what I used last night, and flashed again and again, didn't work, but today I changed a small thing and now the text is send as it should. The small thing I changed had nothing to do with the variable...
Creepy stuff sometimes
But now I have another issue:
- FC1.jpg (32.46 KiB) Viewed 2858 times
In this example I wait until the AUXpin variable goes low and then try to receive a string via UART1.
I see via my logic analyser that there is text received, but not stored into the variable "receivetext".
When the AUX pin goes low, the transfer of data is held for a few microseconds.
The module I"m working with holds this to give the microcontroller the time to wake up.
The time between the AUXpin going low and the sending of the data is about 5ms (datasheet).
But which confuses me all the time is the waiting time in the Flowcode UART component.
I tried several settings (from 0 to 255), but strangely the variable "receivetext" is empty all the time.
How can I make sure the data that comes from the module gets into the variable "receivetext"?
Thanks!
Re: UART string variable question (quick question)
Posted: Sun Jun 30, 2019 4:31 pm
by chipfryer27
Hi
I would strongly be tempted to use the RxInt Interrupt feature when capturing data. That way you ensure the uC will be ready to process when data is actually received at the UART.
If you also couple this with the Circular Buffer you are free to process your incoming stream whenever you wish. There are a few examples kicking around that are very helpful.
Enable RxInt to call your Receive_Macro (or whatever you wish to call it)
In the Macro use UART:ReceiveChar or ReceiveString to capture the data depending on your needs.
You could then put this in the Circular Buffer for processing whenever.
Another option is to have a loop inside the macro, exiting when ReceiveChar times out. In the loop, capture the data per byte and then store in the CB. I used this approach in a previous project with little issue. From the Main program I "polled" the CB to look for the presence of my data and if found processed.
Hope this helps.
Regards
Re: UART string variable question (quick question)
Posted: Mon Feb 26, 2024 5:09 pm
by Michael Burger
Very helpful, thank you!!
Using the RxInt for data capture solved a lot of issues for me.
Re: UART string variable question (quick question)
Posted: Mon Feb 26, 2024 11:21 pm
by chipfryer27
Hi
Glad you found it helpful.
When using comms, keeping the interrupt as short as possible is very beneficial. Usually I'll just grab my byte (for example) and store in a circular buffer before exiting.
In my Main Loop, I'll poll buffer and act accordingly. I may "test" to see if expected amount of bytes are present or I may look for a specific value(s). Many options.
This way my Main is doing "something useful" most of the time, only branching to handle incoming data when necessary.
Regards
Re: UART string variable question (quick question)
Posted: Tue Feb 27, 2024 2:35 am
by AbhijitR
Hello! Chipfryer
Thank you for your comments, may i request you to help me with the pictures you posted on 30th Jun 2019, unfortunately i am not able to view those.
Thank you.
Abhi
Re: UART string variable question (quick question)
Posted: Tue Feb 27, 2024 8:04 am
by chipfryer27
Hi Abhi
Good to hear from you again.I hope all is well.
I've no idea what happened to the pictures in the post, they appear to have "errors" so can't be displayed. Unfortunately I don't have any copies.
It was kind of a follow on from another e32Lora. Were you looking for anything specific to the LoRa module or just generically sending/ receiving?
Regards
Re: UART string variable question (quick question)
Posted: Tue Feb 27, 2024 12:37 pm
by AbhijitR
Hi! Chipfryer
Yes everything is well for me, thank you, I hope you too are good.
Regarding the pictures it would have been a help if me (in future) or someone else was interested to understand what exactly you were explaining, but its okay.
I remember sometime back Martin (medelec35) mentioned due to change of forum app pictures might have got lost.
Thank you.
Abhi
Re: UART string variable question (quick question)
Posted: Wed Feb 28, 2024 7:51 am
by chipfryer27
Hi Abhi
All good here with the exception of setting up a new laptop which is a pain. However as I'll be able to use Flowcode App Developer it will be worth the headache:)
It would be easy to recreate a generic chart, but to redo the LoRa I'd need to first refamiliarise myself with modules.
Regards