Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : 24LC32 EEPROM problems...
Page 1 of 2 | |||||
Author | Message | ||||
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9066 |
Just when I thought I had nailed my I2C EEPROM issues, I am having major issues trying to read and write to a 24LC32A. This device uses word addressing as most EEPROM chips or FRAM does, but the code that does work fine on a FRAM chip, won't work on this device. Is there something special about the 24LC32 which would make it incompatible with the I2C commands? I am trying to talk to it on a MM+. Test code: A=1 'Address byte B=1 '1st data byte C=2 '2nd data byte D=3 '3rd data byte E=4 '4th data byte I2C OPEN 100,100 I2C WRITE &B1010000,0,6,A\256,A Mod 256,B,C,D,E 'Write four bytes from address 1 Pause 10 'make sure EEPROM has time to write(5ms needed) I2C WRITE &B1010000,0,2,A\256,A Mod 256 'Reset memory pointer to 1. Pause 10 I2C READ &B1010000,0,4,D$ 'Read four bytes into D$ Print len(D$) B1=asc(mid$(D$,1,1)) C1=asc(mid$(D$,2,1)) D1=asc(mid$(D$,3,1)) E1=asc(mid$(D$,4,1)) Print B1,C1,D1,E1 This code always returns with: 4 0 2 0 0 I am expecting and needing it to return with: 4 1 2 3 4 I can't see what the hell I am doing wrong, and my brain now hurts - especially as I thought I had nailed these feckin' EEPROM chips. The only thing I can think of is that the 24LC32A is not a compatible device..... YES - 4k7 pull-up's to 3v3, and datasheet says that device is happy with any voltage greater then-equal to 2.5v, which it has. YES - Address pins are correct - pins 1-4 are all connected directly to ground. Will ALWAYS only be four bytes, so figured I should be able to send them all in one command along with the address bytes - so 6 bytes in total. 'A\256' and 'A Mod 256' have been used before with great success on the FRAM chips - I don't see how the addressing is different, but maybe it is? Smoke makes things work. When the smoke gets out, it stops! |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 8592 |
Try I2C WRITE &B1010000,1,2,A\256,A Mod 256 'Reset memory pointer to 1. as the write before the read. In general when reading after sending an address the write should use option 1 to avoid sending a stop code UPDATE: If you are using the 24C32 on a DS3231 board the default address is &B1010111 The following code is tested and works on a Micromite b32 with a DS3231 board option explicit option default integer dim A=1 'Address byte dim B=1 '1st data byte dim C=2 '2nd data byte dim D=3 '3rd data byte dim E=4 '4th data byte dim d6$ DIM B1,C1,D1,E1 I2C OPEN 100,0 I2C WRITE &B1010111,0,6,A\256,A Mod 256,B,C,D,E 'Write four bytes from address 1 Pause 10 'make sure EEPROM has time to write(5ms needed) I2C WRITE &B1010111,1,2,A\256,A Mod 256 'Reset memory pointer to 1. I2C READ &B1010111,0,4,D6$ 'Read four bytes into D$ Print len(D6$) B1=asc(mid$(D6$,1,1)) C1=asc(mid$(D6$,2,1)) D1=asc(mid$(D6$,3,1)) E1=asc(mid$(D6$,4,1)) Print B1,C1,D1,E1 |
||||
viscomjim Guru Joined: 08/01/2014 Location: United StatesPosts: 925 |
Thats interesting, I have never used the 1 before, I will have to give that a try. |
||||
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9066 |
Hi - thanks guys. I'm away for a day job, but will try this out later. In other eeprom I have used, you reset the address pointer by specifically sending the address bytes followed by a stop. That way, the pointer gets moved, but no data is exchanged. Odd.... I will let you know what happens later tonight(my time). EEPROM is a Microchip 24LC32A SOIC on my own PCB. It is not on a RTC module or other pre-assembled module from eBay. WP(pin7) is grounded, so writing should be possible. I'll post back tonight - stay tuned! Smoke makes things work. When the smoke gets out, it stops! |
||||
jman Guru Joined: 12/06/2011 Location: New ZealandPosts: 711 |
Hi G add this after the write Print "0=ok 1=nack 2=timeout"; mm.i2c If you get a 0 then the write was good this way no guess work Regards Jman |
||||
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9066 |
RESULTS: 4 0 0 0 0 ? mm.i2c results in 2 - timeout. Code changed to reflect the 000 address pins I have. Screenshots: EDIT: Here is a shot of how I have the EEPROM connected to the MM+: Next thing is to pull out the logic analyzer and see if we are getting things happening on the I2C pins - will post results of this test soon. EDIT: Cannot run logic analyzer. Keep getting "I2C is busy" error messages. Even with pause 500's between writes or read attempts. Is it possible there is a bug with the MM+ I2C? I will now try the same code on a 170 and see what happens. EDIT: Have got rid of the "I2C is busy" error - removed the logic analyzer - it's wires must have been holding the bus till you start sampling. Will start running then connect analyzer. Smoke makes things work. When the smoke gets out, it stops! |
||||
jman Guru Joined: 12/06/2011 Location: New ZealandPosts: 711 |
Hi G Try this I2C open 100,100 For I = 8 To &H77 I2C Read I, 1, 1, A If MM.I2C = 0 Then GoTo Found Pause 5 Next I Print "No I2C device found" End Found: Print "Address is ";"&H";Hex$(I) Post the results Jman |
||||
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9066 |
RESULTS: Results from the logic analyser: EDIT: Analyser results are from my previous attempts, not jman's test code. I have yet to try any of this code on a 170, but that is next. I will cut the SCL and SDA tracks to the MM+ chip, and hop onto these from a 170. Smoke makes things work. When the smoke gets out, it stops! |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 8592 |
Grogs Is WP tied low? This has to be connected and must be low to allow writes. A0,A1, A2, VSS are all obviously connected but do they also connect to GND? Difficult to tell from the pic. Do you still design boards without a schematic? It really really makes things easier if you start from the schematic and then the design check in the PCB software can make sure the layout is correct. |
||||
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9066 |
@ matherp - yes WP grounded - see post #4. According to the test-tool in the layout software, all points that should be ground, are ground: I do have a couple of those RTC/EEPROM eBay modules, so I might hook one of them up to a spare MM+ and see if I have the same issue. EDIT: I don't know why it did not occur to me to check this earlier, but I am running 4.7 Beta 23 on this module - I will upgrade to the latest - this may well be something that has been fixed - worth a try. Smoke makes things work. When the smoke gets out, it stops! |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 5907 |
I didn't have a 24LC32 but I do have a 24LC256. On a MM+ explore64 this works OK. LIST ALL ' TassyJim ' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Option explicit Option default integer Dim A=1 'Address byte Dim B=1 '1st data byte Dim C=2 '2nd data byte Dim D=3 '3rd data byte Dim E=4 '4th data byte Dim d6$ Dim B1,C1,D1,E1 I2C OPEN 100,0 I2C WRITE &B1010000,0,6,A\256,A Mod 256,B,C,D,E 'Write four bytes from address 1 Pause 10 'make sure EEPROM has time to write(5ms needed) Print MM.I2C I2C WRITE &B1010000,1,2,A\256,A Mod 256 'Reset memory pointer to 1. I2C READ &B1010000,0,4,D6$ 'Read four bytes into D$ Print Len(D6$) B1=Asc(Mid$(D6$,1,1)) C1=Asc(Mid$(D6$,2,1)) D1=Asc(Mid$(D6$,3,1)) E1=Asc(Mid$(D6$,4,1)) Print B1,C1,D1,E1 > RUN 0 4 1 2 3 4 > What pins are you using? I use I2C (1) pins 43 and 44. Jim Edit: I just traced your board. The pins look correct so I think the beta32 will fix it. VK7JH MMedit MMBasic Help |
||||
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9066 |
Yes, pins 43 and 44 - see images above. This is what I can't understand - it should be working, but isn't - I hate these sorts of feckin' issues. I will check for continuity on the SCL and SDA tracks - perhaps we have a fluffy via on the PCB or something. I will also check that ALL pins 1-4 and 7 are indeed grounded. Smoke makes things work. When the smoke gets out, it stops! |
||||
jman Guru Joined: 12/06/2011 Location: New ZealandPosts: 711 |
This indicates a hardware error of some sort PCB the I2C device itself.. Jman |
||||
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9066 |
EXCREMENT! ...I have a working theory - stay tuned for an update...(board is slightly different to the version in the images - no feckin' pull-ups on SDA or SCL at all, despite what I insisted was the case in post #1. ...please don't kill me, if this ends up being the problem, and it probably is, as those pull-ups are essential........ Will fit some now, and get back ASAFP. Smoke makes things work. When the smoke gets out, it stops! |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 8592 |
Grogs After opening "I2C OPEN 100,100" insert the command poke &HBF886358,&H600 This should (may) enable the chips internal pullups on the i2C lines |
||||
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9066 |
Thanks for the poke, but I have added 4k7's now, and am getting a response to jman's code. I am trying to run my original code now, but the MM+ is complaining about my use of variable D when D$ has been defined. Once OPTION EXPLICIT has been issued, is there any way to disable it? Nothing wants to work. Have cycled power, NEW'd the program, xmodem'd another copy across without the option explicit, but it keeps telling me about it. Reset etc, won't go away. Will try hard-reset. One step away from proving a point with my mistake, but can't get away from the explicit problem now. I could just change the code to make a point, but I want to get rid of that now that it won't let me turn it off. Smoke makes things work. When the smoke gets out, it stops! |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 8592 |
None of the latest versions of the Micromite firmware allow this (since 4.7 I think)- nothing to do with options. I corrected it in my version of your code. |
||||
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9066 |
Hard-reset does not clear that option explicit once defined. Would love to be able to disable it..... For now, I just changed the code, and guess what? (rhetorical) And with my ORIGINAL feckin' code: Schoolboy mistake, and I should have known better..... My sincerest apologies for wasting everyone's time - sheesh...... EDIT: ....and the analyser output looks much healtier too now.... CURSES!!!!!!!! Smoke makes things work. When the smoke gets out, it stops! |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 5907 |
From the manual: OPTION EXPLICIT Placing this command at the start of a program will require that every variable be explicitly declared using the DIM command before it can be used in the program. This option is disabled by default when a program is run. If it is used it must be specified before any variables are used. Good to see it working at last. Jim VK7JH MMedit MMBasic Help |
||||
Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3165 |
I love this, it is better than watching high drama on the TV. Geoff Graham - http://geoffg.net |
||||
Page 1 of 2 |
Print this page |