GPIO access speed


6 posts
by buteman » Wed Jan 16, 2013 3:24 pm
I am planning to use the GPIO system, about which I know very little at present, I thought I would ask some questions here in the hope I can do what I want.
My questions are:
How fast can they be read?
Can a group of them be read as bits in a port as they can on the arduino?
How fast can they be written to?
Can they be written to as bits of a port?
Can anyone answer these questions please as I have not turned up anything definitive via google searches.
Thanks
Posts: 59
Joined: Tue Jul 03, 2012 9:06 am
by joan » Wed Jan 16, 2013 3:31 pm
buteman wrote:I am planning to use the GPIO system, about which I know very little at present, I thought I would ask some questions here in the hope I can do what I want.
My questions are:
How fast can they be read?
Can a group of them be read as bits in a port as they can on the arduino?
How fast can they be written to?
Can they be written to as bits of a port?
Can anyone answer these questions please as I have not turned up anything definitive via google searches.
Thanks

As fast as you can. You are limited by the processing you do after each read.
Yes, any combination of the user gpios can be read/written in one operation.
As fast as you can, You are limited by the processing you do before each write.
Not sure what you mean. The read/write registers are memory mapped, one 32 bit word covers all the user gpios for read, another for write. If you consider that a port then yes.
User avatar
Posts: 6560
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK
by Arjan » Wed Jan 16, 2013 4:05 pm
Using a C library in Linux (for example : http://www.open.com.au/mikem/bcm2835/index.html) you would be able to toggle pins with a 7 MHz frequency max.
Improved performance can be done using bare metal programming.
Posts: 131
Joined: Sat Sep 08, 2012 1:59 pm
by joan » Wed Jan 16, 2013 4:46 pm
You don't need to use a C library and its overheads. Just do it in plain C. I'm not sure what use just toggling bits is though, unless the only point is to generate a square wave.
User avatar
Posts: 6560
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK
by buteman » Sat Jan 19, 2013 4:02 pm
@ Joan
What I want to do is hook up an 8 bit parallel output ADC to my R.Pi and be able to read the values on all 8 pins in one go. If the pins are connected correctly this would result in a very quick way of finding what the result of the ADC's conversion was as the read would be the 8 bit value.

Or am I completely off track here :?
If I am right perhaps you could give me an example of the code I would need or point me to that code somewhere.
tia
Posts: 59
Joined: Tue Jul 03, 2012 9:06 am
by joan » Sat Jan 19, 2013 6:15 pm
The code at http://abyz.co.uk/rpi/misc/gpio-monitor_v0.c monitors all the gpios (0..53) for state changes. All the user gpios are in bank 1 (gpios 0..31).

If you're familiar with C you could just chop out the few lines of code you actually need (basically initGpio() and a little bit of the main() function).
User avatar
Posts: 6560
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK