I2C Read Problem

I2C, Serial, Wireless etc.

Moderator: chris

I2C Read Problem

Postby tnsguy » Tue May 24, 2011 5:04 pm

I am using the serial port driver to communicate with a USB-to-I2C converter. It writes perfectly to the target device. It also sends a proper I2C read command when I use 0x54 (read from device with no register address). However, when I use either 0c55 or 0x56 (a read command with either a 1-byte or a 2-byte address sent to the target) the converter sends a write instead of a read request to the target.

I have confirmed this with a logic analyzer looking at the I2C bus and, since my target is a micro-controller, looking at what is received by the target. I have also confirmed that the correct command is being sent to the converter.

Has anyone else ever seen this? I am stopped dead until I can resolve this.

Thanks.
tnsguy
 
Posts: 4
Joined: Tue May 24, 2011 4:54 pm

Re: I2C Read Problem

Postby Gerry » Tue May 24, 2011 6:04 pm

Please post the exact command string you are using to do the read, that you say is causing the write.
User avatar
Gerry
Site Admin
 
Posts: 245
Joined: Wed Nov 08, 2006 12:28 pm

Re: I2C Read Problem

Postby tnsguy » Tue May 24, 2011 6:12 pm

The exact bytes sent to the USB-to-I2C converter are: 0x56, 0x71, 0x81, 0x00, 0x02.

The code used is:
Public Function baRead(ByVal u8Cmd() As Byte, ByVal u8Channel As Byte, ByVal NumReturnBytes As Byte) As Byte()

Dim bTheResult(3) As Byte
Dim baCmd(6) As Byte

baCmd(0) = &H54
baCmd(1) = bI2CAddr * 2 + 1
baCmd(2) = u8Cmd(1)
baCmd(3) = u8Channel
baCmd(4) = NumReturnBytes
Try
comPort.Open()
Catch de As ArgumentException
MsgBox("Invalid Com Port")
Throw
Return baCmd
End Try

comPort.Write(baCmd, 0, 5)
bTheResult = bI2CRead(NumReturnBytes)

comPort.Close()

Return bTheResult

End Function

Instead of a 0x71 being sent as the first byte of the I2C communication with the target, a 0x70 is sent as shown on a logic analyzer.

Thanks.
tnsguy
 
Posts: 4
Joined: Tue May 24, 2011 4:54 pm

Re: I2C Read Problem

Postby tnsguy » Tue May 24, 2011 11:19 pm

BTW - The converter is running version 7 of the firmware.
tnsguy
 
Posts: 4
Joined: Tue May 24, 2011 4:54 pm

Re: I2C Read Problem

Postby Gerry » Wed May 25, 2011 9:47 am

Hi,

The command
0x56, 0x71, 0x81, 0x00, 0x02
is a command to read two bytes from the slaves internal address at 0x8100. Is that your intention?

The first thing the bus master (USB-I2C) must do is send the internal address that you want to read from to the slave (your device). This is a write operation. So every read command you send will be preceeded on the I2C bus by a write sequence. Command 0x54 does not need to send an internal address so there is no preceeding write.

I have a fuller explanation in my I2C tutorial here:
http://www.robot-electronics.co.uk/acatalog/I2C_Tutorial.html
Have a look at the section "Reading from the Slave"
User avatar
Gerry
Site Admin
 
Posts: 245
Joined: Wed Nov 08, 2006 12:28 pm

Re: I2C Read Problem

Postby tnsguy » Wed May 25, 2011 3:25 pm

Thanks for the explanation Gerry. I think that clears it up.
tnsguy
 
Posts: 4
Joined: Tue May 24, 2011 4:54 pm


Return to Communication devices

Who is online

Users browsing this forum: No registered users and 1 guest

cron