Page 1 of 1

a little question about gpio_read_bit

Posted: Mon Dec 07, 2020 8:50 pm
by Sziklai
When Im changing from digitalWrite to gpio_write_bit everything goes good.
but gpio_read_bit doesn't work. I just need faster gpio readings.

pinMode(PF3, INPUT);
pinMode(PF5, INPUT);
//temporary debug display:
display.clearDisplay();
display.setCursor(8, 0);
display.print(gpio_read_bit(GPIOF, 3));
display.setCursor(8, 56);
display.print(gpio_read_bit(GPIOF, 5));
display.display();

returns "8" for pin F3 and "32" for pin F5?

what Im doing wrong?
How much gpio_read_bit should be faster than digitalRead?
Thank you.

Re: a little question about gpio_read_bit

Posted: Mon Dec 07, 2020 9:14 pm
by mlundin
F3 is bit 3 returns 2^3 = 8, and F5 gives 2^5 = 32

Re: a little question about gpio_read_bit

Posted: Mon Dec 07, 2020 9:31 pm
by Sziklai
Oh. It makes sense..!
But how do i read a single pin input state high/low?
Like digitalRead(PF3) but faster.

Should it be like this:
if gpio_read_bit(GPIOF, 3) == 0 means pin grounded, if !=0 then floating or pulled to vcc?
I thought it gona be "0" and "1" respectively, but ok..

Re: a little question about gpio_read_bit

Posted: Mon Dec 07, 2020 10:25 pm
by GonzoG
There is no "gpio_read_bit" for fast read in Roger's core.
If you want fast read you need to get data from registers:

Code: Select all

GPIOx->regs->IDR
x - port (A,B, C, D, etc).

Re: a little question about gpio_read_bit

Posted: Tue Dec 08, 2020 2:52 pm
by stevestrong
The function gpio_read_bit() does what its name say. The output is zero if pin is tied to GND, non-zero otherwise.
If you want to make a "1* out of it then you have to shift right the read value with the number corresponding to the bit position.

Re: a little question about gpio_read_bit

Posted: Tue Dec 08, 2020 10:22 pm
by Sziklai
bit is a bit!
Thank you all! I got it!! What a good feeling! :D