I am trying to read RTD with MCP3551 over SPI...
Can anyone please guide me regarding any available resource for communication between ESP32 and MCP3551...
I have seen mcp3551.h file in man examples but now can't locate this file on entire google i have searched...
Will be obliged if someone can share this file to me, since there are demo examples available with this library which i can try....
Also if someone can give reference code for other 22/24 bit ADC over SPI with ESP32 then will be great guide....
rohimo:
I am trying to read RTD with MCP3551 over SPI...
Can anyone please guide me regarding any available resource for communication between ESP32 and MCP3551...
I have seen mcp3551.h file in man examples but now can't locate this file on entire google i have searched...
Will be obliged if someone can share this file to me, since there are demo examples available with this library which i can try....
Also if someone can give reference code for other 22/24 bit ADC over SPI with ESP32 then will be great guide....
You don't really need a library for this.
Looking at the datasheet probably something like this could work:
(compiles but not tested!!!)
#include "SPI.h"
union {
int32_t val;
uint8_t bytes[4];
} conv;
void setup() {
Serial.begin(115200);
//Initialise SPI interface
//SPI clock speed:5MHz, Data Shift:MSB First, Data Clock Idle: SPI_MODE3 (Mode 1,1)
SPI.beginTransaction(SPISettings(5000000, MSBFIRST, SPI_MODE3));
digitalWrite(SS, HIGH); //set CS pin HIGH (using board's default SPI SS pin)
Serial.println("MCP3551 Single Conversion Example...");
}
void loop() {
//Start conversion
digitalWrite(SS, LOW); //set CS pin LOW
delayMicroseconds(1);
digitalWrite(SS, HIGH); //set CS pin HIGH
//wait for conversion to complete
delayMicroseconds(1);
digitalWrite(SS, LOW); //set CS pin LOW
while (digitalRead(MISO)); //wait for SDO/RDY to go low
//read data
conv.bytes[2] = SPI.transfer(0x00);
conv.bytes[1] = SPI.transfer(0x00);
conv.bytes[0] = SPI.transfer(0x00);
digitalWrite(SS, HIGH); //set CS pin HIGH
//check if conversion value is negative. adjust bytes[2] and bytes[3] accordingly
if ( (conv.bytes[2] & 0x08 == 0x08) || ((conv.bytes[2] & 0x02 == 0x02) && (conv.bytes[2] & 0x04 == 0)) ) {
conv.bytes[2] |= 0xC0; //bits 23-22 masked
conv.bytes[3] = 0xFF;
}
else {
conv.bytes[2] &= 0x3F; //bits 23-22 masked
conv.bytes[3] = 0;
}
//print out data
Serial.print("Overflow HIGH (OVH): ");
if (conv.bytes[2] & 0x04 == 0x04) Serial.println("1");
else Serial.println("0");
Serial.print("Overflow LOW (OVL): ");
if (conv.bytes[2] & 0x08 == 0x08) Serial.println("1");
else Serial.println("0");
Serial.print("Conversion value: ");
Serial.println(conv.val, DEC);
delay(1000); // Abitrary delay value for loop
}