Jolyon Hill / MCP23S17

Dependents:   ColourSensor

Fork of MCP23S17 by Romilly Cocking

main.cpp

Committer:
romilly
Date:
2010-08-18
Revision:
0:930da696072e
Child:
1:5abd129839e7

File content as of revision 0:930da696072e:

#include "mbed.h"

/* first attempt at driving an MCP23S17
*
* Turns alternate bits of B register on and off
* 
* I have not added many comments yet.
* This is a proof of concept,
* not a finished example.
*/

DigitalOut myled(LED1);

SPI spi(p5, p6, p7);
DigitalOut ncs(p20);

void write(char command, char address, char data) {
    ncs = 0;
    spi.write(command);
    spi.write(address);
    spi.write(data);
    ncs = 1;
}

void init() {
    write(0x40, 0x0A, 0xA0);
    write(0x40, 0x10, 0x00);
}

void output(char byte) {
    ncs = 0;
     write(0x40,0x1A, byte); // configures for multi-write - could send a series of bytes for immediate output
    ncs = 1;  
}

int main() {
    init();
    while(1) {
        myled = 1;
        wait(0.2);
        output(0xAA);
        myled = 0;
        wait(0.2);
        output(0x55);
    }
}