a little question about gpio_read_bit

Post here first, or if you can't find a relevant section!
Post Reply
Sziklai
Posts: 3
Joined: Wed Jul 15, 2020 5:38 pm

a little question about gpio_read_bit

Post 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.
mlundin
Posts: 94
Joined: Wed Nov 04, 2020 1:20 pm
Answers: 6
Location: Sweden

Re: a little question about gpio_read_bit

Post by mlundin »

F3 is bit 3 returns 2^3 = 8, and F5 gives 2^5 = 32
Sziklai
Posts: 3
Joined: Wed Jul 15, 2020 5:38 pm

Re: a little question about gpio_read_bit

Post 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..
GonzoG
Posts: 403
Joined: Wed Jan 15, 2020 11:30 am
Answers: 26
Location: Prudnik, Poland

Re: a little question about gpio_read_bit

Post 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).
stevestrong
Posts: 502
Joined: Fri Dec 27, 2019 4:53 pm
Answers: 8
Location: Munich, Germany
Contact:

Re: a little question about gpio_read_bit

Post 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.
Last edited by stevestrong on Wed Dec 09, 2020 8:14 am, edited 2 times in total.
Sziklai
Posts: 3
Joined: Wed Jul 15, 2020 5:38 pm

Re: a little question about gpio_read_bit

Post by Sziklai »

bit is a bit!
Thank you all! I got it!! What a good feeling! :D
Post Reply

Return to “General discussion”