AnsweredAssumed Answered

GPIO struct parameters not initialized

Question asked by evans.chris on Aug 5, 2011
Latest reply on Aug 9, 2011 by evans.chris
The GPIO struct is defined but it is not initialized before it is used in main.  Everything works but I am stuck with trying to find a value that I can use in GPIO_Init.  GPIOx->CR2 is OR'd with another value and I don't know where to get the initial value GPIOx->CR2.  The only thing I can think is that a random number is in that address.

This is in the given program that comes with the firmware.  I am new to C and this is probably a simple problem. 

Thanks,
Chris



In the main function that comes with the Discovery microcontroller.  The first thing that main does is to call GPIO_Init.   I have included it here.

void GPIO_Init(GPIO_TypeDef* GPIOx,
               uint8_t GPIO_Pin,
               GPIO_Mode_TypeDef GPIO_Mode)
{
 
 
  /*----------------------*/
  /* Check the parameters */
  /*----------------------*/

  assert_param(IS_GPIO_MODE(GPIO_Mode));
  assert_param(IS_GPIO_PIN(GPIO_Pin));

  /* Reset crresponding bit to GPIO_Pin in CR2 register */
  GPIOx->CR2 &= (uint8_t)(~(GPIO_Pin));

  /*-----------------------------*/
  /* Input/Output mode selection */
  /*-----------------------------*/

  if ((((uint8_t)(GPIO_Mode)) & (uint8_t)0x80) != (uint8_t)0x00) /* Output mode */
  {
    if ((((uint8_t)(GPIO_Mode)) & (uint8_t)0x10) != (uint8_t)0x00) /* High level */
    {
      GPIOx->ODR |= GPIO_Pin;
    } else /* Low level */
    {
      GPIOx->ODR &= (uint8_t)(~(GPIO_Pin));
    }
    /* Set Output mode */
    GPIOx->DDR |= GPIO_Pin;
  } else /* Input mode */
  {
    /* Set Input mode */
    GPIOx->DDR &= (uint8_t)(~(GPIO_Pin));
  }

I think you can see that GPIOx->CR2 and GPIOx->ODR and GPIOx->DDR are being used to set bits.(Outlined in RED)  My thinking is that they are not initialized by the function GPIO_Init yet so any number that happens to be in that address could be used.

I am a beginner in both uC's and C.  Thanks for your help.

Chris

Outcomes