problem using 24LC64 with SX/B
Fellow SX/B programmers;
Perhaps you could spot the error in my program...
I am trying to use I2C chips with the SX/B and recently got the DS1621 to work and display to a 7segx2 display. Now, I have added the Microchip 24LC42 on the same I2C bus:SDA/SCL at a different address 101.
The program ( TempMI2.sxb attached) is suppose to read the temperature every 5 seconds and store it in memory starting at location 1. It then loops back and starts again. During the loop the temperature is displayed, then the target memory location and finally '00' to indicate end of cycle.
When the program runs it displays correctly the·temperature '25' then the first target memory location '01' and then the temperature data that was stored at that location '-5'· *which is wrong*, followed by the '00' and end of cycle. This would lead me to believe that the MEM_IN & MEM_OUT subroutines may have errors. These routines are copied below:
·MEM_OUT:
' puts byte to memory chip
' USE: MEM_OUT addressW, value
· tmpW1 = __WPARAM12··' storage address
· tmpB2 = __PARAM3··' value
· I2CSTART SDA
· I2CSEND SDA, adrMW··' control byte (write)
· I2CSEND SDA, tmpW1_MSB·' address high byte
· I2CSEND SDA, tmpW1_LSB·' address low byte
· I2CSEND SDA, tmpB2··' data value
· I2CSTOP SDA
· RETURN
·MEM_IN:
' gets byte from memory chip
' USE: value = MEM_OUT addressW
· tmpW1 = __WPARAM12··' storage address
· I2CSTART SDA
· I2CSEND SDA, adrMW··' send control byte(write)
· I2CSEND SDA, tmpW1_MSB·' send address word
· I2CSEND SDA, tmpW1_LSB
· I2CSTART SDA···' restart for read
· I2CSEND SDA, adrMR··' send control byte (read)
· I2CRECV SDA, tmpB2, Nak·' read the byte
· I2CSTOP SDA
· RETURN tmpB2
Thanks, John
Perhaps you could spot the error in my program...
I am trying to use I2C chips with the SX/B and recently got the DS1621 to work and display to a 7segx2 display. Now, I have added the Microchip 24LC42 on the same I2C bus:SDA/SCL at a different address 101.
The program ( TempMI2.sxb attached) is suppose to read the temperature every 5 seconds and store it in memory starting at location 1. It then loops back and starts again. During the loop the temperature is displayed, then the target memory location and finally '00' to indicate end of cycle.
When the program runs it displays correctly the·temperature '25' then the first target memory location '01' and then the temperature data that was stored at that location '-5'· *which is wrong*, followed by the '00' and end of cycle. This would lead me to believe that the MEM_IN & MEM_OUT subroutines may have errors. These routines are copied below:
·MEM_OUT:
' puts byte to memory chip
' USE: MEM_OUT addressW, value
· tmpW1 = __WPARAM12··' storage address
· tmpB2 = __PARAM3··' value
· I2CSTART SDA
· I2CSEND SDA, adrMW··' control byte (write)
· I2CSEND SDA, tmpW1_MSB·' address high byte
· I2CSEND SDA, tmpW1_LSB·' address low byte
· I2CSEND SDA, tmpB2··' data value
· I2CSTOP SDA
· RETURN
·MEM_IN:
' gets byte from memory chip
' USE: value = MEM_OUT addressW
· tmpW1 = __WPARAM12··' storage address
· I2CSTART SDA
· I2CSEND SDA, adrMW··' send control byte(write)
· I2CSEND SDA, tmpW1_MSB·' send address word
· I2CSEND SDA, tmpW1_LSB
· I2CSTART SDA···' restart for read
· I2CSEND SDA, adrMR··' send control byte (read)
· I2CRECV SDA, tmpB2, Nak·' read the byte
· I2CSTOP SDA
· RETURN tmpB2
Thanks, John
SXB
![](/plugins/FileUpload/images/file.png)
7K
Comments
One way to handle this is to wait perhaps 10ms after each write. Another is to attempt to
read the data back. The EEPROM will not respond (you'll get a NAK response to addressing
the chip) until the the write cycle is done.
Where do you suggest putting the PAUSE and for how long?
Thanks, John
As far as I can tell, my program uses the same sequence of I2cXX commands as yours when you look inside SUB PUT_EE and FUNC GET_EE *but* for some reason I get '-5' in the display instead of '26'. I noticed that you use a slightly different SUB, ENDSUB syntax, and a FUNC. I believe my syntax is also ok. So it is still a mystery why it (looking at the high level code) still doesn't work.
Only options I can think of is: try another chip, or step thru in assembler...
'adrMW CON $10100100 ' write to mem chip 24lc64 1010 a2,a1,a0, r/w
'adrMR CON $10100101 ' read from mem chip 24lc64 1010 a2,a1,a0, r/w
SlaveWr CON $A4 '$A0 ' note: these lines must be used and the names
SlaveRd CON SlaveWr | 1 ' indicated used in program.. in order to work
Just to make sure you understand where the error was, the percent sign is used as a prefix for binary numbers and the dollar sign is for hex numbers. The values $A4 and $A5 are equivalent to %10100100 and %10100101.
Dave