Getting I2C on ESP8266 to work #5474
Replies: 1 comment
-
Posted at 2016-05-02 by @MaBecker The I2C test with an oled is only using i2c.writeTo(). Will do some tests with a I2C device that use i2c.readFrom(). Posted at 2016-05-02 by DrAzzy I2C.find() doesn't do what you think it does. See the reference If you need to search the I2C bus for devices, it's just a for loop and I2C1.readFrom() to implement it yourself... Or you could just consult the datasheet and find out what the address is that way. This works... (as of a few weeks ago, I've been swamped lately, no time to do anything on my project, but unless something got broken, this works).
I don't think bitrate/baudrate works on the ESP8266. Posted at 2016-05-02 by @MaBecker Tried i2cdetect code with a OLED attached at address 0x3c and limit scan to 0x30-0x3f Get fussy read results for adr <> 0x3c and lots of o no error for 0x3c - read value 65
Posted at 2016-05-07 by @MaBecker start investigating the source code Posted at 2016-05-08 by tve There is a section on I2C on the esp8266 page: http://www.espruino.com/EspruinoESP8266 Posted at 2016-05-08 by @MaBecker @tve - thanks
.... will check this with a logic analyzer Posted at 2016-05-09 by davem I ran into similar issue trying to get I2C working with the Wii Nunchuck.
Posted at 2016-05-10 by @MaBecker There are some implementation for clock stretching, eg: core_esp8266_si2c.c and Frida posted, that she has implemented clock stretching http://forum.espruino.com/comments/12973407/ Posted at 2016-05-11 by virtualcodewarrior I am still trying to make it work with my FM radio module. The wiring should be correct because when I flashed Mongoose IoT (formerly smart.js)
And have it work perfectly. On Espruino I used the following (hopefully) equivalent code :
Which results in
Can this have something to do with the lack of clock stretching ?? Posted at 2016-05-11 by @MaBecker I guess you use the WEBIDE and upload your code, so the time between writeTo and readFrom is different. To make it equivalent put your code in a function and use setTimeout() to call it. eg:
Posted at 2016-05-11 by Wilberforce Are the 4,5 above the same - does it refer to gpio # or PIN number, or board label? Perhaps try Posted at 2016-05-11 by Wilberforce @tve recommends these pins for the esp8266 https://gitter.im/espruino/Espruino?at=572c3c4612cceadb7b1b25db Just realised you are part of this thread.... Have you any other i2c device you can try other than the wii controller.... Posted at 2016-05-12 by virtualcodewarrior Looks like the I2C problem is specific to the radio module. A MCP23017 port expander that I connected to the same bus is recognized and works without problem. It is not a problem with the esp8266 because flashing different firmware makes it work. I will check the difference between the two firmwares next using a logic analyzer Posted at 2016-05-12 by virtualcodewarrior Looks like espruinos I2C is almost 10x faster than mongoose, maybe it is too fast for this module. Would now be nice if I could set the bitrate lower. Posted at 2016-05-12 by @gfwilliams
This could be the issue? AFAIK I2C devices generally don't mind going slow, but some of them really don't like higher clock speeds. Posted at 2016-05-13 by virtualcodewarrior Ok back to the drawing board, I slowed Espruino down to the same speed and even slower, but it made no difference. Hopefully I am learning something here ;-) Posted at 2016-05-14 by tve If my comment is correct, it's running at approx 250khz. I didn't see any device that could not run at 400Mhz and this is the fastest I could make it go without making weird waveforms. Posted at 2016-05-16 by virtualcodewarrior The code was indeed running at around 250kHz, according to the data sheet of the radio module it supports up to 400 kHz so it should have worked, but for some reason it doesn't. The espruino version has these artifacts on the signal that don't exist on the mongoose version. I cannot get higher resolution out of my logic analyzer but
I wonder if setting sda to 1 actually pulls it to 0 first before reapplying the 1. Note that the following images are using a lower sample rate so that is why the rise times look slow and it doesn't show the artifacts.
It looks like mongoose allows clock stretching also, but that happens after ack so should not be the cause of the difference. You can imagine that I am positively stumped why mongoose works consistently correct while Espruino consistently fails. Posted at 2016-05-16 by tve What is the exact device you're trying to get to work? Posted at 2016-05-17 by virtualcodewarrior The device is a RRD-102V2.0 module that has a RDA5807M Fm radio chip. According to the specs, It should be capable of 400kHz I2C communication speeds. I managed to get slightly higher resolution that shows the glitch even better The glitch shows up even if not connected to the radio module and rda and scl just connected to the two pullup resistors. Posted at 2016-05-17 by virtualcodewarrior Here is the mongoose IoT output on the same exact hardware for comparison. just to rule out any hardware or measuring errors. Posted at 2016-05-17 by bigplik hi, did anyone solve how to connect OLED into ESP8266 on Espruino? Posted at 2016-05-17 by @MaBecker @bigplik Yes - check http://forum.espruino.com/conversations/286554/#comment12977481 Posted at 2016-05-18 by MrTimcakes @bigplik Perhaps this thread may be of use to you http://forum.espruino.com/conversations/285779/#12949434 Posted at 2016-05-23 by virtualcodewarrior I gave up on the build-in I2C and used the following code to bit bang the I2C instead in JavaScript (code almost 1 to 1 from I2C article on wikipedia):
This code actually works with the radio module and I managed to tune the FM station and got it to play :-). Here is the radio code that uses my bit-banging I2C for anyone who is interested :
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2016-05-01 by virtualcodewarrior
I am trying to get i2c to work on my ESP8266, but don't have much luck.
I must be missing something.
Maybe someone here can help me.
I tried
I put 10k pull-ups on both GPIO12 and GPIO14
Correct me if i am wrong but I was assuming that the I2C.find command is similar to i2cdetect and should return a list of I2C compatible devices/addresses on the I2C bus.
If I specify a bitrate, like
my ESP8266 will crash/reset.
When I try to read from an valid device address (checked with my Raspberry pi) I get
But the returned data is invalid and a similar result is returned when reading from an invalid device address (just with different data).
I am running this version of the firmware :
s3.voneicken.com/espruino/espruino_1v85.tve_master_66fde09_esp8266.tgz
@MaBecker tested this build to have working support for I2C as mentioned in the
Latest Espruino build for Esp8266 topic.
I am trying to communicate with an rrd-102v2.0 (FM radio (RDA5807)).
Beta Was this translation helpful? Give feedback.
All reactions