AnsweredAssumed Answered

Same functions ; different result

Question asked by ionut.fasola on Dec 17, 2013
I am using STM8L-Discovery board, STVD and Cosmic Compiler 32k; and ST peripheral libraries(stn8l15x.h file revision number is 1.4/2010) 
I have runned the next code:



#include "stm8l15x.h"
#include "delay.h"


void main(void)
 {//initializare pini

      GPIO_DeInit(GPIOA);
      GPIO_DeInit(GPIOE);
      
     // GPIO_Mode_In_FL_No_IT      = (uint8_t)0x00,   /*!< Input floating, no external interrupt */
  //GPIO_Mode_In_PU_No_IT      = (uint8_t)0x40,   /*!< Input pull-up, no external interrupt */
 // GPIO_Mode_In_FL_IT         = (uint8_t)0x20,   /*!< Input floating, external interrupt */
  //GPIO_Mode_In_PU_IT         = (uint8_t)0x60,   /*!< Input pull-up, external interrupt */
  //GPIO_Mode_Out_OD_Low_Fast  = (uint8_t)0xA0,   /*!< Output open-drain, low level, 10MHz */
  //GPIO_Mode_Out_PP_Low_Fast  = (uint8_t)0xE0,   /*!< Output push-pull, low level, 10MHz */
  //GPIO_Mode_Out_OD_Low_Slow  = (uint8_t)0x80,   /*!< Output open-drain, low level, 2MHz */
  //GPIO_Mode_Out_PP_Low_Slow  = (uint8_t)0xC0,   /*!< Output push-pull, low level, 2MHz */
  //GPIO_Mode_Out_OD_HiZ_Fast  = (uint8_t)0xB0,   /*!< Output open-drain, high-impedance level, 10MHz */
  //GPIO_Mode_Out_PP_High_Fast = (uint8_t)0xF0,   /*!< Output push-pull, high level, 10MHz */
  //GPIO_Mode_Out_OD_HiZ_Slow  = (uint8_t)0x90,   /*!< Output open-drain, high-impedance level, 2MHz */
  //GPIO_Mode_Out_PP_High_Slow = (uint8_t)0xD0
       //PA6- input - button; PE4- output-led
     GPIO_Init(GPIOA,GPIO_Pin_6,GPIO_Mode_In_PU_No_IT );
     
     GPIO_Init(GPIOE,GPIO_Pin_4,GPIO_Mode_Out_OD_Low_Slow);
     GPIO_Init(GPIOE,GPIO_Pin_0,GPIO_Mode_Out_OD_Low_Slow);
     GPIO_Init(GPIOE,GPIO_Pin_1,GPIO_Mode_Out_OD_Low_Slow);
     GPIO_Init(GPIOE,GPIO_Pin_2,GPIO_Mode_Out_OD_Low_Slow);
     GPIO_Init(GPIOE,GPIO_Pin_3,GPIO_Mode_In_FL_No_IT  );
     GPIO_Init(GPIOE,GPIO_Pin_5,GPIO_Mode_Out_OD_Low_Slow);
     GPIO_Init(GPIOE,GPIO_Pin_6,GPIO_Mode_Out_OD_Low_Slow);
     GPIO_Init(GPIOE,GPIO_Pin_7,GPIO_Mode_Out_OD_Low_Slow);


     GPIO_WriteBit(GPIOE,GPIO_Pin_All,RESET);
     //pin PE3 is resetting as well; but it does not through error
     
while(1)
{     
     if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_6))
     {     delay_ms(100);
          GPIO_ResetBits(GPIOE,4);
          delay_ms(100);
          GPIO_SetBits(GPIOE,(uint8_t)4);
     }
     else
     
       delay_ms(40);
          GPIO_WriteBit(GPIOE,GPIO_Pin_4,RESET);
          delay_ms(40);
          GPIO_WriteBit(GPIOE,GPIO_Pin_4,SET);
      
     }
}
 }

I have runned the programm; the led stays off permanently; if I push the button( equivalent with putting to GND the PA6 pin); the led starts blinking.


I have looked at those functions definitions from library; they are the sane; or if is a hidden stuf in there, it should do the same thing.

void GPIO_WriteBit(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef GPIO_Pin, BitAction GPIO_BitVal)
{
  /* Check the parameters */
  assert_param(IS_GPIO_PIN(GPIO_Pin));
  assert_param(IS_STATE_VALUE(GPIO_BitVal));


  if (GPIO_BitVal != RESET)
  {
    GPIOx->ODR |= GPIO_Pin;


  }
  else
  {
    GPIOx->ODR &= (uint8_t)(~GPIO_Pin);
  }
}

/**
  * @brief  Writes high level to the specified GPIO pins.
  * @note   The port must be configured in output mode.
  * @param  GPIOx : Select the GPIO peripheral number (x = A to I).
  * @param  GPIO_Pin : Specifies the pins to be turned high.
  * @retval None
  */
void GPIO_SetBits(GPIO_TypeDef* GPIOx, uint8_t GPIO_Pin)
{
  GPIOx->ODR |= GPIO_Pin;
}/**
  * @brief  Writes low level to the specified GPIO pins.
  * @param  GPIOx : Select the GPIO peripheral number (x = A to I).
  * @param  GPIO_Pin : Specifies the pins to be turned low
  * @retval None
  * @par    Required preconditions:
  *   The port must be configured in output mode.
  */
void GPIO_ResetBits(GPIO_TypeDef* GPIOx, uint8_t GPIO_Pin)
{
  GPIOx->ODR &= (uint8_t)(~GPIO_Pin);
}


Outcomes