> It is bit 7 for R/W (Slave address + write bit)
How did you find that?
> It is bit 7 for R/W (Slave address + write bit)
How did you find that?
Louie
Picked up from the datasheet of the device. That is what I understood, am I wrong?
Though I did tried $3B & $5B.
Not sure if you're wrong or not. I'm still trying to decipher that part in the datasheet because they don't make it easy. I've found that some information has to be gleaned from other devices of the same manufacturer to put the whole story together, kinda sucks!
I also noticed the address stays at $1B after the first loop in your test program and if it works you might miss it.
Note: I just found one of my programs on another I2C device that has bit 1=0 as the Write bit.
$1B = $00011011 used for Read
$1A = $00011010 used for Write
Last edited by LinkMTech; - 27th July 2013 at 17:37.
Louie
I read it again to confirm this, the attachment is my source. It also mentions 9 bits long address. Not sure who sends an ack. I see that in read statement the device send ack, so why add it to the address PIC is sending. Very confusing.
Ahhhh... okay
Let's use this info then. Looks like the address is using bits 1~7 and the Read/Write control bit is 0.
If control bit is set (=1) then Read, if bit cleared (=0) then Write
So:
%00110111 = $37 ' Read function
%00110110 = $36 ' Write function
Try that.
By the way, the device sends the ACK, or acknowledges, by holding the Data line LOW on the 9th clock cycle. The PIC will see this and continue to send data.
Louie
How do I implement this, like this below?
Code:Main: High Led : Pause 500: Low Led : PAUSE 500 Addr=$36 I2CWRITE SDA,SCL,ADDR,LOC Addr=$37 : pause 10 ' OR If SDA=1 then main I2CREAD SDA,SCL,loc,[VALUE],Fail PAUSE 25 DEBUG HEX Value,13,10 PAUSE 250 DEBUG "Done....",13,10 WHILE 1 : WEND Goto Main Fail: toggle portc.2 goto main
Just notice the address missing on the Read function.
Moved the Fail label after Write to test this part first. This will let you know if the Write address was recognized so the Pause 10 is not needed.
Code:Main: High Led : Pause 500: Low Led : PAUSE 500 Addr=$36 I2CWRITE SDA,SCL,ADDR,LOC, Fail ' Test here first Addr=$37 ': pause 10 ' OR If SDA=1 then main I2CREAD SDA,SCL,ADDR,loc,[VALUE] ',Fail PAUSE 25 DEBUG HEX Value,13,10 PAUSE 250 DEBUG "Done....",13,10 WHILE 1 : WEND Goto Main Fail: toggle portc.2 goto main
Louie
I just discovered, that the I am actually receiving only 1 byte as expected. Rest are just "Start......"13,10 and "Done",13,10. Yesterday got too exhausted and missed this mistake of mine.
Here is the current code withEvery time Change line goes low (detected something), I try to read first 4 memory locations. The communication fails a lot of times (both write and read (write more than read) )in this attempt but I do get the data on the screen finally. Secondly, the data which comes is wrong. For example, memory locations 0 does not read 2E for a start.Code:Start: Loc=0 Start_Again: I2CWRITE SDA,SCL,$36,[LOC],Fail1 Main: Value=0 High Led : Pause 500: Low Led : PAUSE 500 I2CREAD SDA,SCL,$37,[VALUE] ,Fail2 PAUSE 250 DEBUG Value Loc=Loc+1 If Loc<4 then Start_Again ' Read first 4 locations x=0 WHILE !Change ' Stay here if Change Stays High Pause 500 : x=x+1 If x =10 then LOC=3 : Goto Main ' Do another read Endif WEND while Change : pause 100 : wend ' Stay here if change is Low Goto Start Fail1: ' Try Write again For x=0 to 50 High Portc.2 : Pause 50 : Low PortC.2 : Pause 50 Next x Goto Start_again Fail2: ' Try read again For x=0 to 5 High Portc.2 : Pause 250 : Low PortC.2 : Pause 250 Next x Goto Main
Bookmarks