Page 1 of 1
stm32 & usart
Posted: Wed May 13, 2020 12:24 pm
by Alkaline
Hello
I'm trying to implement a uart communication in a project.
As a debug I am trying to communicate between the computer and the microcontroller stm32f030rc.
Communication from the microcontroller to the PC is ok while from the computer to the microcontroller I have some problems.
the received string is not complete and / or has errors. After a few messages, reception stops while the microcontroller continues to send its string regularly
The speed is 1152000 and on the computer I am using Termite 3.4 software
Re: stm32 & usart
Posted: Wed May 13, 2020 6:00 pm
by Benj
Hello,
I'm not too familiar with the ARM hardware but on a PIC if more then two characters are received without being collected then this can cause problems and put the receive hardware into an error mode. We try to clear this error if it happens but on the ARM things might be a little different. Or the error gets cleared but then immediatley happens again.
Anyway here is an example of how I might go about the same thing. This uses an interrupt to pull in data as it is received and then populates the string from the buffered data up to the length of the string - 1 for the null termination byte.
Let us know how you get on with this.
Re: stm32 & usart
Posted: Wed May 13, 2020 6:08 pm
by Alkaline
I noticed this problem because the gsm module (gl865) that I am using is programmed correctly but I cannot read its commands.
Everything works great on the pic32. The same thing happens if I use the gsm component.
So I tried to make a simple program that reads and writes on a terminal but the reception doesn't happen correctly.
I'll update you tomorrow morning
Re: stm32 & usart
Posted: Wed May 13, 2020 8:56 pm
by Benj
Hmm the GSM component will also use an interrupt.
Let us know how you get on and Ill have a think on it. Maybe some sort of brown out problem though TX is still working. Hmm.
Re: stm32 & usart
Posted: Thu May 14, 2020 8:36 am
by Alkaline
Hello
The updated version works correctly.
the gsm component however does not continue to work in reception.
The command sends it but cannot read the reply.
Kind regards
Re: stm32 & usart
Posted: Thu May 14, 2020 5:46 pm
by Alkaline
Even with the gsm module the code does not stop if I use your code.
If you can give me some advice.
Once the message has been received, it is put into the buffer via interupt.
How do I read it immediately afterwards?
Inserting the UART_TX routine inside the interrupt I think is not the best solution.
Could I use a flag indicating that the buffer was written and then call the UART_RX routine to write the buffer inside a variable?
Re: stm32 & usart
Posted: Fri May 15, 2020 11:05 pm
by Benj
Hello,
Assuming the RX message is terminated with a carriage return or similar you could simply do a WaitForValue component macro call with a timeout e.g. "n" or "\r". This way you can wait for the message to be received before stepping in and actioning the response. This is how we handle things like comms to various modules.
Interesting that the GSM component has a problem. I'll have a peek at this and see if I can work out what might be going wrong here. The RX function does a bit more as I beleive it looks for unsolicited incoming messages such as RING and maybe this is causing a problem with the STARM?
Re: stm32 & usart
Posted: Sat May 16, 2020 1:21 pm
by Alkaline
I share the code that I did to manage the module to see if it is possible to improve it or worse there is something wrong.
I state that I was able to test it only a few hours (4-6) but in those few hours it never got nailed.
In practice The code does the following.
Periodically queries the module about the status of the SIM, whether it is registered on the network and the signal quality.
This information is stored in an array of bytes and can thus be used to update the display or other things.
Obviously there are controls. For example, it cannot control the signal if the SIM is not inserted as it does not interrogate the module during an active call.
It also allows you to store the number in a local variable that can be subsequently manipulated or saved in eeprom
About the gsm component:
When I try to send a command it always returns me 255 even if in reality the command has been sent. (for example set the led of the gsm module).
Re: stm32 & usart
Posted: Wed May 20, 2020 4:27 pm
by Alkaline
Hi Benj
Occasionally uart crashes and doesn't allow you to receive messages. Sending continues but reception is blocked.
I am sending the command, I wait 100 ms and then I check the buffer. If I got an answer, I send the next command like this forever.
Re: stm32 & usart
Posted: Tue May 26, 2020 5:12 pm
by Alkaline
Hi
I keep blocking received messages without being able to restore communication.
I tried to change both the speed and the waiting time before reading the answer, but sometimes the system stops. (Uart reception only, the mcu responds to all other commands and the gsm module continues to function)
Re: stm32 & usart
Posted: Fri Sep 18, 2020 11:06 am
by Alkaline
Hello everyone
i still couldn't fix the uart blocking problem.
I have attached the recent version of the routine that manages the gsm module.
Occasionally the uart crashes and I can't restore the connection with the gsm module unless restarting the system.
From what I can understand this is a timing problem...But I can also be totally wrong.
Re: stm32 & usart
Posted: Fri Sep 18, 2020 1:34 pm
by LeighM
Could you add a "LED flash" into the UART_RX macro?
e.g. output high at the start, output low at the end,
then monitor this and the UART Rx pin with an oscilloscope
just to check that it is the receive and interrupt that has stopped
Re: stm32 & usart
Posted: Fri Sep 18, 2020 1:42 pm
by Alkaline
Hi LeighM
ok!
edit:
In yellow is the led / pin that signals the interrupt and in pink the transmission.
There is a 179us delay from the arrival of the data to the interrupt

