Hi, I am having issues with I2C data reading. The code stops at "Log_Debug(buf[i]);" with a "Segmentation fault occurred".
int main(void)
{
static int i2cFd = -1;
const uint8_t* buf[] = { 0, 0 };
Log_Debug("Loading\n");
i2cFd = I2CMaster_Open(2);
I2CMaster_SetDefaultTargetAddress(i2cFd, 10);
I2CMaster_SetBusSpeed(i2cFd, 100000);
I2CMaster_SetTimeout(i2cFd, 100);
/*if (i2cFd < 0) {
Log_Debug("ERROR: I2CMaster_Open: errno=%d (%s)\n", errno, strerror(errno));
return -1;
}*/
while (true) {
Log_Debug("Reading...\n");
I2CMaster_Read(i2cFd, 10, &buf, 2);
Log_Debug("Read returned: ");
for (int i = 0; i < 1; i++) {
Log_Debug(buf[i]);
}
Log_Debug("\n\n");
nanosleep(5000000000, NULL);
}
}
This is the console output:
Remote debugging from host 192.168.35.1 Loading Reading... Read returned:
I am using an arduino slave with this code as onRequest:
void onI2CRequest(int bytes) {
TinyWire.send(digitalRead(pin1));
TinyWire.send(digitalRead(pin2));
}
With an Arduino master data is read correctly.