Surprised Espressif have not followed up on this and included in the SDK...
pete, i think - because it is a really simple protocoll (i2c) - we have docu about gpio, interrupts and we have the i2c_master, so we can build simple the i2c_slave by using the standard i2c RFC ( Slave )
but i agree with you, it really would be nice to have an i2c slave.c and .h file as we do for the masters -
but think over, the "player on i2c_slave" must study the i2c protocoll too, because there are steps need to hold on the protocoll rules.
the slave is only a talk member to the master, and does only, when
( clock ) and what
the master request. the begin for the slave is, to understand how to handle the master - so the slave can follow the instruction.
there must be a base understand for start and stop sequenze, ( SDA, SCL ) what happend on this and why.
what happend when master : i2c_master_start()
what happend when master : i2c_master_stop()
so we can setup the interrupt ( combine compare with SCL ) on SDA Pin for a START and other interrupt ( combine compare with SCL ) on SDA Pin for the STOP. this is a base understand.
the next interrupt is on the 8 bits DATA on SDA whilest not Stop, this is done 8 times, on 9 bit time slot the master read ACK/LAST example, this is base too. and vola - you have a i2c_slave.c and i2c_slave.h
the kitchen demo here i posted is only a user doing - when the i2c_slave is used.
the i2c base must be clear, how i2c works, then take the i2c docu, interrupt docu, gpio docu, i am sure - you finnish before i post the demo next time by self. its really easy.
i start with interrupts only on SDA first time, and make a while on SCL,
then i got the info between the reading lines , we must do on SDA + SCL
but i promissed, will post my i2c_slave.c and .h and the demo project next time.
edit: 4 August 2016
preinfo - what comes after the holdiay: DevF
example, here comes a master example flowchart, done with the freeware GUI IDE DevF
simple generated code :
Code: Select all
// we include Headers here
// global vars
uint8 addr = 0x54;
uint8 cmdWrite = 0;
uint8 cmdRead = 1;
uint8 ACK = 0;
uint8 sendByte = 0;
static uint32 count = 0;
sendByte = count;
ACK = i2c_master_checkAck();
os_printf("ACK ADDR True\n");
os_printf("addr does not match\n");
os_delay_us(30 * 1000 );
os_delay_us(30 * 1000 );
os_printf("count: %d\n", counter() );
os_delay_us(1 * 1000 * 1000);
for this, we need in project folder driver files from sdk:
-> driver / i2c_master.c
-> driver / include / i2c_master.h
and we can share the "sketch" simply with one project file ( likewise arduino )
we can export parts, we can import parts, we can share parts, we can work together on a project...
DevF Install is easy:
download the release project from the leader of the freeware at github to your desktop and expand.
you only must call one exe file for the ide - and make your setups/configs. it comes black to white.
so you can change all color/colour by your self like you like, this setups saved in the registry.
after this, download the language definition file for the esp serie from my github later:
there are then
and copy the text file to the language folder.
the freeware support just in time:
and later ( i am at work to translate )
links, esp repo, i2c slave and a small how to for start after the holiday.
we start step by step in this from scratch together.
please stand still patient
found my master just in time
and the stuff is great and freeware
( the same is build for the esp32 )