-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Open
Labels
Resolution: Unable to reproduceWith given information issue is unable to reproduceWith given information issue is unable to reproduce
Description
Board
ESP32 Pico Kit V4.1
Device Description
arduino-esp32/libraries/SPI/src/SPI.cpp
Line 136 in c2e6a30
void SPIClass::setHwCs(bool use) { |
This function does not work. What is the correct usage
Hardware Configuration
ICM42688 IMU connected to pins 19,23,18,5.
Version
v3.3.1
Type
Bug
IDE Name
Arduino Ide
Operating System
Windows 11
Flash frequency
40Mhz
PSRAM enabled
no
Upload speed
115200
Description
The sketch works when manually toggling the CS pin.
Sketch
++
#include <Arduino.h>
#include <SPI.h>
const int CS_PIN = 5;
const uint8_t REG_WHO_AM_I = 0x75;
const uint8_t EXPECTED_WHO = 0x47;
const uint8_t REG_PWR_MGMT0 = 0x4E;
const uint8_t PWR_MGMT_WAKE = 0x0F;
const uint8_t REG_DATA_START = 0x1D;
const uint8_t DATA_LEN = 14;
uint8_t spiReadRegister(uint8_t reg)
{
uint8_t val = 0;
SPI.beginTransaction(SPISettings(2000000, MSBFIRST, SPI_MODE0));
SPI.transfer(reg | 0x80);
val = SPI.transfer(0x00);
SPI.endTransaction();
return val;
}
bool spiWriteRegister(uint8_t reg, uint8_t value)
{
SPI.beginTransaction(SPISettings(2000000, MSBFIRST, SPI_MODE0));
SPI.transfer(reg & 0x7F);
SPI.transfer(value);
SPI.endTransaction();
return true;
}
bool spiReadBurst(uint8_t startReg, uint8_t *buf, uint8_t len)
{
SPI.beginTransaction(SPISettings(2000000, MSBFIRST, SPI_MODE0));
SPI.transfer(startReg | 0x80);
for (uint8_t i = 0; i < len; i++)
{
buf[i] = SPI.transfer(0x00);
}
SPI.endTransaction();
return true;
}
int16_t toSigned16(uint8_t hi, uint8_t lo)
{
return (int16_t)((hi << 8) | lo);
}
void setup()
{
Serial.begin(115200);
delay(200);
SPI.begin();
SPI.setHwCs(true);
delay(10);
Serial.println("ICM-42688 SPI hw-CS test");
uint8_t who = spiReadRegister(REG_WHO_AM_I);
Serial.printf("WHO_AM_I = 0x%02X (expected 0x%02X)\n", who, EXPECTED_WHO);
spiWriteRegister(REG_PWR_MGMT0, PWR_MGMT_WAKE);
delay(20);
}
void loop()
{
uint8_t buf[DATA_LEN];
spiReadBurst(REG_DATA_START, buf, DATA_LEN);
int16_t temp_raw = toSigned16(buf[0], buf[1]);
int16_t ax_raw = toSigned16(buf[2], buf[3]);
int16_t ay_raw = toSigned16(buf[4], buf[5]);
int16_t az_raw = toSigned16(buf[6], buf[7]);
int16_t gx_raw = toSigned16(buf[8], buf[9]);
int16_t gy_raw = toSigned16(buf[10], buf[11]);
int16_t gz_raw = toSigned16(buf[12], buf[13]);
Serial.printf("TEMP=%d | ACC=%d,%d,%d | GYRO=%d,%d,%d\n",
temp_raw, ax_raw, ay_raw, az_raw, gx_raw, gy_raw, gz_raw);
delay(200);
}
Debug Message
No error on console
Other Steps to Reproduce
No response
I have checked existing issues, online documentation and the Troubleshooting Guide
- I confirm I have checked existing issues, online documentation and Troubleshooting guide.
Metadata
Metadata
Assignees
Labels
Resolution: Unable to reproduceWith given information issue is unable to reproduceWith given information issue is unable to reproduce