ftricamo
Posts: 2
Joined: Tue Feb 26, 2019 6:56 pm

gpio_fsel() won't set to output

Fri Nov 29, 2019 11:33 pm

noob issue on GPIO blink. trying to get BCM 18 (pin 12) as an output.

If i do a GPIO readall, it shows 18 as an input. If i switch everything over to 22 (or any other GPIO pin) everything works.

How can i tell what has control of that pin? or is this a sign the pin circuitry is damaged?

Image

Code: Select all

#include <stdio.h>
#include <bcm2835.h>


int main(int argc, char **argv)
{
	printf("hello, just starting the main loop\n");
	
	if(!bcm2835_init())return 1;
	
	bcm2835_gpio_fsel(18, BCM2835_GPIO_FSEL_OUTP); // This is not working
	 unsigned int delay = 10000;
	 printf("before loop\n");
	 while (1){
		 printf("in the loop\n");
		 printf("the pin is %d :",LED);
		 bcm2835_gpio_set(18); 
		 printf("LED is ON\n");
		 bcm2835_delay(delay);  
		 bcm2835_gpio_clr(18);
		 printf("LED is off\n");
		 bcm2835_delay(delay); 
	}
	return 0;

}
Attachments
GPIO readall output.jpg
GPIO readall output.jpg (176.61 KiB) Viewed 249 times

User avatar
buja
Posts: 545
Joined: Wed Dec 31, 2014 8:21 am
Location: Netherlands

Re: gpio_fsel() won't set to output

Sat Nov 30, 2019 7:01 am

Yes, I am afraid something is wrong with your BCM pin 18.
This slightly modified version of your program works on my Pi.

Code: Select all

#include <stdio.h>
#include <bcm2835.h>

#define LED 18

int main(int argc, char **argv)
{
    printf("hello, just starting the main loop\n");

    if(!bcm2835_init())
		return 1;

    bcm2835_gpio_fsel(LED, BCM2835_GPIO_FSEL_OUTP); // This is not working
    unsigned int delay = 2000;
    printf("before loop\n");
    while (1) {
        printf("in the loop\n");
        printf("the pin is %d :",LED);
        bcm2835_gpio_set(LED);
        printf("LED is ON\n");
        bcm2835_delay(delay);
        bcm2835_gpio_clr(LED);
        printf("LED is off\n");
        bcm2835_delay(delay);
    }
    return 0;
}

Return to “C/C++”