Skip to main content
claire
Associate II
May 10, 2012
Question

problem read input data

Posted on May 10, 2012 at 14:12

i am on the stm32l discovery and i send a square wave on the pin PA1 but it's like i don't receive it, i'm trying to read it with the function GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_1) but it desn't work !!

int main(void){

    /*Configuration de la pin1 du portA(arriver du signal detection de traverse)*/

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;

    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;

    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;

    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;

    GPIO_Init(GPIOA,&GPIO_InitStructure);

    GPIO_PinAFConfig(GPIOA, GPIO_PinSource1, GPIO_AF_TIM2);

  TIM_InitStruct.TIM_Period = 849;

  TIM_InitStruct.TIM_Prescaler = PrescalerValue;

  TIM_InitStruct.TIM_ClockDivision = 0;

  TIM_InitStruct.TIM_CounterMode = TIM_CounterMode_Up;

TIM_TimeBaseInit(TIM2,&TIM_InitStruct);

        /*timer2 chanel 2 pin PA1*/

    TIM_ICInitStruct.TIM_Channel = TIM_Channel_2;

    TIM_ICInitStruct.TIM_ICPolarity = TIM_ICPolarity_Rising;

    TIM_ICInitStruct.TIM_ICSelection  = TIM_ICSelection_DirectTI;

    TIM_ICInitStruct.TIM_ICPrescaler = TIM_ICPSC_DIV1;

    TIM_ICInitStruct.TIM_ICFilter = 0x0;

    TIM_ICInit(TIM2, &TIM_ICInitStruct);

TIM_Cmd(TIM2, ENABLE);

    LCD_GLASS_Configure_GPIO();

    LCD_GLASS_Init();

  while (1){

      

    bitA = GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_1);

    sprintf(str,'' %u'',bitA);

    LCD_GLASS_DisplayString( (unsigned char *) str );

  }

}
    This topic has been closed for replies.

    2 replies

    Tesla DeLorean
    Guru
    May 10, 2012
    Posted on May 10, 2012 at 14:18

    Remove this line

     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    claire
    claireAuthor
    Associate II
    May 10, 2012
    Posted on May 10, 2012 at 14:24

    thank you for your speed answer

    i tried but it still doesn't work

    the IDR register stays at '0'