Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: MCP23S17Test MCP23S17_Basic_IO_Demo HelloWorld Lab3-SnakeGame ... more
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);
}
}
MCP23S17 I/O Expander