2015-10-04 06:19 AM
Hi all,
Just plunging in again to learn STM32/ARM coding, and have a GPIO issue (on a STM32L100C discovery board): Why does this work...GPIOC->MODER |= (GPIO_MODER_MODER8_0 | GPIO_MODER_MODER9_0) ;
GPIOC->OTYPER &= ~(GPIO_OTYPER_OT_8 | GPIO_OTYPER_OT_9) ;
GPIOC->OSPEEDR |= (GPIO_OSPEEDER_OSPEEDR8|GPIO_OSPEEDER_OSPEEDR9);
GPIOC->PUPDR &= ~(GPIO_PUPDR_PUPDR8|GPIO_PUPDR_PUPDR9);
while
(1)
{
GPIOC->ODR = 0x0300;
delay(10000);
GPIOC->ODR = 0x0300;
delay(10000);
}
But not this?...
GPIOC->MODER |= (GPIO_MODER_MODER8_0 | GPIO_MODER_MODER9_0) ;
GPIOC->OTYPER &= ~(GPIO_OTYPER_OT_8 | GPIO_OTYPER_OT_9) ;
GPIOC->OSPEEDR |= (GPIO_OSPEEDER_OSPEEDR8|GPIO_OSPEEDER_OSPEEDR9);
GPIOC->PUPDR &= ~(GPIO_PUPDR_PUPDR8|GPIO_PUPDR_PUPDR9);
while
(1)
{
GPIOC->BSRR = 0x0300;
delay(10000);
// GPIOC->BSRR = 0x0300; // This also did not work
GPIOC->BRR = 0x0300;
delay(10000);
}
#keyhole-debugging
2015-10-04 06:30 AM
What does ''works'' mean, because the result should be different between the two. The first example would seem to write the same value twice, so it's not as if the LEDs / GPIO state would change.
Check the GPIO configuration, and make sure all the bits you want set/clear actually get into the final state you want/expect, especially where there are multiple bits involved, and the initial state is unknown/unexpected. Use a debugger, review the registers.2015-10-04 09:01 AM
''Works'' means the LEDs (on PC8 and PC9) blink. My understanding is that BSRR will set specific bits, and BRR should clear them. I also found that I an clear the bits by using BSRR, but shifting the specific bits 16 over to the left, so ''GPIOC->BSRR = 0x03000000;'' will turn the LEDs off. But if I use BRR I should not need to shift the bits over 16 to the left. So why doesn't BRR work to turn the LEDs off as I have it?
2015-10-04 11:51 AM
..
2015-10-05 08:19 AM
Seem to be missing a lot of context here, the SPL uses BSRRL, and BSRRH to differentiate the two halves of the 32-bit register, so you're clearly not using that.
Maybe you should be looking more carefully at the tools/library you are using, and how the structure for the GPIO is defined.2018-03-31 10:52 AM
//This works
GPIOC ->BSRRL |= GPIO_BSRR_BS_8;
//BRR Register will NOT work (in the STM32L100 this register does not work)
GPIOC ->BRR |= (1 << 8);
//You have to write to the High register to reset the pin (Since you cannot use BRR Reg)
GPIOC ->BSRRH |= (1<<8);
Note: BSRR Register is used for Atomic write while ODR register is not atomic (i.e between interrupts or multi-tasking context switching can happen midway)
2018-03-31 06:09 PM
You're posting to a 2+ year old thread! Please don't do that unless there is some compelling reason.
You can write the 32-bit word if you use the appropriate cast.
>>BRR Register will NOT work (in the STM32L100 this register does not work)
Is there an errata for this?