My questions:
Do I need to append R/W bit myself? ACK bit?
I assume I don’t need this and I don’t need to use shifted left addresses like 0x98? That is corrent?
Please confirm if i understand correctly:
Write command: address from datasheet: 0x98h, command: 0x3, data: 0x14 (See Figure 5)
Spark Code:
0x98>>1 is 0x4C, that is not the issue. Can you adjust code to correct_for_spark variation? Ignore address, it is working fine. You are saying transmitting is done differently in spark. I need it to fit datasheet. Arduino runs this fine
The Wire library works the same. It’s the low level STM32 I2C drivers that are different. They’re the basic out of the box drivers provided by ST and not very fancy. Until I finish my fresh DMA implementation I2C is going to be a bit buggy and unstable. Make sure you give time for read and write operations to take place after your endTransmission call and you’ll generally be alright.
Do you have access to a Logic analyzer? A Bus Pirate or Raspberry Pi even? If so I’d log the I2C traffic from the Arduino and Core then compare the differences.
Can you just adjust actual real code please? I am not tech spec, I have no idea how it works on low level. That it why I am asking tech specialists for help.
“Add magic delay values to places” is not actually helping ^^’’ Some things you say sound total nonsence for me ^^’’. Like address thing or “give time for read and write operations to take place”. How I am supposed to give time to read operation? Like that?
b = Wire.read()
//here value of b is one value
delay(1)
//and here value of b can be different? Is read operation async?
I’ve located blocking code:
Wire.beginTransmission(_addr);
Wire.write(r);
uint8_t status = Wire.endTransmission(false);
delayMicroseconds(150);
if(status == 0) {
//IF CODE REACHES HERE SPARK DIES <-------
if(Wire.requestFrom(_addr, 1, true) == 1) {
uint8_t result = Wire.read();
return result;
};
}
return 0;
Once code goes to Wire.requestFrom(_addr, 1, true), Wire.read() - core reboots. Basically it reboots immediately after cloud connects.
Wire.beginTransmission(_addr);
Wire.write(r);
uint8_t status = Wire.endTransmission(false);
Works fine when no device is present on i2c line. So I check status and try to read only when status==0, meaning write has completed successfully and device present.
Now to interesting part. When I read spark dies. I expect that once i disconnect i2c device it wont do read operation and spark will recover. But it does not. Reading from Wire corrupts firmware?
I have a question: reading Spark variable and firing function works on interrupt? If yes, how can I prevent them from firing during time-sensitive processes?
I’ve updated gits http://gist.github.com/Ryotsuke/9100459 with working code.
But it stability rate is only 60% which is terribly low. Stability = successfull reads/all reads