0.1.6 MCP_ADC

This commit is contained in:
rob tillaart 2021-08-01 15:51:21 +02:00
parent d76462113f
commit 68e354dfed
5 changed files with 37 additions and 13 deletions

View File

@ -1,7 +1,7 @@
//
// FILE: MCP_ADC.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.5
// VERSION: 0.1.6
// DATE: 2019-10-24
// PURPOSE: Arduino library for MCP3002, MCP3004, MCP3008, MCP3202, MCP3204, MCP3208
// URL: https://github.com/RobTillaart/MCP_ADC
@ -35,15 +35,18 @@ void MCP_ADC::begin(uint8_t select)
if (_useHSPI) // HSPI
{
mySPI = new SPIClass(HSPI);
mySPI->begin(14, 12, 13, _select); // CLK MISO MOSI SELECT
mySPI->end();
mySPI->begin(14, 12, 13, select); // CLK=14 MISO=12 MOSI=13
}
else // VSPI
{
mySPI = new SPIClass(VSPI);
mySPI->begin(18, 19, 23, _select); // CLK MISO MOSI SELECT
mySPI->end();
mySPI->begin(18, 19, 23, select); // CLK=18 MISO=19 MOSI=23
}
#else // generic SPI
#else // generic hardware SPI
mySPI = &SPI;
mySPI->end();
mySPI->begin();
#endif
}
@ -65,7 +68,11 @@ void MCP_ADC::setGPIOpins(uint8_t clk, uint8_t miso, uint8_t mosi, uint8_t selec
_dataIn = miso;
_dataOut = mosi;
_select = select;
mySPI->begin(_clock, miso, _dataOut, _select); // CLK MISO MOSI SELECT
pinMode(_select, OUTPUT);
digitalWrite(_select, HIGH);
mySPI->end(); // disable SPI
mySPI->begin(clk, miso, mosi, select);
}
#endif

View File

@ -2,7 +2,7 @@
//
// FILE: MCP_ADC.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.5
// VERSION: 0.1.6
// DATE: 2019-10-24
// PURPOSE: Arduino library for MCP_ADC
// URL: https://github.com/RobTillaart/MCP_ADC
@ -13,7 +13,7 @@
#include "SPI.h"
#define MCP_ADC_LIB_VERSION (F("0.1.5"))
#define MCP_ADC_LIB_VERSION (F("0.1.6"))
class MCP_ADC
@ -41,7 +41,8 @@ public:
void selectVSPI() { _useHSPI = false; };
bool usesHSPI() { return _useHSPI; };
bool usesVSPI() { return !_useHSPI; };
// to overrule ESP32 default hw pins...
// to overrule ESP32 default hardware pins
void setGPIOpins(uint8_t clk, uint8_t miso, uint8_t mosi, uint8_t select);
#endif

View File

@ -86,7 +86,24 @@ Differential channel table
- **void selectVSPI()** see above.
- **bool usesHSPI()** returns true if HSPI is used.
- **bool usesVSPI()** returns true if VSPI is used.
- **void setGPIOpins(clk, miso, mosi, select)** overrule GPIO pins of ESP32 for hardware SPI.
The **selectVSPI()** or the **selectHSPI()** needs to be called
BEFORE the **begin()** function.
#### experimental
- **void setGPIOpins(clk, miso, mosi, select)** overrule GPIO pins of ESP32 for hardware SPI. needs to be called
AFTER the **begin()** function.
```cpp
void setup()
{
MCP.selectVSPI();
MCP.begin(15);
MCP.setGPIOpins(CLK, MISO, MOSI, SELECT); // SELECT should match the param of begin()
}
```
## About SPI Speed
@ -118,7 +135,6 @@ For hardware SPI the ESP32 uses the VSPI pins. (see ESP examples).
it actually does float mapping. As it implies the same mapping for all it might
not be that useful
- analogRead (mask, int array\[8\] ) read ports (set in mask) in an array in one call.
- ESP32 - how to integrate the HSPI interface.
## Operations

View File

@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/MCP_ADC.git"
},
"version": "0.1.5",
"version": "0.1.6",
"license": "MIT",
"frameworks": "*",
"platforms": "*"

View File

@ -1,5 +1,5 @@
name=MCP_ADC
version=0.1.5
version=0.1.6
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for MCP3002, MCP3004, MCP3008, MCP3202, MCP3204, MCP3208