Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: Hardware i2c/keyscan capabilities of teensy 4.1?

  1. #1
    Junior Member
    Join Date
    Feb 2020

    Hardware i2c/keyscan capabilities of teensy 4.1?

    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.

  2. #2
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Ayer Massachussetts


    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 by MichaelMeissner; 05-09-2021 at 04:57 PM.

  3. #3
    Junior Member
    Join Date
    Feb 2020
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts