Skip to main content
Visitor II
June 30, 2020
Question

I'm writing the following code: GPIOA-"MODER" 0x400; (set GPIO_MODER_MODE5_0). It's not working! In the debugging window, bit 11 doesn't change and the LD4 LED doesn't switch.

  • June 30, 2020
  • 3 replies
  • 2925 views

I have Nucleo-G071RB. I want to flash the LED LD4 using CMSIS. Use IAR 8.40

I'm writing the following code: GPIOA->MODER |= 0x400; (set GPIO_MODER_MODE5_0). It's not working! In the debugging window, bit 11 doesn't change and the LD4 LED doesn't switch!

However, if I write a GPIOA->MODER = 0x400; then it works. (the debugger doesn't work because it's on GPIOA the same way, but it doesn't matter).

The same thing is happening at other ports B, C, ...

What's my mistake?

Thank you.

    This topic has been closed for replies.

    3 replies

    Super User
    June 30, 2020

    The reset value of GPIOA->MODER is 0xEBFF FFFF; so both bits of MODE5 are already set, by ORing to them they can't change.

    GPIOA->MODER = (GPIOA->MODER & ~GPIO_MODER_MODE5) | (1 * GPIO_MODER_MODE5_0);

    JW

    VTyut.1Author
    Visitor II
    June 30, 2020

    My error was that I didn't look at the set default values in MODER registers (F0 series - ...00000000000, G0 series - ...11111111).

    Thanks!

    Visitor II
    January 22, 2024

    Try this one:

    1- First set the address of the GPIO->MODER Register

    GPIO_MODER = (uint32_t*)0x48000000;

    2- Set the MODER [9:8] = 0x1

    *GPIO_MODER |= 0x400;