Ive used i2c implementation found on: https://github.com/RedBearLab/Biscuit
Remember to change #defines to reflect your wiring. Also check .c file for hardcoded ports. You need to change this before running code.
My wiring of MCP23009 to BLE112:
wiring MCP23009 i2c extender to CC2540 (BLE112) |
First you need to establish connection to MCP23009 (i2c address: 0x40) and set few registers:
i2c_init();
i2c_start(0x40);
// io mode
i2c_write(0x00); // IODIR
i2c_write(0x00); // 00 - all pins as output
i2c_stop();
// polarity
i2c_restart(0x40);
i2c_write(0x01);
i2c_write(0x00);
i2c_stop();
// config
i2c_restart(0x40);
i2c_write(0x05);
i2c_write(0x00);
i2c_stop();
// pullup
i2c_restart(0x40);
i2c_write(0x06);
i2c_write(0x00); // 00 - disable pullups
i2c_stop();
Registers can be found in datasheet, quick look to understand what registers was set in code:
Then you can turn on LED:
i2c_restart(0x40);
i2c_write(0x09);
i2c_write(0xFE);
i2c_stop();
Useful links:
MCP23009 datasheet
No comments:
Post a Comment