Read Full Register

Status
Not open for further replies.

Wilfried

New member
Hi, I'm new to teensy and this forum and I'm looking for some help regarding my Teensy 3.5 project. When reading the "How-to Tips" the section "Using I/O pins" talks about reading a full register (8bit) which I would like to use for my project (reading external hardware which offers a byte interface). Unfortunately I have not found anything (yet) to read a full register (8, 16, 32 bit) with one command for the teensy 3.5. When scanning the "Teensy 3.5 & 3.6 Schematic" it looks to me that the registers and pins are not used in a consecutive way - but I might be wrong. Right now I have a working solution at bit basis:

byte read_byte() {
byte b = 0;
b |= digitalRead(A0)<<0;
b |= digitalRead(A1)<<1;
b |= digitalRead(A2)<<2;
b |= digitalRead(A3)<<3;
b |= digitalRead(A4)<<4;
b |= digitalRead(A5)<<5;
b |= digitalRead(A6)<<6;
b |= digitalRead(A7)<<7;
return b;
}

which does not look very efficient to me.

Thanks!
 
When scanning the "Teensy 3.5 & 3.6 Schematic" it looks to me that the registers and pins are not used in a consecutive way - but I might be wrong.
You're right. You can't just read a register.

byte read_byte() {
byte b = 0;
b |= digitalRead(A0)<<0;
b |= digitalRead(A1)<<1;
b |= digitalRead(A2)<<2;
b |= digitalRead(A3)<<3;
b |= digitalRead(A4)<<4;
b |= digitalRead(A5)<<5;
b |= digitalRead(A6)<<6;
b |= digitalRead(A7)<<7;
return b;
}
That's not as bad as you might think. If you use digitalReadFast instead, the compiler can optimize it very good.
which does not look very efficient to me.
Don't think. Measure the time - you'll see - its better than it looks like :)

Edit: You can use different pinnumbers - if I remember correctly, there is a least one full 8bit port. In this case, you can use a register-read. Take a look at the schematics!
Edit: For example, PortC.
 
Status
Not open for further replies.
Back
Top