Cannot interface with i2c device
Posted: Fri Feb 01, 2019 8:55 am
Hi,
i've been trying this for a few days already- no success.
I am trying to connect to TCS34725 color sensor via i2c, but seems like no any connection.
When I try to read from address it always return 255.
Here it is my code:
Attached is the datasheet of the color sensor.
https://cdn-shop.adafruit.com/datasheets/TCS34725.pdf
Please help!
i've been trying this for a few days already- no success.
I am trying to connect to TCS34725 color sensor via i2c, but seems like no any connection.
When I try to read from address it always return 255.
Here it is my code:
So what I am doing wrong? I have also 24LC256 EEPROM on the same i2c bus, and it works OK.Device = 18F26k20
Clock = 64
Config FOSC = INTIO67
#option I2C_SCL = PORTB.4
#option I2C_SDA = PORTB.5
Dim I2C_EEPROM As Byte
Include "si2c.bas"
Public Sub i2cwrite (paddress As byte, pdata As Byte)
SI2C.Start
SI2C.WriteByte(I2C_EEPROM)
SI2C.WriteByte(paddress)
SI2C.WriteByte(pdata)
SI2C.Stop
DelayMS(10)
End Sub
Public Function i2cread (pAddress As byte) As Byte
SI2C.Start
SI2C.WriteByte(I2C_EEPROM)
SI2C.WriteByte(paddress)
SI2C.Restart
SI2C.WriteByte(I2C_EEPROM + 1)
Result = SI2C.ReadByte
SI2C.Acknowledge(I2C_NOT_ACKNOWLEDGE)
SI2C.Stop
End Function
Sub test()
I2C_EEPROM = $29
I2CWrite(0,1)
delayms(20)
I2CWrite(0, %00011011)
While true
temp=i2cread($12)
GLCD.WriteAt(0,0,DecToStr(temp)+" ")
DelayMS (100)
End While
End Sub
main:
test()
End
Attached is the datasheet of the color sensor.
https://cdn-shop.adafruit.com/datasheets/TCS34725.pdf
Please help!