2017-12-04 09:21 AM
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 ...TC1 is defined as USART1_SR_TC register bitband alias ...
#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));
withwhile(TC1==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 ..
#flag-check #bitband #while #stuck Note: this post was migrated and contained many threaded conversations, some content may be missing.Solved! Go to Solution.
2017-12-07 06:08 AM
How about your attitudes ?? which is completely out of topic ..
2017-12-07 06:10 AM
And someone else asking for free may not want to click or use the link ... Seriously .. I do not want to listen your suggestions .. Everything else except knowledge is not welcome ... because you are speaking to somebody who knows to thank to the contributors .. Please stay out of my topic , you are disturbing it ...
2017-12-07 06:21 AM
It ignores details, and the details are important.
Peripheral registers are not memory cells, reading and writing at the same address may act on a different register, and registers might act dynamically to the writing of specific bits, or might changing state within the ~8-cycle clock window you're fiddling with them. For example TIM->CNT += 8 doesn't advance the counter if it is clocking at the speed of the processor.
Behind all the smoke and mirrors you're not actually writing a single bit, and while programatically this might appear more efficient, frequently it isn't
Using it as a bit-band read works most of the time, provided the register doesn't differentiate between an 8, 16 or 32-bit wide read operation. ie doing an operation on CRC->DR for example.
Bit-banding action on TIM->SR is problematic because the write infers an AND operation, and when you read bits as zero that subsequently change to one this AND operation clears them, resulting in you never seeing the bits assert
Now say you can't use bit-banding, just than blind application will lead to failure and consequence. ie your three phase motor gets a spanner thrown into it.
Does writing the TC bit on USART->SR clear it? What if I try to clear the LBD or CTS bits?
Apply the use conservatively, where you understand the interaction.
2017-12-07 07:08 AM
That really makes it crazy clear !! Thank you Clive !! It is an amazing answer .. Now the point of view at my side completely changed ... Thank you millions of times ..