🎨 Rename MAX31865 elements
This commit is contained in:
parent
b77a5d4c8d
commit
8d4e4ac115
|
@ -73,10 +73,10 @@ SPISettings MAX31865::spiConfig = SPISettings(
|
||||||
* @param spi_clk the SPI clock pin to use
|
* @param spi_clk the SPI clock pin to use
|
||||||
*/
|
*/
|
||||||
MAX31865::MAX31865(int8_t spi_cs, int8_t spi_mosi, int8_t spi_miso, int8_t spi_clk) {
|
MAX31865::MAX31865(int8_t spi_cs, int8_t spi_mosi, int8_t spi_miso, int8_t spi_clk) {
|
||||||
_cs = spi_cs;
|
cselPin = spi_cs;
|
||||||
_mosi = spi_mosi;
|
mosiPin = spi_mosi;
|
||||||
_miso = spi_miso;
|
misoPin = spi_miso;
|
||||||
_sclk = spi_clk;
|
sclkPin = spi_clk;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -86,8 +86,8 @@ SPISettings MAX31865::spiConfig = SPISettings(
|
||||||
* @param spi_cs the SPI CS pin to use along with the default SPI device
|
* @param spi_cs the SPI CS pin to use along with the default SPI device
|
||||||
*/
|
*/
|
||||||
MAX31865::MAX31865(int8_t spi_cs) {
|
MAX31865::MAX31865(int8_t spi_cs) {
|
||||||
_cs = spi_cs;
|
cselPin = spi_cs;
|
||||||
_sclk = _miso = _mosi = -1;
|
sclkPin = misoPin = mosiPin = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#else // LARGE_PINMAP
|
#else // LARGE_PINMAP
|
||||||
|
@ -104,10 +104,10 @@ SPISettings MAX31865::spiConfig = SPISettings(
|
||||||
* @param pin_mapping set to 1 for positive pin values
|
* @param pin_mapping set to 1 for positive pin values
|
||||||
*/
|
*/
|
||||||
MAX31865::MAX31865(uint32_t spi_cs, uint32_t spi_mosi, uint32_t spi_miso, uint32_t spi_clk, uint8_t pin_mapping) {
|
MAX31865::MAX31865(uint32_t spi_cs, uint32_t spi_mosi, uint32_t spi_miso, uint32_t spi_clk, uint8_t pin_mapping) {
|
||||||
_cs = spi_cs;
|
cselPin = spi_cs;
|
||||||
_mosi = spi_mosi;
|
mosiPin = spi_mosi;
|
||||||
_miso = spi_miso;
|
misoPin = spi_miso;
|
||||||
_sclk = spi_clk;
|
sclkPin = spi_clk;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -119,8 +119,8 @@ SPISettings MAX31865::spiConfig = SPISettings(
|
||||||
* @param pin_mapping set to 1 for positive pin values
|
* @param pin_mapping set to 1 for positive pin values
|
||||||
*/
|
*/
|
||||||
MAX31865::MAX31865(uint32_t spi_cs, uint8_t pin_mapping) {
|
MAX31865::MAX31865(uint32_t spi_cs, uint8_t pin_mapping) {
|
||||||
_cs = spi_cs;
|
cselPin = spi_cs;
|
||||||
_sclk = _miso = _mosi = -1UL; //-1UL or 0xFFFFFFFF or 4294967295
|
sclkPin = misoPin = mosiPin = -1UL; //-1UL or 0xFFFFFFFF or 4294967295
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // LARGE_PINMAP
|
#endif // LARGE_PINMAP
|
||||||
|
@ -139,12 +139,12 @@ SPISettings MAX31865::spiConfig = SPISettings(
|
||||||
* @param ref The resistance of the reference resistor, in ohms.
|
* @param ref The resistance of the reference resistor, in ohms.
|
||||||
*/
|
*/
|
||||||
void MAX31865::begin(max31865_numwires_t wires, float zero, float ref) {
|
void MAX31865::begin(max31865_numwires_t wires, float zero, float ref) {
|
||||||
Rzero = zero;
|
zeroRes = zero;
|
||||||
Rref = ref;
|
refRes = ref;
|
||||||
|
|
||||||
OUT_WRITE(_cs, HIGH);
|
OUT_WRITE(cselPin, HIGH);
|
||||||
|
|
||||||
if (_sclk != TERN(LARGE_PINMAP, -1UL, -1)) {
|
if (sclkPin != TERN(LARGE_PINMAP, -1UL, -1)) {
|
||||||
softSpiBegin(SPI_QUARTER_SPEED); // Define pin modes for Software SPI
|
softSpiBegin(SPI_QUARTER_SPEED); // Define pin modes for Software SPI
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -162,10 +162,10 @@ void MAX31865::begin(max31865_numwires_t wires, float zero, float ref) {
|
||||||
#ifdef MAX31865_DEBUG_SPI
|
#ifdef MAX31865_DEBUG_SPI
|
||||||
SERIAL_ECHOLNPGM(
|
SERIAL_ECHOLNPGM(
|
||||||
TERN(LARGE_PINMAP, "LARGE_PINMAP", "Regular")
|
TERN(LARGE_PINMAP, "LARGE_PINMAP", "Regular")
|
||||||
" begin call with _cs: ", _cs,
|
" begin call with cselPin: ", cselPin,
|
||||||
" _miso: ", _miso,
|
" misoPin: ", misoPin,
|
||||||
" _sclk: ", _sclk,
|
" sclkPin: ", sclkPin,
|
||||||
" _mosi: ", _mosi,
|
" mosiPin: ", mosiPin,
|
||||||
" config: ", readRegister8(MAX31865_CONFIG_REG)
|
" config: ", readRegister8(MAX31865_CONFIG_REG)
|
||||||
);
|
);
|
||||||
#endif
|
#endif
|
||||||
|
@ -282,8 +282,8 @@ uint16_t MAX31865::readRaw() {
|
||||||
*/
|
*/
|
||||||
float MAX31865::readResistance() {
|
float MAX31865::readResistance() {
|
||||||
// Strip the error bit (D0) and convert to a float ratio.
|
// Strip the error bit (D0) and convert to a float ratio.
|
||||||
// less precise method: (readRaw() * Rref) >> 16
|
// less precise method: (readRaw() * refRes) >> 16
|
||||||
return (((readRaw() >> 1) / 32768.0f) * Rref);
|
return (((readRaw() >> 1) / 32768.0f) * refRes);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -300,8 +300,8 @@ float MAX31865::temperature() {
|
||||||
*
|
*
|
||||||
* @return Temperature in C
|
* @return Temperature in C
|
||||||
*/
|
*/
|
||||||
float MAX31865::temperature(uint16_t adcVal) {
|
float MAX31865::temperature(uint16_t adc_val) {
|
||||||
return temperature(((adcVal) / 32768.0f) * Rref);
|
return temperature(((adc_val) / 32768.0f) * refRes);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -309,11 +309,11 @@ float MAX31865::temperature(uint16_t adcVal) {
|
||||||
* Uses the technique outlined in this PDF:
|
* Uses the technique outlined in this PDF:
|
||||||
* http://www.analog.com/media/en/technical-documentation/application-notes/AN709_0.pdf
|
* http://www.analog.com/media/en/technical-documentation/application-notes/AN709_0.pdf
|
||||||
*
|
*
|
||||||
* @param Rrtd the resistance value in ohms
|
* @param rtd_res the resistance value in ohms
|
||||||
* @return the temperature in degC
|
* @return the temperature in degC
|
||||||
*/
|
*/
|
||||||
float MAX31865::temperature(float Rrtd) {
|
float MAX31865::temperature(float rtd_res) {
|
||||||
float temp = (RTD_Z1 + sqrt(RTD_Z2 + (RTD_Z3 * Rrtd))) / RTD_Z4;
|
float temp = (RTD_Z1 + sqrt(RTD_Z2 + (RTD_Z3 * rtd_res))) * RECIPROCAL(RTD_Z4);
|
||||||
|
|
||||||
// From the PDF...
|
// From the PDF...
|
||||||
//
|
//
|
||||||
|
@ -324,17 +324,17 @@ float MAX31865::temperature(float Rrtd) {
|
||||||
// of resistance.
|
// of resistance.
|
||||||
//
|
//
|
||||||
if (temp < 0) {
|
if (temp < 0) {
|
||||||
Rrtd = (Rrtd / Rzero) * 100; // normalize to 100 ohm
|
rtd_res = (rtd_res / zeroRes) * 100; // normalize to 100 ohm
|
||||||
float rpoly = Rrtd;
|
float rpoly = rtd_res;
|
||||||
|
|
||||||
temp = -242.02 + (2.2228 * rpoly);
|
temp = -242.02 + (2.2228 * rpoly);
|
||||||
rpoly *= Rrtd; // square
|
rpoly *= rtd_res; // square
|
||||||
temp += 2.5859e-3 * rpoly;
|
temp += 2.5859e-3 * rpoly;
|
||||||
rpoly *= Rrtd; // ^3
|
rpoly *= rtd_res; // ^3
|
||||||
temp -= 4.8260e-6 * rpoly;
|
temp -= 4.8260e-6 * rpoly;
|
||||||
rpoly *= Rrtd; // ^4
|
rpoly *= rtd_res; // ^4
|
||||||
temp -= 2.8183e-8 * rpoly;
|
temp -= 2.8183e-8 * rpoly;
|
||||||
rpoly *= Rrtd; // ^5
|
rpoly *= rtd_res; // ^5
|
||||||
temp += 1.5243e-10 * rpoly;
|
temp += 1.5243e-10 * rpoly;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -399,15 +399,15 @@ uint16_t MAX31865::readRegister16(uint8_t addr) {
|
||||||
*/
|
*/
|
||||||
void MAX31865::readRegisterN(uint8_t addr, uint8_t buffer[], uint8_t n) {
|
void MAX31865::readRegisterN(uint8_t addr, uint8_t buffer[], uint8_t n) {
|
||||||
addr &= 0x7F; // make sure top bit is not set
|
addr &= 0x7F; // make sure top bit is not set
|
||||||
if (_sclk == TERN(LARGE_PINMAP, -1UL, -1))
|
if (sclkPin == TERN(LARGE_PINMAP, -1UL, -1))
|
||||||
SPI.beginTransaction(spiConfig);
|
SPI.beginTransaction(spiConfig);
|
||||||
else
|
else
|
||||||
WRITE(_sclk, LOW);
|
WRITE(sclkPin, LOW);
|
||||||
|
|
||||||
WRITE(_cs, LOW);
|
WRITE(cselPin, LOW);
|
||||||
|
|
||||||
#ifdef TARGET_LPC1768
|
#ifdef TARGET_LPC1768
|
||||||
DELAY_CYCLES(_spi_speed);
|
DELAY_CYCLES(spiSpeed);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
spiTransfer(addr);
|
spiTransfer(addr);
|
||||||
|
@ -420,10 +420,10 @@ void MAX31865::readRegisterN(uint8_t addr, uint8_t buffer[], uint8_t n) {
|
||||||
buffer++;
|
buffer++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_sclk == TERN(LARGE_PINMAP, -1UL, -1))
|
if (sclkPin == TERN(LARGE_PINMAP, -1UL, -1))
|
||||||
SPI.endTransaction();
|
SPI.endTransaction();
|
||||||
|
|
||||||
WRITE(_cs, HIGH);
|
WRITE(cselPin, HIGH);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -433,24 +433,24 @@ void MAX31865::readRegisterN(uint8_t addr, uint8_t buffer[], uint8_t n) {
|
||||||
* @param data the data to write
|
* @param data the data to write
|
||||||
*/
|
*/
|
||||||
void MAX31865::writeRegister8(uint8_t addr, uint8_t data) {
|
void MAX31865::writeRegister8(uint8_t addr, uint8_t data) {
|
||||||
if (_sclk == TERN(LARGE_PINMAP, -1UL, -1))
|
if (sclkPin == TERN(LARGE_PINMAP, -1UL, -1))
|
||||||
SPI.beginTransaction(spiConfig);
|
SPI.beginTransaction(spiConfig);
|
||||||
else
|
else
|
||||||
WRITE(_sclk, LOW);
|
WRITE(sclkPin, LOW);
|
||||||
|
|
||||||
WRITE(_cs, LOW);
|
WRITE(cselPin, LOW);
|
||||||
|
|
||||||
#ifdef TARGET_LPC1768
|
#ifdef TARGET_LPC1768
|
||||||
DELAY_CYCLES(_spi_speed);
|
DELAY_CYCLES(spiSpeed);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
spiTransfer(addr | 0x80); // make sure top bit is set
|
spiTransfer(addr | 0x80); // make sure top bit is set
|
||||||
spiTransfer(data);
|
spiTransfer(data);
|
||||||
|
|
||||||
if (_sclk == TERN(LARGE_PINMAP, -1UL, -1))
|
if (sclkPin == TERN(LARGE_PINMAP, -1UL, -1))
|
||||||
SPI.endTransaction();
|
SPI.endTransaction();
|
||||||
|
|
||||||
WRITE(_cs, HIGH);
|
WRITE(cselPin, HIGH);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -463,19 +463,19 @@ void MAX31865::writeRegister8(uint8_t addr, uint8_t data) {
|
||||||
* @return the 8-bit response
|
* @return the 8-bit response
|
||||||
*/
|
*/
|
||||||
uint8_t MAX31865::spiTransfer(uint8_t x) {
|
uint8_t MAX31865::spiTransfer(uint8_t x) {
|
||||||
if (_sclk == TERN(LARGE_PINMAP, -1UL, -1))
|
if (sclkPin == TERN(LARGE_PINMAP, -1UL, -1))
|
||||||
return SPI.transfer(x);
|
return SPI.transfer(x);
|
||||||
|
|
||||||
#ifdef TARGET_LPC1768
|
#ifdef TARGET_LPC1768
|
||||||
return swSpiTransfer(x, _spi_speed, _sclk, _miso, _mosi);
|
return swSpiTransfer(x, spiSpeed, sclkPin, misoPin, mosiPin);
|
||||||
#else
|
#else
|
||||||
uint8_t reply = 0;
|
uint8_t reply = 0;
|
||||||
for (int i = 7; i >= 0; i--) {
|
for (int i = 7; i >= 0; i--) {
|
||||||
WRITE(_sclk, HIGH); DELAY_NS_VAR(_spi_delay);
|
WRITE(sclkPin, HIGH); DELAY_NS_VAR(spiDelay);
|
||||||
reply <<= 1;
|
reply <<= 1;
|
||||||
WRITE(_mosi, x & _BV(i)); DELAY_NS_VAR(_spi_delay);
|
WRITE(mosiPin, x & _BV(i)); DELAY_NS_VAR(spiDelay);
|
||||||
if (READ(_miso)) reply |= 1;
|
if (READ(misoPin)) reply |= 1;
|
||||||
WRITE(_sclk, LOW); DELAY_NS_VAR(_spi_delay);
|
WRITE(sclkPin, LOW); DELAY_NS_VAR(spiDelay);
|
||||||
}
|
}
|
||||||
return reply;
|
return reply;
|
||||||
#endif
|
#endif
|
||||||
|
@ -486,13 +486,13 @@ void MAX31865::softSpiBegin(const uint8_t spi_speed) {
|
||||||
SERIAL_ECHOLNPGM("Initializing MAX31865 Software SPI");
|
SERIAL_ECHOLNPGM("Initializing MAX31865 Software SPI");
|
||||||
#endif
|
#endif
|
||||||
#ifdef TARGET_LPC1768
|
#ifdef TARGET_LPC1768
|
||||||
swSpiBegin(_sclk, _miso, _mosi);
|
swSpiBegin(sclkPin, misoPin, mosiPin);
|
||||||
_spi_speed = swSpiInit(spi_speed, _sclk, _mosi);
|
spiSpeed = swSpiInit(spi_speed, sclkPin, mosiPin);
|
||||||
#else
|
#else
|
||||||
_spi_delay = (100UL << spi_speed) / 3; // Calculate delay in ns. Top speed is ~10MHz, or 100ns delay between bits.
|
spiDelay = (100UL << spi_speed) / 3; // Calculate delay in ns. Top speed is ~10MHz, or 100ns delay between bits.
|
||||||
OUT_WRITE(_sclk, LOW);
|
OUT_WRITE(sclkPin, LOW);
|
||||||
SET_OUTPUT(_mosi);
|
SET_OUTPUT(mosiPin);
|
||||||
SET_INPUT(_miso);
|
SET_INPUT(misoPin);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -89,15 +89,15 @@ class MAX31865 {
|
||||||
private:
|
private:
|
||||||
static SPISettings spiConfig;
|
static SPISettings spiConfig;
|
||||||
|
|
||||||
TERN(LARGE_PINMAP, uint32_t, uint8_t) _sclk, _miso, _mosi, _cs;
|
TERN(LARGE_PINMAP, uint32_t, uint8_t) sclkPin, misoPin, mosiPin, cselPin;
|
||||||
|
|
||||||
#ifdef TARGET_LPC1768
|
#ifdef TARGET_LPC1768
|
||||||
uint8_t _spi_speed;
|
uint8_t spiSpeed;
|
||||||
#else
|
#else
|
||||||
uint16_t _spi_delay;
|
uint16_t spiDelay;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
float Rzero, Rref;
|
float zeroRes, refRes;
|
||||||
|
|
||||||
void setConfig(uint8_t config, bool enable);
|
void setConfig(uint8_t config, bool enable);
|
||||||
|
|
||||||
|
@ -135,6 +135,6 @@ public:
|
||||||
uint16_t readRaw();
|
uint16_t readRaw();
|
||||||
float readResistance();
|
float readResistance();
|
||||||
float temperature();
|
float temperature();
|
||||||
float temperature(uint16_t adcVal);
|
float temperature(uint16_t adc_val);
|
||||||
float temperature(float Rrtd);
|
float temperature(float rtd_res);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue