stm32 & usart
Moderator: Benj
-
- Posts: 143
- Joined: Mon Aug 20, 2018 11:04 am
- Has thanked: 42 times
- Been thanked: 41 times
- Contact:
stm32 & usart
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
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
- Attachments
-
- UART_DEBUG.fcfx
- (23.52 KiB) Downloaded 194 times
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: stm32 & usart
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 143
- Joined: Mon Aug 20, 2018 11:04 am
- Has thanked: 42 times
- Been thanked: 41 times
- Contact:
Re: stm32 & usart
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
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
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: stm32 & usart
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 143
- Joined: Mon Aug 20, 2018 11:04 am
- Has thanked: 42 times
- Been thanked: 41 times
- Contact:
Re: stm32 & usart
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
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
-
- Posts: 143
- Joined: Mon Aug 20, 2018 11:04 am
- Has thanked: 42 times
- Been thanked: 41 times
- Contact:
Re: stm32 & usart
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?
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?
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: stm32 & usart
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?
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?
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 143
- Joined: Mon Aug 20, 2018 11:04 am
- Has thanked: 42 times
- Been thanked: 41 times
- Contact:
Re: stm32 & usart
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).
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).
- Attachments
-
- DEBUG_GSM.fcfx
- (35.72 KiB) Downloaded 192 times
-
- Posts: 143
- Joined: Mon Aug 20, 2018 11:04 am
- Has thanked: 42 times
- Been thanked: 41 times
- Contact:
Re: stm32 & usart
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.
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.
-
- Posts: 143
- Joined: Mon Aug 20, 2018 11:04 am
- Has thanked: 42 times
- Been thanked: 41 times
- Contact:
Re: stm32 & usart
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)
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)
-
- Posts: 143
- Joined: Mon Aug 20, 2018 11:04 am
- Has thanked: 42 times
- Been thanked: 41 times
- Contact:
Re: stm32 & usart
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.
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.
- Attachments
-
- DEBUG_GSM_2.fcfx
- (46.7 KiB) Downloaded 190 times
- LeighM
- Matrix Staff
- Posts: 2178
- Joined: Tue Jan 17, 2012 10:07 am
- Has thanked: 481 times
- Been thanked: 699 times
- Contact:
Re: stm32 & usart
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
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
-
- Posts: 143
- Joined: Mon Aug 20, 2018 11:04 am
- Has thanked: 42 times
- Been thanked: 41 times
- Contact:
Re: stm32 & usart
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 edit2:
I was able to replicate the problem. The module keeps sending replies but the interrupt doesn't seem to work anymore!
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 edit2:
I was able to replicate the problem. The module keeps sending replies but the interrupt doesn't seem to work anymore!
- LeighM
- Matrix Staff
- Posts: 2178
- Joined: Tue Jan 17, 2012 10:07 am
- Has thanked: 481 times
- Been thanked: 699 times
- Contact:
Re: stm32 & usart
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
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
Code: Select all
FCL_RX = MX_HANDLE_UART2_RX_VAL;
Thanks
Leigh
-
- Posts: 143
- Joined: Mon Aug 20, 2018 11:04 am
- Has thanked: 42 times
- Been thanked: 41 times
- Contact:
Re: stm32 & usart
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
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
-
- Posts: 143
- Joined: Mon Aug 20, 2018 11:04 am
- Has thanked: 42 times
- Been thanked: 41 times
- Contact:
Re: stm32 & usart
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.
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.
- LeighM
- Matrix Staff
- Posts: 2178
- Joined: Tue Jan 17, 2012 10:07 am
- Has thanked: 481 times
- Been thanked: 699 times
- Contact:
Re: stm32 & usart
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.
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.
-
- Posts: 143
- Joined: Mon Aug 20, 2018 11:04 am
- Has thanked: 42 times
- Been thanked: 41 times
- Contact:
Re: stm32 & usart
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
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
- LeighM
- Matrix Staff
- Posts: 2178
- Joined: Tue Jan 17, 2012 10:07 am
- Has thanked: 481 times
- Been thanked: 699 times
- Contact:
Re: stm32 & usart
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.
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.
- Attachments
-
- DEBUG_GSM_3.fcfx
- (49.38 KiB) Downloaded 139 times
-
- Posts: 143
- Joined: Mon Aug 20, 2018 11:04 am
- Has thanked: 42 times
- Been thanked: 41 times
- Contact:
Re: stm32 & usart
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
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