Shop OBEX P1 Docs P2 Docs Learn Events
problem using 24LC64 with SX/B — Parallax Forums

problem using 24LC64 with SX/B

verobelverobel Posts: 81
edited 2007-10-23 18:44 in General Discussion
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

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-10-17 17:34
    You may not be waiting for the EEPROM to finish its first write cycle. It takes at least 5ms.
    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.
  • verobelverobel Posts: 81
    edited 2007-10-17 17:51
    Do you know how long the write cycle takes? I currently have PAUSE 5000 in program after my call to MEM_OUT (perhaps the PAUSE should be coded inside the subroutine). There is no PAUSE in MEM_IN.

    Where do you suggest putting the PAUSE and for how long?
    Thanks, John
  • JonnyMacJonnyMac Posts: 9,216
    edited 2007-10-17 18:22
    You may want to encapsulate your I2C commands to save overall code space in the project. I've attached an EEPROM program that will show you how to do that; you can also adapt your DS1621 interfacing to these subroutines and functions. Yes, the code is for the 24LC512, but it's compatible with the 24LC64.
  • verobelverobel Posts: 81
    edited 2007-10-17 23:14
    Thanks for the sample program.

    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...
  • verobelverobel Posts: 81
    edited 2007-10-18 03:06
    By using the sample program from JonnyMac and extensive testing I was able to isolate the faults in my program to..

    '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
  • Dave HeinDave Hein Posts: 6,347
    edited 2007-10-23 18:32
    John,

    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
  • verobelverobel Posts: 81
    edited 2007-10-23 18:44
    Thanks Dave... looks so obvious now!
Sign In or Register to comment.