Simplified access to a Microchip Digital Potentiometer (MCP41xxx/MCP42xxx) devices
Dependents: MCP41xxxApp MCP320xApp MCP41xxxApp
Diff: MCP4xxxx_SPI.cpp
- Revision:
- 4:bbfc8e352ff5
- Parent:
- 2:7c27fb9785be
- Child:
- 5:4f6133144e7e
diff -r 0acab5201dd8 -r bbfc8e352ff5 MCP4xxxx_SPI.cpp
--- a/MCP4xxxx_SPI.cpp Sat Feb 02 10:15:25 2013 +0000
+++ b/MCP4xxxx_SPI.cpp Mon Feb 04 17:15:33 2013 +0000
@@ -1,4 +1,4 @@
-/* mbed simplified access to Microchip 24LCxx Serial EEPROM devices (SPI)
+/* mbed simplified access to Microchip MCP42xxx/MCP41xxx Digital Potentiometer devices (SPI)
* Copyright (c) 2013 ygarcia, MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
@@ -26,14 +26,15 @@
CMCP4xxxx_SPI::CMCP4xxxx_SPI(const PinName p_mosi, const PinName p_miso, const PinName p_sclk, const PinName p_cs, const PinName p_reset, const PinName p_shdn, const unsigned int p_frequency) : _internalId("") {
DEBUG_ENTER("CMCP4xxxx_SPI")
- if (CMCP4xxxx_SPI::SPIModuleRefCounter != 0) {
- error("CMCP4xxxx_SPI: Wrong params");
+ CMCP4xxxx_SPI::SPIModuleRefCounter += 1;
+ if (CMCP4xxxx_SPI::SPIModuleRefCounter > 1) {
+ // Nothing to do
+ return;
}
_spiInstance = new SPI(p_mosi, p_miso, p_sclk);
_spiInstance->frequency(p_frequency); // Set the frequency of the SPI interface
_spiInstance->format(16, 0); // See http://mbed.org/users/mbed_official/code/mbed/docs/0954ebd79f59//classmbed_1_1SPI.html
- CMCP4xxxx_SPI::SPIModuleRefCounter += 1;
DEBUG_ENTER("CMCP4xxxx_SPI: refCounter=%d", CMCP4xxxx_SPI::SPIModuleRefCounter)
if (p_cs != NC) {
Yann Garcia