First and foremost Thank You, Thank You, Thank You for all of your help guys I really do appreciate it.
Here is the working Code:
and it's out putting this to Hyperterm:Code:' Define serial output pin SO con 0 ' Define serial mode T2400 con 0 ' 2 Byte Address Vars addr1 var word addr2 var word addr3 var word ' Vars for data being written D1 Var Byte D2 Var Byte D3 Var Byte ' Vars for data being read B1 VAR BYTE B2 VAR BYTE B3 VAR BYTE ' Set Data Bytes D1 = 7 D2 = 6 D3 = 5 ' Set Address Bytes addr1 = 1 addr2 = 2 addr3 = 3 I2CWRITE PORTB.1,PORTB.4,$A0,addr1,[D1] ' Write a 1 to address 1 PAUSE 10 ' Wait 10ms for write to complete I2CWRITE PORTB.1,PORTB.4,$A0,addr2,[D2] ' Write a 2 to address 2 PAUSE 10 ' Wait 10ms for write to complete I2CWRITE PORTB.1,PORTB.4,$A0,addr3,[D3] ' Write a 3 to address 3 PAUSE 10 ' Wait 10ms for write to complete I2CREAD PORTB.1,PORTB.4,$A0,addr1,[B1] ' Read address 1 into B1 I2CREAD PORTB.1,PORTB.4,$A0,addr2,[B2] ' Read address 2 into B2 I2CREAD PORTB.1,PORTB.4,$A0,addr3,[B3] ' Read address 3 into B3 Serout SO,T2400,["Addr",#addr1,":",#B1," and then Addr",#addr2,":",#B2," and then Addr",#addr3,":",#B3,13,10] ' Print B1's Value in DEC
The problem I had in the beginning was I had the SDA/SCL Pins wrong and I did not have the A2 pin Tied to +5V but after correcting those I had my control byte misunderstood and thats why it would not work. After changing the control byte back to $A0 with the A2 held High and the propper pins chosen for SDA and SCL it now works like it should.Code:Addr1:7 and then Addr2:6 and then Addr3:5 Addr1:7 and then Addr2:6 and then Addr3:5 Addr1:7 and then Addr2:6 and then Addr3:5
I hope this thread saves everyone a ton of time in the future with these chips I know I sure learned a ton from this little experiance![]()




Bookmarks