SSI does Microchip Port Expanders!
G’day folks,
it hasn’t even been a week since we published our SSI object, and we already found an application for it. We used the SSI to control Microchip’s MCP23017 16-bit port expander.
For those of you who never tested this, Microchip port expanders are I2C or SPI ICs that give you 8 or 16 I/O lines. Add something like this to our (relatively low-pin count EM1206) and you get 16 additional I/O lines for <1US$!
Without further ado, here is the code that setups an I2C channel, configures all I/O lines of the MCP23017 as outputs, and writes &hAA55 to the output ports:

'------------------------------------------------------------------
'configure I2C clock as output
io.num=I2C_SCL 'you need to declare I2C_SCL, I2C_SDA
io.state=HIGH
io.enabled=YES
'setup SSI channel
ssi.channel=0
ssi.mode=PL_SSI_MODE_3
ssi.clkmap=I2C_SCL
ssi.dimap=I2C_SDA
ssi.domap=I2C_SDA
ssi.zmode=PL_SSI_ZMODE_ENABLED_ON_ZERO
ssi.direction=PL_SSI_DIRECTION_LEFT
ssi.baudrate=40 'this I2C device is relatively slow
ssi.enabled=YES
'setup all I/O lines of the MCP23017 as outputs (see Microchip's documentation)
i2c_start()
ssi.str(chr(&h40)+chr(&h00)+chr(&h00)+chr(&h00),1)
i2c_stop()
'output &hAA55 (see Microchip's documentation)
i2c_start()
ssi.str(chr(&h40)+chr(&h12)+chr(&hAA)+chr(&h55),1)
i2c_stop()
'------------------------------------------------------------------
sub i2c_start
io.lineset(I2C_SCL,HIGH)
io.num=I2C_SDA 'set SDA to HIGH first so we can have HIGH->LOW transition
io.state=LOW 'we are manipulating data line through the OE register
io.enabled=NO
io.enabled=YES 'this will set the data output to LOW
end sub
'----------------------------------------------------------------------------
sub i2c_stop
io.lineset(I2C_SCL,LOW) 'this will remove the ack bit
io.num=I2C_SDA 'set SDA to LOW first so we can have LOW->HIGH transition
io.state=LOW 'we are manipulating data line through the OE register
io.enabled=YES
io.lineset(I2C_SCL,HIGH)
io.enabled=NO 'this will set the data output to HIGH
end sub