We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hello ..
I am having a very weird issue with my code piece .. The MCU is STM32F407VET6 .. What I'm trying to do is sending a string via USART1 peripheral module .. In order check if the character in the USART1 is sent out of the USART1->DR register I am continuously checking the "Transmit Complete Bit of the usart1 status register The code below works well ...
#define TC1 *((uint32_t *)(0x42220018)) //Previously defined at //the top of the main file void EXTI4_IRQHandler(void) { uint8_t i; char x[6]="BURAK\n"; EXTI_PR_Bit4=1; // Cleared by writing 1 // ISR code TC1=0; for(i=0;i<7;i++) { USART1->DR=x[i]; while(!(USART1->SR&USART_SR_TC));// Transmit Complete ? } TC1=0; }
BUT !
When I replace
while(!(USART1->SR&USART_SR_TC));
with
while(TC==0);
The code stucks.. freezes ... and stops ...Why does it happen ?? Are Bit-Band Aliases not reliable things to use with while ,if , for statements ?? Does it have to be read/modify/write sequence always ??
Thanks in advance ..
Not sure.
Try these changes -
#define TC1 *((__IO uint32_t *)(0x42220018)) //#define TC1 *((uint32_t *)(0x42220018))
and
while (TC1 == 0); // while (TC==0);
Sorry Kevin - you posted first.
Just take my post as a second vote for volatile, affirming your suggestion.
As not a great idea to send out the USART like this in a IRQ_Handler.
Thanks Robert. Always nice to have the support of someone who really knows their subject :)
Thanks it solved with volatile keyword ... Is there a diffence between __IO and volatile keywords ??
__IO is not a keyword - it is just a #define
Look at the #define ...
all peripheral registers are defined as volatile. That's where the difference actually is.
community.st.com/.../45696-while-loop-stucks