Skip to main content
craig239955_stm1_st
Associate III
February 2, 2014
Question

Strange problem with configuring output pins

  • February 2, 2014
  • 3 replies
  • 583 views
Posted on February 02, 2014 at 11:45

I'm using the below code to activate output pins.


void
GPIO_cfg(
void
){


GPIO_InitTypeDef GPIO_IS; 
// GPIO Initialisation Structure => GPIO_IS


// Configure/enable peripheral clocks

RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);


GPIOB->MODER = (0x00001000); 
// This line works


/* Configure PE15 in output pushpull mode */

GPIO_IS.GPIO_Pin = GPIO_Pin_6; 
// Configure pin 6

GPIO_IS.GPIO_Mode = GPIO_Mode_OUT;

// These lines don't work


GPIO_IS.GPIO_OType = GPIO_OType_PP;

GPIO_IS.GPIO_Speed = GPIO_Speed_2MHz;

GPIO_IS.GPIO_PuPd = GPIO_PuPd_NOPULL;

GPIO_Init(GPIOA, &GPIO_IS);


GPIO_SetBits(GPIOB, GPIO_Pin_6);


}

If I remove the ''

GPIOB->MODER

'' section, it no longer correctly configures the output, not a clue why. Seems like maybe there's a problem with the GPIO_Init() function? I'm using an STM32L152 Discovery board.
    This topic has been closed for replies.

    3 replies

    raptorhal2
    Lead
    February 2, 2014
    Posted on February 02, 2014 at 16:46

    You don't show definitions for the members of GPIO_IS structure. My guess is that they are missing or incorrect.

    Use the GPIO_InitStructure provided by the Library, and all should go well.

    Cheers, Hal

    Tesla DeLorean
    Guru
    February 2, 2014
    Posted on February 02, 2014 at 17:05

    GPIO_Init(GPIOA, &GPIO_IS);

    But not GPIOA right?
    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    craig239955_stm1_st
    Associate III
    February 2, 2014
    Posted on February 02, 2014 at 17:56

    Damnit, I'm totally blind sometimes. Thanks.