2.7V 4-Channel 12-Bit A/D Converters with SPI™ Serial Interface
Fork of MCP3204 by
Revision 1:cf7328552994, committed 2016-01-20
- Comitter:
- stjo2809
- Date:
- Wed Jan 20 10:53:06 2016 +0000
- Parent:
- 0:b5950cd5e330
- Commit message:
- Tested
Changed in this revision
MCP3204.cpp | Show annotated file Show diff for this revision Revisions of this file |
MCP3204.h | Show annotated file Show diff for this revision Revisions of this file |
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 + }
diff -r b5950cd5e330 -r cf7328552994 MCP3204.h --- a/MCP3204.h Mon Mar 23 07:49:58 2015 +0000 +++ b/MCP3204.h 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 @@ -55,17 +55,7 @@ * @param spi The mbed SPI instance (make in main routine) * @param nCs The SPI chip select pin. */ - MCP3204(SPI& spi, PinName nCs); - - /** Create an instance of the MCP4261 connected with SPI pins. - * - * @param mosi The SPI Master Output, Slave Input pin. - * @param miso The SPI Master Input, Slave Output pin. - * @param sck The SPI Serial Clock pin. - * @param nCs The SPI chip select pin. - */ - MCP3204(PinName mosi, PinName miso,PinName sck, PinName nCs); - + MCP3204(SPI& spi, PinName nCs); /** Read from single channel. * @@ -86,7 +76,7 @@ SPI& _spi; DigitalOut _nCs; - int _make_value_from_responce(int responce_msb, int responce_lsb); + int _make_value_from_responce(int _msb, int _lsb); int _read(char sgl_or_diff, char channel); };