Simplified access to a Microchip Digital Potentiometer (MCP41xxx/MCP42xxx) devices
Dependents: MCP41xxxApp MCP320xApp MCP41xxxApp
Diff: MCP4xxxx_SPI.h
- Revision:
- 1:cf3cee91eb87
- Parent:
- 0:03314ad622d6
- Child:
- 2:7c27fb9785be
diff -r 03314ad622d6 -r cf3cee91eb87 MCP4xxxx_SPI.h --- a/MCP4xxxx_SPI.h Fri Jan 25 16:10:58 2013 +0000 +++ b/MCP4xxxx_SPI.h Sun Jan 27 17:04:05 2013 +0000 @@ -57,10 +57,10 @@ enum Commands { WriteToPot1, //<! Write to digital potentiometer #1 WriteToPot2, //<! Write to digital potentiometer #2 - WriteToPotBoth, //<! Write to both digital potentiometers + WriteToBoth, //<! Write to both digital potentiometers ShutdownPot1, //<! Shutdown digital potentiometer #1 ShutdownPot2, //<! Shutdown digital potentiometer #2 - ShutdownPotBoth, //<! Shutdown both digital potentiometers + ShutdownBoth, //<! Shutdown both digital potentiometers }; public: /** Constructor with Write Protect command pin wired. @@ -82,26 +82,52 @@ */ inline const SPI * operator * () { return (const SPI *)_spiInstance; }; - /** Write a command + /** Send a write a command (WriteToPot1, WriteToPot2 or WriteBoth) * * @param p_command The command to execute: Write or Shutdown (See DS11195C-page 18) * @param p_value The potentiometer selection bits (See DS11195C-page 14 Clause 4.1 Modes of Operation) - * @return true on success, false otherwise + * @return 0x00 on success, 0Xffff otherwise * Exemple: * @code - * unsigned char value = 0xaa; + * unsigned char potLevel; * ... - * myEEPROM.Write(memoryAddress, value); + * g_chipSelect.write(0); + * g_digitalPot.Write(CMCP4xxxx_SPI::WriteToPot2, potLevel); + * g_chipSelect.write(1); * ... * @endcode */ unsigned short Write(const Commands p_command, const unsigned char p_value); + /** Send a shutdown a command (ShutdownPot1, ShutdownPot2 or ShutdownBoth) + * + * @param p_command The command to execute: Write or Shutdown (See DS11195C-page 18) + * @param p_value The potentiometer selection bits (See DS11195C-page 14 Clause 4.1 Modes of Operation) + * @return 0x00 on success, 0Xffff otherwise + * Exemple: + * @code + * ... + * g_chipSelect.write(0); + * g_digitalPot.Write(CMCP4xxxx_SPI::ShutdownPot1); + * g_chipSelect.write(1); + * ... + * @endcode + */ + unsigned short Write(const Commands p_command); + /** Write a NOP command */ unsigned short Write(); /** Reset the device + * @code + * unsigned char potLevel; + * ... + * g_chipSelect.write(0); + * g_digitalPot.Reset(); + * g_chipSelect.write(1); + * ... + * @endcode */ bool Reset();