I had a wander through the code. The delay is used to ensure that the state of the data line, SDA
, is read or changed, half way through the clock pulse on the clock line, SCL
.
For example, to transmit a byte:
void SoftwareI2C::sendByte(uint8_t ucDta)
{
for(uint8_t i=0; i<8; ++i)
{
sdaSet((ucDta&0x80)!=0);
sclSet(HIGH);
tunedDelay(_half_bit_delay_us);
sclSet(LOW);
tunedDelay(_half_bit_delay_us);
ucDta <<= 1;
}
}
The SDA
line is raised or lowered, the SCL
line is raised, then a delay, then lowered then another delay, then the next data bit is processed. That’s pretty much all that’s needed.
It’s not PlatformIO, it’s AVR and non-AVR microcontrollers.
In your code, somewhere, add #define __AVR__
. Does that make any difference? Probably above where the header for the SoftwareI2C library is included.
Cheers,
Norm.