Matthew Mellor / MCP32082Two

Dependents:   sendFootSensorsPacketsFinalUDP

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers mcp3208.cpp Source File

mcp3208.cpp

00001 //
00002 //
00003 //
00004 #include "mcp3208.h"
00005 
00006 
00007 MCP3208::MCP3208(PinName mosi, PinName miso, PinName clk, PinName cs)
00008 :   _spi(mosi,miso,clk),
00009     _cs(cs),
00010     _vref(5.0)
00011 {
00012     _spi.frequency(2000000);
00013     _spi.format(12,3);
00014     _cs = 1;
00015 }
00016 
00017 int
00018 MCP3208::binary(int ch)
00019 {
00020     _cs = 0;
00021     int ret = _spi.write((0x18|ch)<<2);
00022     int adb = _spi.write(0);
00023     _cs = 1;
00024     return adb;
00025 }
00026 
00027 float
00028 MCP3208::volt(int ch)
00029 {
00030     return _vref * binary(ch) / 4095;
00031 }