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.
Fork of MCP23S17 by
Diff: main.cpp
- Revision:
- 0:930da696072e
- Child:
- 1:5abd129839e7
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Wed Aug 18 12:30:39 2010 +0000
@@ -0,0 +1,46 @@
+#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);
+ }
+}
