I2C Slave Mode

User avatar
rudi
Posts: 197
Joined: Fri Oct 24, 2014 7:55 pm

I2C Slave Mode

Postby rudi » Tue Apr 26, 2016 11:51 am

Hi

do we have I2C Slave Mode example / document?

try just in Time to go on with Master Mode ( run like a dream ) and now i try a I2C Slave mode.

Because i2c_master api used the clock ( CLK ) we can not used this for a SLAVE,
because Only Master generated CLK .

Own API and Docu for I2C Slave would be fine.

thanks
best wishes
rudi ;-)
Last edited by rudi on Sun Jul 24, 2016 8:29 am, edited 1 time in total.

-------------------------------------
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪

User avatar
rudi
Posts: 197
Joined: Fri Oct 24, 2014 7:55 pm

Re: I2C Slave Mode

Postby rudi » Thu Apr 28, 2016 9:33 am

update:

started successful in
I2C_Slave_ESP8266.png


used the master code and changed simply from clocking to listen the master generated clock
an ISR on SDA gives me the START signal for checking HIGH SCL
hope this helps for other who are searched the same.

solved!
here are working just in time 2 esp8266 and one esp32beta ,
one 8266 as master the seconds as slaves.
they are work at standard 50kHz and 120 kHz stable, 250 and 400 kHz sometimes spikes,
but i am sure, this are my pullup resistors. will test next time signal capazity and tune the pullups better.

i2c slave
done! ;-)

now i have all. this part was the last missing here.

best wishes
rudi ;-)

-------------------------------------
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪

User avatar
martinayotte
Posts: 10
Joined: Tue Nov 04, 2014 4:33 am

Re: I2C Slave Mode

Postby martinayotte » Fri Apr 29, 2016 11:29 pm

Hi Rudi,
Would you mind sharing this code ?
Maybe you can even submit a PR to https://github.com/esp8266/Arduino ?

User avatar
rudi
Posts: 197
Joined: Fri Oct 24, 2014 7:55 pm

Re: I2C Slave Mode

Postby rudi » Wed May 04, 2016 7:37 am

martinayotte wrote:Hi Rudi,
Would you mind sharing this code ?
Maybe you can even submit a PR to https://github.com/esp8266/Arduino ?


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:

I2C_ESP_Slave.PNG



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.

IMG_5070.JPG


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 ;-)
Last edited by rudi on Wed Jul 20, 2016 5:00 pm, edited 2 times in total.

-------------------------------------
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪

User avatar
rudi
Posts: 197
Joined: Fri Oct 24, 2014 7:55 pm

Re: I2C Slave Mode

Postby rudi » Sat May 14, 2016 11:26 am

hi

as promised, here first the ESP8266 I2C Slave video

EDIT: will update the video with a better project

best wishes
rudi ;-)

done!
Last edited by rudi on Sun Jul 24, 2016 8:30 am, edited 1 time in total.

-------------------------------------
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪

ESP_Stanza
Posts: 11
Joined: Fri Oct 31, 2014 9:10 pm

Re: I2C Slave Mode

Postby ESP_Stanza » Sun May 15, 2016 9:36 pm

That's great!
Thank you, Rudi.

User avatar
martinayotte
Posts: 10
Joined: Tue Nov 04, 2014 4:33 am

Re: I2C Slave Mode

Postby martinayotte » Tue Jul 05, 2016 3:50 am

Hi Rudy,

Did you got chance to prepare your I2C Slave code to make it published ?

Thanks in advance,
Martin.

User avatar
rudi
Posts: 197
Joined: Fri Oct 24, 2014 7:55 pm

Re: I2C Slave Mode

Postby rudi » Wed Jul 06, 2016 5:42 am

hi martin,

how are you, hope u're fine.

just in time work[hurry] on finnsih CAN and Modbus ( esp8266 & esp32 ) this week, and weekend video for this for yt, because we are next week in holiday, but back to your question, yes, if you ( community ) does not have a solution after come back, will try to post a small project - that arduino community can transfer to the ide, hope this helps? ( perhabs igrr named me :P would make proud )

important things are short:
-GPIO must be configured as OpenDrain
-ISR on all two's, SDA and SCL
-debug prints with os_printf_plus ( better no print out in the isr )

btw, SPI Slave ( SDIO too ) is done too.
we can work with full HW speed between esp's now. have a nice project with this on hand just in time, be surprised! this is fun project - but this comes with esp32 start - earliest - need the BLE for the fun..

i am honest:
the i2c slave theme was the simplest but hardest too for me personally, my mistake was allways in the OpenDrain config,
and the right ACK / NACK - do not only do gpio(low/high) - we need to set/clear the pin ( opendrain ) ..but this you know by self better - but i have missed few bits for this and tried tried and tried..

i will come back to the theme here by self later and post
perhabs is a good idea to make a small creative I2C project and a pdf for it,
so perhabs espressif(stanza) can append this to the technical docu too, let me work on this,
think this is a good way for all?..and the last theme is documented with an example.

best wishes!
rudi ;-)

-------------------------------------
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪

User avatar
martinayotte
Posts: 10
Joined: Tue Nov 04, 2014 4:33 am

Re: I2C Slave Mode

Postby martinayotte » Fri Jul 08, 2016 8:33 pm

Thanks Rudy,
I will be glad to do some tests and example when things will get ready.
Ciao !

Jeisonas

Re: I2C Slave Mode

Postby Jeisonas » Sat Jul 09, 2016 11:30 pm

Rudi, this looks very exciting! I would be very grateful if you could share the library, because there is currently no proper way of running an ESP as a slave apart from using UART.

Who is online

Users browsing this forum: No registered users and 1 guest