Skip to content

Enumerate the I2C bus #722

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 66 additions & 14 deletions Firmware/RTK_Surveyor/Begin.ino
Original file line number Diff line number Diff line change
Expand Up @@ -1239,25 +1239,77 @@ void beginI2C()
// Assign I2C interrupts to the core that started the task. See: https://github.com/espressif/arduino-esp32/issues/3386
void pinI2CTask(void *pvParameters)
{
bool i2cBusAvailable;
uint32_t timer;

Wire.begin(); // Start I2C on core the core that was chosen when the task was started
// Wire.setClock(400000);

// begin/end wire transmission to see if bus is responding correctly
// All good: 0ms, response 2
// SDA/SCL shorted: 1000ms timeout, response 5
// SCL/VCC shorted: 14ms, response 5
// SCL/GND shorted: 1000ms, response 5
// SDA/VCC shorted: 1000ms, reponse 5
// SDA/GND shorted: 14ms, response 5
Wire.beginTransmission(0x15); // Dummy address
int endValue = Wire.endTransmission();
if (endValue == 2)
online.i2c = true;
else
systemPrintln("Error: I2C Bus Not Responding");
// Display the device addresses
i2cBusAvailable = false;
for (uint8_t addr = 0; addr < 127; addr++)
{
// begin/end wire transmission to see if the bus is responding correctly
// All good: 0ms, response 2
// SDA/SCL shorted: 1000ms timeout, response 5
// SCL/VCC shorted: 14ms, response 5
// SCL/GND shorted: 1000ms, response 5
// SDA/VCC shorted: 1000ms, response 5
// SDA/GND shorted: 14ms, response 5
timer = millis();
Wire.beginTransmission(addr);
if (Wire.endTransmission() == 0)
{
i2cBusAvailable = true;
switch (addr)
{
default: {
systemPrintf("0x%02x\r\n", addr);
break;
}

i2cPinned = true;
case 0x19: {
systemPrintf("0x%02x - LIS2DH12 Accelerometer\r\n", addr);
break;
}

case 0x36: {
systemPrintf("0x%02x - MAX17048 Fuel Guage\r\n", addr);
break;
}

case 0x3d: {
systemPrintf("0x%02x - SSD1306 (64x48) OLED Driver\r\n", addr);
break;
}

case 0x42: {
systemPrintf("0x%02x - u-blox ZED-F9P GNSS Receiver\r\n", addr);
break;
}

case 0x43: {
systemPrintf("0x%02x - u-blox NEO-D9S-00B Correction Data Receiver\r\n", addr);
break;
}

case 0x60: {
systemPrintf("0x%02x - Crypto Coprocessor\r\n", addr);
break;
}
}
}
else if ((millis() - timer) > 3)
{
systemPrintln("Error: I2C Bus Not Responding");
i2cBusAvailable = false;
break;
}
}

// Update the I2C status
online.i2c = i2cBusAvailable;
i2cPinned = true;
vTaskDelete(nullptr); // Delete task once it has run once
}

Expand Down