Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Listening to UART using IWDG #57

Open
TomRaeves opened this issue Jan 26, 2022 · 6 comments
Open

Listening to UART using IWDG #57

TomRaeves opened this issue Jan 26, 2022 · 6 comments

Comments

@TomRaeves
Copy link

We cant seem to figure out how we can listen to the UART because we are using IWDG and so our functions only gets called periodically after certain time points so we will miss some information if it gets sent inbetween these times. Is there a way to continuously listen to the UART after pressing a button for an amount of time when we are using the periodical IWDG timers for everything else ?
@MatsDeMeyer @michielaernouts

@TomRaeves
Copy link
Author

It is working if we enable a timer which listens on the UART every 0.1 seconds but I don't know if this is the most elegant/foolproof way to do it.

@SamGeens
Copy link

SamGeens commented Jan 26, 2022

It is possible to use UART with interrups. An interrupt handler will be called every time a UART message is received. I've not done this myself so I can't help with that but at least it is possible. I guess that if you're looking for the most elegant way this is the one.

@TomRaeves
Copy link
Author

i dont think its possible to use an interrupt on the UART if you are trying to decide when to listen to the UART.

@SamGeens
Copy link

SamGeens commented Jan 26, 2022

I'm afraid I don't get the point.

our functions only gets called periodically after certain time points so we will miss some information if it gets sent inbetween these times

You said you're missing information because UART is not handled because other code is being executed? The whole point about the interrupt is that it only fires when something is received on UART. So if I understand you correctly you don't need to decide when to listen on UART but need to know when a UART message is being received.

If not I might misunderstood your question :) Some officials should take it from here I think ;)

@jeroen1323
Copy link

I think Sam is right.
If you use HAL_UART_Receive_IT(&UART2, &UART2_rxBuffer, 1); instead of HAL_UART_Receive(&UART2, &UART2_rxBuffer, 1); you will get an interrupt when you receive a message over UART. So by adding a corresponding callback function you should be able to continue. When this interrupt is triggered the scheduled tasks will be on hold for as long as the code is in the callback, so you would not miss any messages.
However, do not use the HAL_UART_Receive_IT in a loop, calling it once is enough to enable the UART interrupt.

@SamGeens
Copy link

@jeroen1323 HAL_UART_Receive_IT is indeed the function I couldn't remember!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants