Olimex Support Forum

OLinuXino Android / Linux boards and System On Modules => A20 => Topic started by: luimarma on September 25, 2015, 12:57:40 PM

Title: GPIO problems with A20-micro and sensor
Post by: luimarma on September 25, 2015, 12:57:40 PM
Hi
I am porting a sensor driver to A20 from a STM32 project.
The device receives pulses from a GPIO configured as output and after each pulse I have to read the state of another GPIO.
I have identified in connector GPIO-3 gpio18_ph9 that I will use for INPUT and gpio19_ph10 that will use for OUTPUT.
I have made sure that the GPIO's are correct first making an small program and set them for output and checking the HIGH and LOW states with a volt meter.
I have used the mem aproach to work with the GPIO for flexibility, but I did not succed interfacing the sensor. It looks like the input is not stable. In fact with the device conected and checking the input state the value changes without reason. This is the code that I used to init the GPIO and setup the pins, the sunxi functions are from gpio_lib:

        if (sunxi_gpio_init()<0) {
           printf("GPIO INIT ERROR");   
           return(-1);
        }
        if (sunxi_gpio_set_cfgpin(SUNXI_GPH(10),SUNXI_GPIO_OUTPUT)<0) {
           printf("EROR SETTING GPIO TO OUTPUT");   
           return(-1);
        }
        if (sunxi_gpio_set_cfgpin(SUNXI_GPH(9),SUNXI_GPIO_INPUT)<0) {
           printf("ERROR SETTING GPIO TO INPUT");   
           return(-1);
        }
FOR SETING HIGH AND LOW
         sunxi_gpio_output(SUNXI_GPH(10),HIGH);
         sunxi_gpio_output(SUNXI_GPH(10),HIGH);
AND FINALLY FOR READING
         value = sunxi_gpio_input(SUNXI_GPH(9));

Anyone has the same problem?
Any solution?
Title: Re: GPIO problems with A20-micro and sensor
Post by: luimarma on September 29, 2015, 12:28:41 PM
Finally seems that I was using a GPIO for input that is shared for something else.

Regards,

Luis
Title: Re: GPIO problems with A20-micro and sensor
Post by: gurpartap on September 30, 2015, 08:39:31 AM
I also faced same problem with a switch. Then I use pull up resistor with switch and it is now reading stable input. If you have microcontroller experience then you should know it.