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

Thread: Port Expander compatibility - MCP23017 + Teensy 4.0

  1. #1

    Port Expander compatibility - MCP23017 + Teensy 4.0

    It looks as if the MCP23017 is sold as a general purpose port expander for a wide range of 3.3v-5v platforms. Is there anything to be concerned about, if I use this with a T4.0?

    For example the MCP23017-E/SO (randomly chosen variant at the top of a Google search) on Mouser is 16-bit, with a max speed of 1.7MHz. The T4.0 is 600MHz - the 1.7MHz max applies to I2C bus speed then? And 16 bits... the T4.0 is 32 bit. Again, I'm assuming these are specifications apply only to the bus, not the microcontroller itself?

    Apologies if this sounds idiotic; I'd just rather not assume!


  2. #2
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Ayer Massachussetts
    I've used the MCP23017 on a Teensy 4.0. It works fine, providing:

    You use 3.3v for the VIN on the MC23017. It can be harmed with 5v input from the I2C device. If you must deal with 5v devices on the I2C bus, there are ways to shift the voltage levels so you don't fry the Teensy. The MCP23017 will work with either 3.3v or 5v applied to the VIN; (and)

    I2C on the Teensy requires external pull-up resistors, unless the device has its own pull-up resistors. On the Teensy if you have a fairly simple I2C bus layout, you would want one 2.2K resistor between SDA (pin 18) and 3.3v, and another 2.2K resistor between SCL (pin 19) and 3.3v. Higher resistor values such as 4.7K usually used for 5v systems will generally work up until 10K or so. If you have a complex bus and/or long wires, you may need to use other resistors.

    The default I2C bus speed is fairly slow. Generally for things involving human reaction times, it is not too slow.

    There is an alternative call in the MCP23017 library where you can get 8 bits at a time, which reduces the number of I2C calls that must be made. For button presses, you can attach a pin to the Teensy which be attached to an interrupt, so that you know when a button in a group of 8 buttons has been pressed (i.e. you don't have to poll each button all of the time, you get an interrupt that tells you to poll the buttons in the next loop call).

    I2C is a shared bus, where each slave device has an address. The MCP230917 has sevaral pins/solder pads that allow you to change the address. By doing so, you can attach multiple MCP23017's to a system.

  3. #3
    Thanks. I've been down the road of I2C bus devices a few times now, mainly just curious as to how the speed and bit width disparity between the Teensy and a chip like this actually plays out. But this is a great list of things to bear in mind, I usually forget at least one of them in the process of experimenting with a new device Had to wonder about whether the vastly faster T4.0 would begin to have issues with any of this stuff and it looks like I will be fine in this case.

    About using the 8-bit alternative call to gain the ability to use interrupts, that is really good info, I have many functions that are timing critical (sending MIDI data, reading a gyro/IMU every 4ms, etc.) - the more lean I can make things, the better.

Posting Permissions

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