Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: MCP41xxxApp MCP320xApp MCP41xxxApp
CMCP4xxxx_SPI Class Reference
This class provides simplified SPI access to a Microchip MCP42xxx/MCP41xxx Digital Potentiometer device. More...
#include <MCP4xxxx_SPI.h>
Public Types | |
| enum | Mcp4xxxFamily |
MCP32xx family. More... | |
| enum | Commands |
Authorized commands See DS11195C-page 18. More... | |
| enum | Addresses |
Register adresses See DS22060B-page 33 Clause 4.0 FUNCTIONAL OVERVIEW. More... | |
Public Member Functions | |
| CMCP4xxxx_SPI (const PinName p_mosi, const PinName p_miso, const PinName p_sclk, const PinName p_cs=NC, const PinName p_reset=NC, const PinName p_shdn=NC, const Mcp4xxxFamily family=_41xxx, const unsigned int p_frequency=1000000) | |
| Constructor with Write Protect command pin wired. | |
| virtual | ~CMCP4xxxx_SPI () |
| Destructor. | |
| const SPI * | operator* () |
| Used to return the unique instance of SPI instance. | |
| unsigned short | WriteRegister (const Addresses p_address, const unsigned char p_value) |
| Write a value to the specified register. | |
| unsigned short | ReadRegister (const Addresses p_address) |
| Read the content of the specified register. | |
| unsigned short | Increment (const Commands p_command=WriteToDigiPot1) |
| Increment the specified digital potentiometer. | |
| unsigned short | Decrement (const Commands p_command=WriteToDigiPot1) |
| Decrement the specified digital potentiometer. | |
| unsigned short | Write (const Commands p_command, const unsigned char p_value) |
| Send a write a command (WriteToPot1, WriteToPot2 or WriteBoth) | |
| unsigned short | Shutdown (const Commands p_command, const bool p_set=true) |
| Send a shutdown a command (ShutdownPot1, ShutdownPot2 or ShutdownBoth) | |
| Mcp4xxxFamily | SetFamilly (const Mcp4xxxFamily family) |
| Write a NOP command. | |
| void | Reset () |
| Reset the device. | |
| void | Shutdown (const bool p_set) |
| Shutdown the device. | |
Detailed Description
This class provides simplified SPI access to a Microchip MCP42xxx/MCP41xxx Digital Potentiometer device.
V0.0.0.2 The SPI static settings are: 16bits, mode (0,0) This class manages ONLY ONE /CS pin. If more than one SPI devices are used, ALL /CS pins shall be done by the application itself
Microchip MCP42xxx/MCP41xxx Serial EEPROM device reference: DS11195C Microchip MCP41xx/MCP42xx Serial EEPROM device reference: DS122060B
Note that MCP41xxx has no SO pin, only a SOI input pin Note that MCP42xxx has a SO pin reserved for daisy-chain configuration Note that MCP41xx/MCP42xx increment/decrement operations are not supported due to the 16 bits SPI setting Note that for SPI details, please visit http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus
- Remarks:
- This class was validated with Tektronix TDS2014 oscilloscope in 3.3V and in mixte power mode 3.3V for mbed and 5V for the Microchip 24LCxx Serial EEPROM device
Definition at line 44 of file MCP4xxxx_SPI.h.
Member Enumeration Documentation
| enum Addresses |
Register adresses See DS22060B-page 33 Clause 4.0 FUNCTIONAL OVERVIEW.
Definition at line 92 of file MCP4xxxx_SPI.h.
| enum Commands |
Authorized commands See DS11195C-page 18.
Definition at line 81 of file MCP4xxxx_SPI.h.
| enum Mcp4xxxFamily |
MCP32xx family.
Definition at line 70 of file MCP4xxxx_SPI.h.
Constructor & Destructor Documentation
| CMCP4xxxx_SPI | ( | const PinName | p_mosi, |
| const PinName | p_miso, | ||
| const PinName | p_sclk, | ||
| const PinName | p_cs = NC, |
||
| const PinName | p_reset = NC, |
||
| const PinName | p_shdn = NC, |
||
| const Mcp4xxxFamily | family = _41xxx, |
||
| const unsigned int | p_frequency = 1000000 |
||
| ) |
Constructor with Write Protect command pin wired.
- Parameters:
-
p_mosi,: MBed pin for SDI p_miso,: MBed pin for SDO. Note that this pin does not exist for MCP41xxx p_sclk,: MBed pin for CLK p_cs : MBed pin for Chip Select. If NC, assumes that application manage /CS, default value is NC, not connected p_reset,: MBed pin to manage /RESET input. If NC, /RESET is not managed, default value is NC, not connected p_shdn,: MBed pin to manage /SHDN input. If NC, /SHDN is not managed, default value is NC, not connected p_frequency,: Frequency of the SPI interface (SCK), default value is 1MHz
Definition at line 26 of file MCP4xxxx_SPI.cpp.
| ~CMCP4xxxx_SPI | ( | ) | [virtual] |
Destructor.
Definition at line 74 of file MCP4xxxx_SPI.cpp.
Member Function Documentation
| unsigned short Decrement | ( | const Commands | p_command = WriteToDigiPot1 ) |
Decrement the specified digital potentiometer.
- Parameters:
-
p_command The digital potentiometer to decrement. Default: WriteToDigiPot1
- Returns:
- 0x0000 on success, any value otherwise
Definition at line 155 of file MCP4xxxx_SPI.cpp.
| unsigned short Increment | ( | const Commands | p_command = WriteToDigiPot1 ) |
Increment the specified digital potentiometer.
- Parameters:
-
p_command The digital potentiometer to increment. Default: WriteToDigiPot1
- Returns:
- 0x0000 on success, any value otherwise
Definition at line 147 of file MCP4xxxx_SPI.cpp.
| const SPI* operator* | ( | ) |
Used to return the unique instance of SPI instance.
Definition at line 115 of file MCP4xxxx_SPI.h.
| unsigned short ReadRegister | ( | const Addresses | p_address ) |
Read the content of the specified register.
Only for _41xx/_42xx famillies
- Parameters:
-
p_address The register to be written
- Returns:
- The register value
Definition at line 128 of file MCP4xxxx_SPI.cpp.
| void Reset | ( | ) |
Reset the device.
unsigned char potLevel; ... g_digitalPot.Reset(); ...
Definition at line 289 of file MCP4xxxx_SPI.cpp.
| CMCP4xxxx_SPI::Mcp4xxxFamily SetFamilly | ( | const Mcp4xxxFamily | family ) |
Write a NOP command.
Change the current family
- Parameters:
-
family The new type of ICs
- Returns:
- the previous type of ICs
Definition at line 273 of file MCP4xxxx_SPI.cpp.
| void Shutdown | ( | const bool | p_set ) |
Shutdown the device.
Definition at line 299 of file MCP4xxxx_SPI.cpp.
| unsigned short Shutdown | ( | const Commands | p_command, |
| const bool | p_set = true |
||
| ) |
Send a shutdown a command (ShutdownPot1, ShutdownPot2 or ShutdownBoth)
- Parameters:
-
p_command The command to execute (See DS11195C-page 18) p_set Set to true to shutdown, false to set up. Only used for _41xx/_42xx famillies (See DS22060B-page 36 REGISTER 4-2: TCON BITS)
- Returns:
- 0x0000 on success, 0Xffff otherwise Exemple:
... g_chipSelect.write(0); g_digitalPot.Shutdown(CMCP4xxxx_SPI::ShutdownPot1); g_chipSelect.write(1); ...
Definition at line 208 of file MCP4xxxx_SPI.cpp.
| unsigned short Write | ( | const Commands | p_command, |
| const unsigned char | p_value | ||
| ) |
Send a write a command (WriteToPot1, WriteToPot2 or WriteBoth)
- Parameters:
-
p_command The command to execute (See DS11195C-page 18) p_value The potentiometer selection bits (See DS11195C-page 14 Clause 4.1 Modes of Operation)
- Returns:
- 0x0000 on success, 0Xffff otherwise Exemple:
unsigned char potLevel; ... g_chipSelect.write(0); g_digitalPot.Write(CMCP4xxxx_SPI::WriteToPot2, potLevel); g_chipSelect.write(1); ...
Definition at line 164 of file MCP4xxxx_SPI.cpp.
| unsigned short WriteRegister | ( | const Addresses | p_address, |
| const unsigned char | p_value | ||
| ) |
Write a value to the specified register.
Only for _41xx/_42xx famillies
- Parameters:
-
p_address The register to be written p_value The value to write
- Returns:
- 0x0000 on success, any value otherwise
Definition at line 103 of file MCP4xxxx_SPI.cpp.
Generated on Tue Jul 12 2022 18:38:23 by
1.7.2