This is library for mcp320x. But operation check is not finished only "mcp3204".
Dependents: Nucleo_mcp3204test
MCP320x.h
- Committer:
- SK_ROBO_
- Date:
- 2016-01-29
- Revision:
- 2:d2c51376ee7c
- Parent:
- 1:66fdf46dc4de
File content as of revision 2:d2c51376ee7c:
#if !defined(__MCP320x_H__) #define __MCP320x_H__ #include <string> //#include <vector> #include "mbed.h" namespace MCP320x_SPI { class CMCP320x_SPI { /** Reference counter used to guarentee unicity of the instance of SPI class */ static unsigned char SPIModuleRefCounter; /** ChipSelect (pin 1) see DS21290F-page 15 Clause 3.3 Chip Select/Shutdown (CS/SHDN) */ DigitalOut *_cs; /** An unique instance of SPI class */ SPI *_spiInstance; /** ADC sample structure */ typedef union { unsigned int value; struct { unsigned char bytes[2]; }; } ADCValue; ADCValue _sample; /** Number of channels according to the IC type */ unsigned char _channelsNum; /** Set to true for single-ended inputs configuration, false for pseudo-differential inputs * @see DS21298E-page 19 Clause 5.0 SERIAL COMMUNICATIONS */ unsigned char _settings; public: /** MCP320x familly */ enum Mcp320xFamilly { _3201 = 0x00, /** See DS21290F */ _3204 = 0x01, /** See DS21298E */ _3208 = 0x03 /** See DS21298E */ }; Mcp320xFamilly _familly; /** MCP320x channels to read */ enum Mcp320xChannels { CH0 = 0x00, /** See DS21290F/DS21290F */ CH1 = 0x01, /** See DS21298E */ CH2 = 0x02, /** See DS21298E */ CH3 = 0x03, /** See DS21298E */ CH4 = 0x04, /** See DS21298E */ CH5 = 0x05, /** See DS21298E */ CH6 = 0x06, /** See DS21298E */ CH7 = 0x07 /** See DS21298E */ }; public: /** Constructor with Write Protect command pin wired. * * @param p_mosi: MBed pin for SDI * @param p_miso: MBed pin for SDO * @param p_sclk: MBed pin for CLK * @param p_cs : MBed pin for Chip Select. If NC, assumes that application manage /CS, default value is NC, not connected * @param p_familly: MCP320x familly. Default: _3201 * @param p_frequency: Frequency of the SPI interface (SCK), default value is 1MHz */ CMCP320x_SPI(const PinName p_mosi, const PinName p_miso, const PinName p_sclk, const PinName p_cs = NC, const Mcp320xFamilly p_familly = _3201, const unsigned int p_frequency = 1000000); /** Destructor * If managed, the /CS pin is set to 1 before to release it */ virtual ~CMCP320x_SPI(); /** Used to return the unique instance of SPI instance */ inline const SPI * operator * () { return (const SPI *)_spiInstance; }; /** * @desc Launch an analog to digital conversion on the specified channel * @param p_channel The channel to convert * @return The converted value */ float Read(const Mcp320xChannels p_channels = CH1); /** * @desc Change current configuration (only for MCP3204/8) * @param p_setConfig Set to true for single-ended inputs configuration, false for pseudo-differential inputs * @see DS21298E-page 17 Clause 4.1 Analog Inputs */ void SetConfig(const bool p_settings); /** Shutdown the device */ bool Shutdown(const bool p_shutdown); private: /** Internal reference identifier */ std::string _internalId; private: /** * @desc Launch an analog to digital conversion on the specified channel for MCP3201 * @see DS21290F-page 17 Clause 4.1 Analog Inputs */ void Read_3201(); /** * @desc Launch an analog to digital conversion on the specified channel for MCP3204/8 * @param p_setConfig Set to true for single-ended inputs configuration, false for pseudo-differential inputs * @see DS21298E-page 17 Clause 4.1 Analog Inputs */ void Read_320x(const Mcp320xChannels p_channels); }; // End of class CMCP320x_SPI } // End of namespace MCP320x_SPI using namespace MCP320x_SPI; #endif // __MCP320x_SPI_H__