V1.04/ESP-01: I2C, first tests
Posted: Sun Nov 01, 2015 2:17 pm
Hi
I've tried the i2c commands and although it isn't working it is not looking too bad.
I'm using a SALEAE logic analyser to view the bus.
Here is my program to read the time from a DS1321 with comments on what I'm seeing:
The big issue for testing further is not being able to send a zero as the starting address for the read
Are you using zero terminated strings or strings with the length in the first byte?
This is important because with i2c we need to read and write zeroes. I would prefer the read to be just a single byte into a numerical variable
so a read of 5 bytes would be:
b1=i2c.read()
b2=i2c.read()
...
rgds
Peter
I've tried the i2c commands and although it isn't working it is not looking too bad.
I'm using a SALEAE logic analyser to view the bus.
Here is my program to read the time from a DS1321 with comments on what I'm seeing:
Code: Select all
let address = 104
let numchars = 1
let nsecs = 0
i2c.begin(address) 'this works nicely address sent out correctly
i2c.write(0) 'this is a problem, I need to send out the data-value 0 but the command takes a string
' I can't create a string with a single 0 value. "" creates and empty string.
i2c.end() 'OK
i2c.requestfrom(address,numchars) ' seems OK read address set correctly
nsecs = i2c.read() ' this looks like the data line is being held low rather than being pulled high by the resistor
' but difficult to tell as the read address sent is wrong but should still be valid, correct number of clocks sent
print nsecs
The big issue for testing further is not being able to send a zero as the starting address for the read
Are you using zero terminated strings or strings with the length in the first byte?
This is important because with i2c we need to read and write zeroes. I would prefer the read to be just a single byte into a numerical variable
so a read of 5 bytes would be:
b1=i2c.read()
b2=i2c.read()
...
rgds
Peter