0

Datasheet for reference here.

The port registers of the MCP23017 I2C I/O expander can be configured in two ways using the IOCON.BANK bit as follows:

If BANK = 0, the A/B registers are paired. For example, IODIRA is mapped to address 00h and IODIRB is mapped to the next address (address 01h). The mapping for all registers is from 00h -15h.

If BANK = 1, the registers associated with each port are segregated. Registers associated with PORTA are mapped from address 00h - 0Ah and registers associated with PORTB are mapped from 10h - 1Ah.

By changing the IOCON.BANK bit, the address of the IOCON register itself changes, see table 3-4, 3-5 in the datasheet.

So, in the case of a MCU reset, how do you determine the state of IOCON.BANK without resetting the MCP23017 so that any peripherals attached to the MCP23017 are unaffected?

Per
  • 131
  • 5

1 Answers1

3

My conclusion is that you cannot determine the state of IOCON.BANK, but you can however get it into a known value without resetting the MCP23017 using the following procedure:

  1. Assume IOCON.BANK = 1
  2. Read register 0x05.
  3. Clear bit 7 (presumably the BANK bit) of the stored value then write that value back to 0x05.

At this point you have either:

  • Switched from BANK = 1 to BANK = 0

or

  • Disabled GPINTENB.GPINT7

To finish, set GPINTENB.GPINT7 if needed.

You now have a known state with IOCON.BANK = 0.

Per
  • 131
  • 5
  • I was hoping the answer wasn't something like this, but I'm glad you've given me a clear solution. – drojf Oct 20 '20 at 08:09