I thought I understood everything based on your comments, Stephen, but I’m having no success. I wonder if you’d have a look at my code?
Here’s the i2cScanner code from Arduino that I’m porting:
#include <Wire.h>
void setup()
{
Wire.begin();
Serial.begin(9600);
}
void loop()
{
Serial.println("Scanning...");
int nDevices = 0;
for(byte address = 1; address < 127; address++ )
{
Wire.beginTransmission(address);
byte error = Wire.endTransmission();
if (error == 0)
{
Serial.print("I2C device found at address 0x");
if (address<16) Serial.print("0");
Serial.print(address,HEX);
Serial.println(" !");
nDevices++;
}
}
if (nDevices == 0)
Serial.println("No I2C devices found\n");
else
Serial.println("done\n");
delay(5000); // wait 5 seconds for next scan
}
And the output (connected via A4/A5 to 3 daisy-chained (!) GPIO boards:
Scanning...
I2C device found at address 0x25 !
I2C device found at address 0x26 !
I2C device found at address 0x27 !
done
Here’s my libdaisy version:
#include "daisy_seed.h"
using namespace daisy;
int main(void)
{
static DaisySeed seed;
seed.Configure();
seed.Init();
seed.StartLog(false);
System::Delay(5000);
static constexpr I2CHandle::Config _i2c_config
= {I2CHandle::Config::Peripheral::I2C_1,
{{DSY_GPIOB, 8}, // SCL
{DSY_GPIOB, 9}}, // SDA
I2CHandle::Config::Speed::I2C_1MHZ};
I2CHandle _i2c;
_i2c.Init(_i2c_config);
seed.PrintLine("Scanning...");
int nDevices = 0;
for(unsigned char address = 1; address < 127; address++)
{
uint8_t testData = 0;
I2CHandle::Result i2cResult
= _i2c.TransmitBlocking(address, &testData, 1, 500);
if(i2cResult == I2CHandle::Result::OK)
{
int prAddress = (address < 16) ? 0 : address;
seed.PrintLine("I2C device found at address %x !", prAddress);
nDevices++;
}
}
if(nDevices == 0)
seed.PrintLine("No I2C devices found");
else
seed.PrintLine("done");
while(1) {}
}
And the output when the Seed is connected (pins 12/13 on the pinout):
Daisy is online
===============
Scanning...
No I2C devices found
I’ve tried it at 100KHz, 400KHz, 1MHz with the same result. I can tell that something is happening, because the code completes in 3-4 seconds; with no pin connections, it takes a bit over 60 seconds (as expected to scan 127 addresses with a 1/2 second timeout). I’m probably doing something dumb, but I’m not seeing it. Can you help? Thanks.