Hardware i2c/keyscan capabilities of teensy 4.1?

Status
Not open for further replies.

sleeper

Member
I'm working on an audio project, and I want to get the most I can from the CPU. What I am worried about is how to better optimize my GPIO/I2C to reduce CPU overhead. I have 2 problems...

1: I'm using 7 i2c hall sensors with no useful way to change address, so my initial solution was to use 1 clock and 7 data lines and bit-bang it.

2: I have a 7x12 switch matrix which I need to poll everything at >2khz to get key velocity info. Basically drive one the 7 pins low, and read the other 12, cycle. I can do this with a timer interrupt for now.

The real question I have is if Teensy4/4.1 has a way for the hardware to "automate" these sorts of tasks, avoiding the CPU penalties of high frequency interrupts.
 
For #1, consider using an I2C multiplexer. That way you can use the hardware I2C support.

If you use digitalWriteFast and digitalReadFast where the pin argument is constant, it expands to just a few instructions and no procedure call overhead. This will often mean changing a loop to straight-line code to do each read.

If you really need to cut cycles, you can write your own code to bypass the Arduino pins, and select your pins based on the GPIO mappings. This will allow you to combine several reads or writes into one operation. However, if you do this, you will be locked into the Teensy 4.0/4.1 chipset, and if you move to something else, you will need to rewrite this section, and possible redo the pin layout.
 
Last edited:
These are good suggestions. The multiplexer is probably a must when I try expanding to 40+ i2c sensors some day. But I'm also more confident with software solutions than hardware,

I guess I'm really hoping to hear if someone knows if DMA or FlexIO can do these things. A simple yes/no would help me decide if it's worth the time to dive in to that.
 
Status
Not open for further replies.
Back
Top