MCP230xx i2c Port expander
Posted: Sun Dec 17, 2017 10:17 am
An idea for a (some) new components.
I've created a (very) small component for the MCP23008 port expander chip which works well and am about to extend it to the MCP23016/7/8.
My questions (mostly questions of style):
What is preferable: a single component with the chip type as a property or multiple components - one for each chip type? (and if I added support for the SPI version of the chips - would that be better pulled to a separate component or left in one?) I don't currently have an SPI version - and I had MCP23008 and 16 in my parts bin!
How many 'helper' routines are preferable - for example, as a minimum, a SetReg/ReadReg (so SetReg(IODIR, b10001000) - to set input/output pins) or more 'helper' macros such as SetIO(b10010001)
I used I2C master instead of cal_i2c (and I'm just playing at the moment) - but what are the advantages to using cal_i2c in a component?
I created a small helper routing for the MCP23016 to create a clock output on an ATMega328p pin - this is by necessity not portable. Anyone out there able to offer alternate routines PIC/ARM etc or better yet a portable alternative? (Though this is probably overkill - clk signal can be generated using a resistor and capacitor - I just didn't have the recommended values to hand and the MCP23016 has really been superseded by 17 and 18 which don't need a clock signal)
As ever - I don't really have many ideas for what simulation should do here - suggestions/help welcome!
If anyone wants to play - here is the code for the MCP23008 with a simple demo that puts 0..255 - 255..0 onto the output port. I used an Arduino Nano with hardware i2c and the usual pullups.
Martin
I've created a (very) small component for the MCP23008 port expander chip which works well and am about to extend it to the MCP23016/7/8.
My questions (mostly questions of style):
What is preferable: a single component with the chip type as a property or multiple components - one for each chip type? (and if I added support for the SPI version of the chips - would that be better pulled to a separate component or left in one?) I don't currently have an SPI version - and I had MCP23008 and 16 in my parts bin!
How many 'helper' routines are preferable - for example, as a minimum, a SetReg/ReadReg (so SetReg(IODIR, b10001000) - to set input/output pins) or more 'helper' macros such as SetIO(b10010001)
I used I2C master instead of cal_i2c (and I'm just playing at the moment) - but what are the advantages to using cal_i2c in a component?
I created a small helper routing for the MCP23016 to create a clock output on an ATMega328p pin - this is by necessity not portable. Anyone out there able to offer alternate routines PIC/ARM etc or better yet a portable alternative? (Though this is probably overkill - clk signal can be generated using a resistor and capacitor - I just didn't have the recommended values to hand and the MCP23016 has really been superseded by 17 and 18 which don't need a clock signal)
As ever - I don't really have many ideas for what simulation should do here - suggestions/help welcome!
If anyone wants to play - here is the code for the MCP23008 with a simple demo that puts 0..255 - 255..0 onto the output port. I used an Arduino Nano with hardware i2c and the usual pullups.
Martin