FlexBook / Mbed 2 deprecated FlexBook171204a

Dependencies:   SDFileSystem app epson mbed msp430 pl tests

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers mcp23s17.cpp Source File

mcp23s17.cpp

00001 //
00002 // Filename: mcp23s17.cpp
00003 //
00004 // Flexbook Hardware Abstraction Layer.
00005 //
00006 
00007 #include "mcp23s17.h"
00008 
00009 namespace HAL {
00010 
00011 MCP23S17::MCP23S17(int addressin, SPI &spiin, DigitalOut &csin)
00012 : address(addressin), spi(spiin), cs(csin)
00013 {
00014     spi.format(8, 1);
00015 }
00016 
00017 int MCP23S17::Read(REG_MCP23S17 reg)
00018 {
00019     cs = 0;
00020     spi.write(address | 0x41);
00021     spi.write(reg);
00022     int data = spi.write(0x00); // Write dummy value to read.
00023     cs = 1;
00024     
00025     return data;
00026 }
00027 
00028 void MCP23S17::Write(REG_MCP23S17 reg, int value)
00029 {
00030     cs = 0;
00031     spi.write(address | 0x40);
00032     spi.write(reg);
00033     spi.write(value);
00034     cs = 1;
00035 }
00036 
00037 } // End HAL namespace.
00038