-
Notifications
You must be signed in to change notification settings - Fork 94
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
Avoid blocking main loop while sending data via UART #10
Comments
Ok. We can use dma for this purpose. |
Is it possible to use DMA when you do not yet know the number of char to be sent? |
Maybe. We have to think. |
I changed the code in order to toggle a pin each time the program goes into the main loop (in protocol.c). I put a digital scope on the serial RX and TX signal and on this pin. |
I made changes in order to use interrupts when sending data via UART (in order to avoid locking the main loop). |
I made a new change in order to put #define DEBUG_TIMING_WITH_FLOOD_AND_MIST in grbl.h (instead of protocol.c; it was wrong). |
I had at look at the way data are sent via UART.
I found this code
#ifndef USEUSB
USART_SendData(USART1, data);
while (!(USART1->SR & USART_FLAG_TXE));
return;
#endif
It means that the CPU waits in the "while" loop when a byte is written in UART if the UART is still sending a previous byte.
So if several bytes have to be sent (e.g in case of error, alarm or on reply on "?") the CPU will be blocked (waiting) several times for about max 100 micro sec per char).
During this time, the cpu can not plan new motions.
I presume it should be better to write the data to be sent in a buffer and to use an interrupt to send the buffer without blocking the main loop.
The text was updated successfully, but these errors were encountered: