Electronics > Projects, Designs, and Technical Stuff
Confused about how this I2C read works
Chet T16:
I have an i2c master which writes to a slave (controlling the display) and reads from the same slave getting the button presses.
In idle mode the masters reads every 0.5 seconds or so and receives the following
--- Quote ---S 01000111 0 00000001 0 00000001 0 P
Read from address: 0x23 Number of Bytes: 2
Byte 1: 0x01
Byte 2: 0x01
--- End quote ---
Pressing a button causes a read instantly giving similar to below
--- Quote ---S 01000111 0 00000100 0 10000010 0 10010001 0 00000000 0 00000100 0 P
Read from address: 0x23 Number of Bytes: 5
Byte 1: 0x04
Byte 2: 0x82
Byte 3: 0x91
Byte 4: 0x00
Byte 5: 0x04
--- End quote ---
There is a third line in addition to SDA and SCL which is pulled low during read and write operations, i thought perhaps that the slave was pulling this low when data was available but having disconnected the master and watched this third line it is going low for three 6ms pulses every 0.5 seconds. Pressing a button has no affect on this.
I have successfully managed to write to the slave but not read. I have tried to read both 2 and 5 bytes when the third line goes low. Reading 2 will give me 0x01 0x01 as above but trying 5 will just give me 0x01 0x01 0xff 0xff 0xff with button presses having no affect on the output.
Any clues how the master might be telling when there is data to be read or what i could try?
Thanks
Chet T16:
Further testing shows that its the slave that decides when to be read from, the master holding the line low when writing and the slave doing the same for reads.
Using the arduino wire library as read requests need to specify the number of bytes, i this normal practise? Should the master be able to open a request and the slave decide when to stop?
shebu18:
Can you give us the model of the slave and master? Exact name. In I2C you have only 2 line, not 3. 3lines sounds more like some sort of SPI.
richcj10:
It really depends on the device. There are EEPROM devices that allow consecutive reads from the device w/o requesting the data.
What chip is it? That would tell forum members more information.
richcj10:
--- Quote from: shebu18 on February 25, 2013, 11:05:58 am ---Can you give us the model of the slave and master? Exact name. In I2C you have only 2 line, not 3. 3lines sounds more like some sort of SPI.
--- End quote ---
It could be a interrupt....
Navigation
[0] Message Index
[#] Next page
Go to full version