- uart_00.jpg (133.62 KiB) Viewed 14424 times
edit2:
I was able to replicate the problem. The module keeps sending replies but the interrupt doesn't seem to work anymore!

- uart_01.jpg (95.67 KiB) Viewed 14416 times
Re: stm32 & usart
Posted: Tue Sep 22, 2020 10:56 am
by LeighM
Thanks for the update (although as an edit I initially missed it)
Could you try the following? …
In the UART_RX macro
Remove, or disable, the call to GSM_UART::Receive
Instead of it, and before the PutByte, add this in a C icon
Let me know how it goes
Thanks
Leigh
Re: stm32 & usart
Posted: Tue Sep 22, 2020 11:54 am
by Alkaline
Hi LeighM
The system is working, for the moment everything is ok.
I'll update you at the end of the evening. Thanks so much for the support !!!!
Regards
Re: stm32 & usart
Posted: Tue Sep 22, 2020 9:29 pm
by Alkaline
Hello
I was unable to complete all tests without the system returning the error.
The UL865 telit module continues to respond to commands sent to it but the interrupt appears to be blocked.
Tomorrow I will test the system again.
Re: stm32 & usart
Posted: Wed Sep 23, 2020 12:30 pm
by LeighM
Perhaps the UART is not recovering from an error.
Is the connection between the GSM module and the processor good, and not subject to noise?
Could you add a timer to determine when the interrupt has failed, then on timeout call GSM_UART::Init() and Enable RXINT2 again.
Re: stm32 & usart
Posted: Thu Sep 24, 2020 2:46 pm
by Alkaline
Hi LeighM
About the connection
i am using the same platform i used before with a pic32 where i never encountered the problem. Both the level translator and the connector are identical.
About the timer
could you put me an example in the program that I loaded you just to be sure to do it correctly?
Regards
Re: stm32 & usart
Posted: Fri Sep 25, 2020 9:25 am
by LeighM
Hi
I have added another timer, which is reset in the UART interrupt.
In the main loop, if the timer exceeds 10 seconds then the UART is re-initialised.
You can make that time period whatever is best for the system.
Just an idea, hope it helps.
Re: stm32 & usart
Posted: Fri Sep 25, 2020 9:54 am
by Alkaline
Hi
I saw the example and implemented a similar thing.
In the macro that I have implemented first I disable the interrupts then I reinitialize the uart and the interrupt.I think this is fine too.
I also inserted a counter to see how many times it resets .
At this moment the reset of the Uart and the Interpt works and the system does not crash.
Regards