I2c problem
I2c problem
Now i've done a few projects with I2c and i've always got them to work with either little or some effort.
I'm now trying to get a temperature reading from an LM75A but I can'get it to respond. I've tried a zx40n and 328l both h/w are s/w channels but i can't seem to get a response. I've got 4k7 pull-ups in place.
If i use i2cmd i get a return of -1
If i use bval = I2CPutByte(chanI2c, byAddress) i get a false returned
Does this suggest the device is simply not responding ?
The published default address is &h48
I'm now trying to get a temperature reading from an LM75A but I can'get it to respond. I've tried a zx40n and 328l both h/w are s/w channels but i can't seem to get a response. I've got 4k7 pull-ups in place.
If i use i2cmd i get a return of -1
If i use bval = I2CPutByte(chanI2c, byAddress) i get a false returned
Does this suggest the device is simply not responding ?
The published default address is &h48
Re: I2c problem
I would think so. Did you remember that the I2C slave address needs to be in the upper 7 bits? For a slave address of 0x48 you would use 0x91 for reading and 0x90 for writing.FFMan wrote:If i use bval = I2CPutByte(chanI2c, byAddress) i get a false returned. Does this suggest the device is simply not responding ?
You can see this more clearly, perhaps, in the timing diagram from the LM75A datasheet (excerpt attached).
- Attachments
-
- LM75A-I2C.jpg (23.32 KiB) Viewed 4413 times
- Don Kinzer
OK follow on question
Thanks to you I have the LM75a working on address &h91
Before i used the LM75a i tried the mcp9808 but i couldn't get it to work, partly because I wasn't entirely sure what the correct address is.
So knowing now i had working device (LM75a) and hardware i wrote a loop to put address sequentially out on i2c to see when i got a response. An address scan in other words.
I failed to get the mcp9808 to respond in the range 1-255, so i connected the known working lm75a in ran the scan again, but it failed to respond even when the scan hit the right address. Is this not a valid thing to do in I2c like this ?
Thanks to you I have the LM75a working on address &h91
Before i used the LM75a i tried the mcp9808 but i couldn't get it to work, partly because I wasn't entirely sure what the correct address is.
So knowing now i had working device (LM75a) and hardware i wrote a loop to put address sequentially out on i2c to see when i got a response. An address scan in other words.
I failed to get the mcp9808 to respond in the range 1-255, so i connected the known working lm75a in ran the scan again, but it failed to respond even when the scan hit the right address. Is this not a valid thing to do in I2c like this ?
Code: Select all
Call I2CStart(chanI2c)
bval=false
while bval=false and byAddress<255
bval = I2CPutByte(chanI2c, byAddress)
debug.print byAddress;" Addr ";bval
sleep(0.5)
byAddress=byAddress+1
wend
No. Every transaction on the I2C bus begins with and "I2C Start signal" and ends with an "I2C Stop signal". Devices do not perform an address matching function until after the I2C Start and I would guess that they don't try to match again until another start signal occurs.FFMan wrote:Is this not a valid thing to do in I2c like this ?
I think that this may work:
Code: Select all
bval=false
while bval=false and byAddress<=255
Call I2CStart(chanI2c)
bval = I2CPutByte(chanI2c, byAddress)
Call I2CStop(chanI2c)
debug.print byAddress;" Addr ";bval
sleep(0.5)
byAddress=byAddress + 2
wend
- Don Kinzer
ok that works i've established the decimal address as 48.
then i send character 5 to read the temp data.
I'm getting 2 bytes of data back but i'm not quite how i should interpret it as detailed on page 24 of the attached.
Do i map bits marked 2^7 to 2^-4 to the LSBs of a word then if the sign bit is set subtract if from 2047 ?
then divide it by 10000 to get 4 decimal digits ?
any help much appreciated
then i send character 5 to read the temp data.
I'm getting 2 bytes of data back but i'm not quite how i should interpret it as detailed on page 24 of the attached.
Do i map bits marked 2^7 to 2^-4 to the LSBs of a word then if the sign bit is set subtract if from 2047 ?
then divide it by 10000 to get 4 decimal digits ?
any help much appreciated
It didn't make sense to me and didn't produce the correct results. I modified it and incorporated it into a test program that demonstrates it is working.FFMan wrote:found this online which should nail it
Code: Select all
' Ths data array provides some test values for the LM75A
Dim lm75a_data as IntegerVectorData ({
&H7d00,
&H1900,
&H0080,
&H0000,
&Hff80,
&He700,
&Hc900
})
' This data array provides the Celsius temperatures for the above data
Dim lm75a_data_check as SingleVectorData ({
125.0,
25.0,
0.5,
0.0,
-0.5,
-25.0,
-55.0
})
Sub Main()
Dim i as Integer
For i = 1 to UBound(lm75a_data)
Call lm75a_convert_temp_data(lm75a_data(i), lm75a_data_check(i))
Next i
End Sub
' This subroutine converts an LM75A data value to the corresponding temperature
Sub lm75A_convert_temp_data(ByVal data as Integer, ByVal check as Single)
Dim temp as Single
temp = CSng(data And &Hff80) / 256.0
Debug.Print "LM75A value &H"; CStrHex(data); " is "; Fmt(temp, 2); "*C (s/b) "; Fmt(check, 2)
End Sub
- Don Kinzer
thanks don.
just to be clear but it's of no matter, we got the LM75a working ok once i got the address right thanks to you. I then switched to the mcp9808 which i had failed to get working earlier and had parked. That is what this decode issue relates to.
from the mcp9808 i get returned decimal bytes 193 & 101 but i can't seem to make sense of them having tried various options.
temp in here would be in the region of 23-24c but i think the return is degrees F.
i'll try some more things tomorrow, ran out of time this evening
just to be clear but it's of no matter, we got the LM75a working ok once i got the address right thanks to you. I then switched to the mcp9808 which i had failed to get working earlier and had parked. That is what this decode issue relates to.
from the mcp9808 i get returned decimal bytes 193 & 101 but i can't seem to make sense of them having tried various options.
temp in here would be in the region of 23-24c but i think the return is degrees F.
i'll try some more things tomorrow, ran out of time this evening