megamoser,
I’m glad it works for now.
The Technical Reference Manual “27 SPI Controller(SPI)” especially “GP-SPI2” is helpful.
The ESP32 SPI is a bit different. Try VSPI at the link below, you may not need to change the MISO, MOSI, and SCLK pins.
megamoser,
I’m glad it works for now.
The Technical Reference Manual “27 SPI Controller(SPI)” especially “GP-SPI2” is helpful.
The ESP32 SPI is a bit different. Try VSPI at the link below, you may not need to change the MISO, MOSI, and SCLK pins.
I read the chip ID on the BMP388. I was able to read the ID without any problem with either regular SPI or VSPI.
#include <SPI.h>
#define CS D3
SPISettings settings(1000000, MSBFIRST, SPI_MODE0);
void setup() {
Serial.begin(115200);
while (!Serial);
Serial.println("Register Read TEST");
pinMode(CS, OUTPUT);
digitalWrite(CS, HIGH);
SPI.begin();
}
void loop() {
Serial.println("Send command...");
SPI.beginTransaction(settings);
digitalWrite(CS, LOW);
SPI.transfer(0x80); // BME388: 0x80 0x00
SPI.transfer(0x00);
Serial.println("Reading register...");
uint8_t readByte = SPI.transfer(0xFF);
digitalWrite(CS, HIGH);
SPI.endTransaction();
Serial.print("0x");
Serial.println(readByte, HEX);
delay(1000);
}
#include <SPI.h>
// XIAO ESP32C3 uses VSPI
#define VSPI_MISO MISO // D9
#define VSPI_MOSI MOSI // D10
#define VSPI_SCLK SCK // D8
#define VSPI_SS D3 // CS
#define VSPI FSPI
SPIClass * vspi = NULL;
void setup() {
Serial.begin(115200);
while (!Serial);
Serial.println("Register Read TEST");
vspi = new SPIClass(VSPI);
vspi->begin(VSPI_SCLK, VSPI_MISO, VSPI_MOSI, VSPI_SS); //SCLK, MISO, MOSI, CS
pinMode(vspi->pinSS(), OUTPUT); //VSPI CS
}
void loop() {
Serial.println("Send command...");
vspi->beginTransaction(SPISettings(1000000UL, MSBFIRST, SPI_MODE0));
digitalWrite(vspi->pinSS(), LOW);
vspi->transfer(0x80); // BME388: 0x80 0x00
vspi->transfer(0x00);
Serial.println("Reading register...");
uint8_t readByte = vspi->transfer(0xFF);
digitalWrite(vspi->pinSS(), HIGH);
vspi->endTransaction();
Serial.print("0x");
Serial.println(readByte, HEX);
delay(1000);
}