scargill wrote:..
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:
DevFexample, here comes a master example flowchart, done with the freeware GUI IDE DevF
simple generated code :
Code: Select all
// we include Headers here
#include <osapi.h>
#include <c_types.h>
#include <i2c_master.h>
// global vars
uint8 addr = 0x54;
uint8 cmdWrite = 0;
uint8 cmdRead = 1;
uint8 ACK = 0;
uint8 sendByte = 0;
uint32 counter()
{
static uint32 count = 0;
count++;
sendByte = count;
return count;
}
void i2c_talk()
{
i2c_master_start();
i2c_master_writeByte(addr+cmdWrite);
ACK = i2c_master_checkAck();
if (ACK)
{
os_printf("ACK ADDR True\n");
i2c_master_writeByte(sendByte);
}
else
{
os_printf("addr does not match\n");
}
i2c_master_stop();
}
void i2c_demo_init()
{
i2c_master_gpio_init();
os_delay_us(30 * 1000 );
i2c_master_init();
os_delay_us(30 * 1000 );
}
void user_init()
{
i2c_demo_init();
while (1)
{
os_printf("count: %d\n", counter() );
i2c_talk(sendByte);
system_soft_wdt_feed();
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
- esp8266/esp8285
- esp31b
- esp32
and copy the text file to the language folder.
the freeware support just in time:
- chinese
- english
- espanol
- francais
- polish
and later ( i am at work to translate )
- german
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 )