Hi Martin
sorry just in time not, i do not program in arduino ide just in time, i use xtensa and other for a contract labor, sorry.
but there is not need to puzzle about this:
simple use Interrupts for SDA/SCL and check the Status signals.
if you have a fired SDA ISR, check the START,
Code: Select all
if (SCL)..// if SCL is high, yeah you have a Start, else was a false trigger..
then receive the 8 bits..
check here, that you allways be in Start mode
if SDA changed while SCL is hig, its a stop, or start ( high to low )
then you can check the addr for match
btw
you can do here a multi communication with the slave by again sending a Start and send commands.. ect..
for processing commands at ESP..
Code: Select all
..
if (( ret & 0xfffe ) != I2C_Slave_Address) break;
..
if addr matched, then you can read the LBit for read/write command.
Code: Select all
..
if ( ret & 1 ) // we have a read from slave by the master
ret = sendyourdata();
else
ret = recvyourdata();
..
// don't forget to enable the ISR again..
enable_ISR..
if we have a Read, then slave send data whilest Master request it
if we have a Write, then slave receive byte whilest slave send Nack.
have a look to the flow too:
btw, here is the esp in action,
we have one esp 8266 as master, one esp 8266 as slave.
atmega 2560 r3 runs in multi master mode ..
i programm in GUI IDE, the same for atmega 2560.
this is pre status for next theme : CAN & eMbHome
we can now do working in CAN, Modbus ... and all other.
sure, after the i2c theme is ready in MARS with gcc , i can share the knowledge too, there is no wisper need about this.
the fact is the interrupting must done well, so check the isr and do not forgett to clear the status after fired.
i allways first make code in GUI IDE then Xtensa and then gcc ( mars ), think for gcc/mars arduino ide the code gets next week a revision. i will investigate next week in the arduino github like you linked.
hope this helps
best wishes
rudi
