[ESP8266] I2C_Demo

ESP_Faye
Posts: 1646
Joined: Mon Oct 27, 2014 11:08 am

[ESP8266] I2C_Demo

Postby ESP_Faye » Thu May 26, 2016 11:47 am

I2C_Demo_For_ESP8266_NONOS_SDK.zip
(395.14 KiB) Downloaded 3157 times

I2C_Demo_For_ESP8266_NONOS_SDK is a demo about I2C based on ESP8266_NONOS_SDK.
If using ESP8266_NONOS_SDK_V1.5.0 or later version, please add "-lcrypto" in 'LINKFLAGS_eagle.app.v6" area of the Makefile.
I2C_Demo_For_ESP8266_NONOS_SDK 为基于 ESP8266_NONOS_SDK 的 I2C 应用的示例。
如果使用 ESP8266_NONOS_SDK_V1.5.0 或之后版本,请在示例的 Makefile 中 'LINKFLAGS_eagle.app.v6" 区域增加 "-lcrypto" 。

I2C_Demo_For_ESP8266_RTOS_SDK.zip
(2.81 KiB) Downloaded 1706 times

I2C_Demo_For_ESP8266_RTOS_SDK is a demo about I2C based on ESP8266_RTOS_SDK.
I2C_Demo_For_ESP8266_RTOS_SDK 为基于 ESP8266_RTOS_SDK 的 I2C 应用的示例。

Thanks for your interest in ESP8266 !

scargill
Posts: 70
Joined: Sun Nov 02, 2014 8:09 pm

Re: [ESP8266] I2C_Demo

Postby scargill » Tue Jul 19, 2016 12:33 am

Call me slow but I came looking for an example of I2c - and there's a NONOS file - with everything BUT an example of I2c - am I missing something?

I'm having trouble - I have an ESP8266 talking to Arduino. The ESP can send multiple bytes to the Arduino - no problem - but I haven't a clue how to get multiple bytes back into the ESP. Repeated reads causes the ESP to crash so clearly I'm missing somebut I can't find anything out there - examples of using the SDK code for communications - indeed there aren't even any examples in the SDK.

Anyone familiar with this scenario??

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

Re: [ESP8266] I2C_Demo

Postby rudi » Wed Jul 20, 2016 7:58 am

scargill wrote:
..
I'm having trouble - I have an ESP8266 talking to Arduino.


hi pete, i understand you so , you use
ESP8266 as I2C Master
Arduino as I2C Slave
ok?
scargill wrote:
The ESP can send multiple bytes to the Arduino - no problem -
but I haven't a clue how to get multiple bytes back into the ESP.

so , do this:
you pulse the clk by esp8266 as master to the arduino and read the input on esp8266 sda what the i2c slave arduino send.

scargill wrote:Repeated reads causes the ESP to crash so clearly I'm missing somebut I can't find anything out there - examples of using the SDK code for communications - indeed there aren't even any examples in the SDK.

Anyone familiar with this scenario??


pete, you must study first I2C Master and I2C Slave
there are ACK, NACK, LAST, Status, Start, Stop, ISR SDA, ISR CLK, Master Send, Slave Send..

example here is a I2C Slave

I2C_ESP_Slave.PNG


in the follow, there is a I2C Master ( ESP8266 ) and a I2C Slave ( ESP8266 ) ..
read in..
have a look into this thread
and study this

and here you can watch an example
I2C Slave is done in the past.

perhabs it helps to understand, how you must code the arduino ( I2C Slave )
that you can read by the Master ( ESP8266 ) from the Slave ( Arduino )
The SDA is the own pin for Master send and for Slave receive
also , for Slave send, and Master receive.
The direction is in the I2C standard protokol described






hope this helps.

best wishes
rudi ;-)

edit:
NONOS: read i2c_master.h
there are all your friends here what you need for read from Arduino,
you must code Arduino in the Arduino IDE as Slave with an address,
and this you send by ESP8266 as I2C Master to the Arduino,
and then you can read by the Master..:


Code: Select all


void i2c_master_gpio_init(void);
void i2c_master_init(void);

void i2c_master_start(void);
void i2c_master_stop(void);

void i2c_master_setAck(uint8 level);
uint8 i2c_master_getAck(void);

uint8 i2c_master_readByte(void);
void i2c_master_writeByte(uint8 wrdata);

bool i2c_master_checkAck(void);
void i2c_master_send_ack(void);
void i2c_master_send_nack(void);



you must study I2C protokoll first, so you see the tree in the jungle what you search for :P

you start with a start by the master,
that do the sda low and then comes the clk
this is the begin of the protokoll,
"see start condition"
(if you do this with multi masters then you must check before, that bus is free with a check for SDA is high example..)
with a SDA low you signal in the bus, that you are will send data now.
after this , the bus is yours.

next ist the write byte,
you send the 7bit adress and shift in your command , want read << 1 or want write << 0
the slave check this
- address matching
- its a read or write

Code: Select all

if ( Address & 1 ).. 


example a read,

then slave put the bits on at sda on each clk pulse ( 8 bits= 1 byte )
this is done, if the master reads a byte, because only the master can pulse the clk..
so
edit ( for better understanding )
the master read a Byte and on 9. clk cykle gives a ACK or NACK for the LAST

Code: Select all

i2c_master_send_ack(void);


and the slave send data whilest the Master request it




// btw slave code..
/ edit

Code: Select all


LAST = i2c_ArduinoSlave_TxByte(data);
while ( LAST == 0 )
// ACK = 0, NACK = 1
 


here you go on detailed:

proto.png


read here, take this:
http://www.ti.com/lit/an/slva704/slva704.pdf

and read carefull opendrain config

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

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

Re: [ESP8266] I2C_Demo

Postby rudi » Sat Jul 23, 2016 9:41 pm

pete,
have a look to elliot's post at hackaday
excelent infos about the ACK, NACK, 7 bit address and so on.
where you hang? what is the detailed problem?
how looks your arduino code?

best wishes
rudi ;-)

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

Who is online

Users browsing this forum: No registered users and 1 guest