2.7V 4-Channel 12-Bit A/D Converters with SPI™ Serial Interface
Fork of MCP3204 by
Diff: MCP3204.cpp
- Revision:
- 1:cf7328552994
- Parent:
- 0:b5950cd5e330
diff -r b5950cd5e330 -r cf7328552994 MCP3204.cpp --- a/MCP3204.cpp Mon Mar 23 07:49:58 2015 +0000 +++ b/MCP3204.cpp Wed Jan 20 10:53:06 2016 +0000 @@ -1,4 +1,4 @@ -/* mbed MCP3204 Library, for driving the 2.7V 4-Channel/8-Channel 12-Bit A/D Converters with SPI™ Serial Interface +/* mbed MCP3204 Library, for driving the 2.7V 4-Channel 12-Bit A/D Converters with SPI™ Serial Interface * Copyright (c) 2015, Created by Steen Joergensen (stjo2809) * * Permission is hereby granted, free of charge, to any person obtaining a copy @@ -29,16 +29,9 @@ MCP3204::MCP3204(SPI& spi, PinName nCs) : _spi(spi), _nCs(nCs) { - + _nCs = 1; _nCs = 0; _nCs = 1; } - - MCP3204::MCP3204(PinName mosi, PinName miso,PinName sck, PinName nCs) : _mosi(mosi), _miso(miso), _sck(sck), _nCs(nCs) - { - SPI _spi(_mosi,_miso,_sck); - } - - int MCP3204::sgl(char channel) { return _read(SINGLE, channel); @@ -55,13 +48,15 @@ int MCP3204::_make_value_from_responce(int _msb, int _lsb) { - --- code --- + int responce = _msb << 8; + responce = responce | _lsb; + responce = responce & 0xfff; + + return responce; } int MCP3204::_read(char sgl_or_diff, char channel) { - _make_value_from_responce(int responce_msb, int responce_lsb); - _nCs = 0; _spi.write(sgl_or_diff); int responce_msb = _spi.write(channel); @@ -71,4 +66,4 @@ int responce = _make_value_from_responce(responce_msb, responce_lsb); return responce; - } \ No newline at end of file + }