This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Simple GPIO read not working -

Firstly, I'n fairly new Keil, and am "upgrading from 8-bit PIC's"

I'm trying to read some data from an ADC.

Not working so I wrote a simple program that reads the input pin status.

To my surprise it doesn't seem to pay any attention to reading to pin status.

I have included the STM32F10xR.lib in the project. Compiles OK, and runs as in I can get it to toggle a couple of output LED's. Just nothing when I read a pin.

Compiler Keil UV4
HArdware Olimnexio (STM32F103RBT6)

#include <stm32f10x_lib.h>

GPIO_InitTypeDef GPIO_InitStructure;

u8 gpio_val;

int main(void)
{
 int i;

  /* Enable GPIOA clock */
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);

        GPIO_InitStructure.GPIO_Pin=GPIO_Pin_1 | GPIO_Pin_5;
        GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
        GPIO_InitStructure.GPIO_Speed=GPIO_Speed_10MHz;
        GPIO_Init(GPIOA,&GPIO_InitStructure);

  /* Enable GPIOD clock */
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);

        GPIO_InitStructure.GPIO_Pin=GPIO_Pin_4;
        GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING;
        GPIO_Init(GPIOD,&GPIO_InitStructure);

        //Make sure the LED's are working
        GPIOA->BSRR= 1<<1;//Set pin A.1 to 1
        GPIOA->BSRR= 1<<5;//Set pin A.5 to 1

        for(i=0;i<0x40000;i++)
        {
        }

        //loop forever
        for(;;)
        {

                for(i=0;i<0x40000;i++)
                {
                }
                //read the pin status and set LED's accordingly
                if(!GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_4))
                {
                        GPIOA->BRR= 1<<1;//Set pin A.1 to 0
                        GPIOA->BSRR= 1<<5;//Set pin A.5 to 1
                }

                else
                {
                        GPIOA->BSRR= 1<<1;//Set pin A.1 to 1
                        GPIOA->BRR= 1<<5;//Set pin A.5 to 0
                }
        }

}