Problem reading 24FC1025 EEPROM with 18f14k22


Closed Thread
Results 1 to 12 of 12
  1. #1
    Join Date
    Feb 2012
    Posts
    64

    Default Problem reading 24FC1025 EEPROM with 18f14k22

    Based off of an article (Serial EEPROM Part #1) by mackrackit, I have been attempting to read/write to a 24FC1025 EEPROM. I have done this in the past using an 18f4620 and everything worked as expected. I am trying to run the same code on a 18f14k22 and I can't get any read/writes to work when using the I2cread/write commands, but it works flawlessly with the shiftin/out examples. all the bytes I am reading is using the I2cread command come in as decimal 16. I tried slowing down the micro and that didn't change anything. Anyone have any ideas?


    Code:
    ' *** I2C EEPROM using Siftin/out   
    START_Shiftin:     
     READ_DATA:
       lcdout Lcdcmd , Line4, "Reading EEPROM Data " 
       For ADDR_LB = 0 To 50 
          GOSUB INT_ROM
          GOSUB START_ROM
          SHIFTOUT DPIN,CPIN,1,[ExtMem0R]
          SHIFTIN DPIN,CPIN,0,[ACK\1,DATI\8]
          SHIFTOUT DPIN,CPIN,1,[%1\1]
          GOSUB STOP_ROM
          lcdout Lcdcmd , Line3, "ADDR:",DEC ADDR_LB,"   "
          lcdout Lcdcmd , Line3+10, "DATA:",DEC DATI,"   "
          PAUSE 250
       NEXT ADDR_LB
    Return
        
    INT_ROM:
       GOSUB START_ROM
       SHIFTOUT DPIN,CPIN,1,[ExtMem0W]
       SHIFTIN DPIN,CPIN,0,[ACK\1]
       SHIFTOUT DPIN,CPIN,1,[ADDR_HB]
       SHIFTIN DPIN,CPIN,0,[ACK\1]
       SHIFTOUT DPIN,CPIN,1,[ADDR_LB]
       SHIFTIN DPIN,CPIN,0,[ACK\1]
    RETURN
        
    START_ROM:
       HIGH CPIN:HIGH DPIN:LOW DPIN
    RETURN
       
    STOP_ROM:
       HIGH CPIN:LOW DPIN:HIGH DPIN
    RETURN
    
    end
    
    
    ' *** I2C EEPROM using PicBasic I2C commands    
    START_I2C:                
        lcdout Lcdcmd , Line4, "Reading EEPROM Data "
        For ADDR = 0 To 50   
           I2CREAD DPIN,CPIN,$A0,ADDR,[DATI]       
           lcdout Lcdcmd , Line3, "ADDR:",DEC ADDR,"   "
           lcdout Lcdcmd , Line3+10, "DATA:",DEC DATI,"   "
           PAUSE 250
        Next ADDR
    Return

  2. #2
    Join Date
    Feb 2012
    Posts
    64


    Did you find this post helpful? Yes | No

    Default Re: Problem reading 24FC1025 EEPROM with 18f14k22

    I have been doing some more testing and found that the data byte returned from the I2CRead relates to the port-pin I have the DPIN set to. I originally had the DPIN set to portA.4 and I was getting 16 as a result on all my reads. I later moved DPIN to A0 and got all 1's. PortB.6 returns all 64's, PortB.7 Returns all 128's... This is very strange. Am I missing something obvious or is there a bug in pBasic Pro 2.60C with I2C eeprom reads using the 18f14k22.

  3. #3
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: Problem reading 24FC1025 EEPROM with 18f14k22

    I am happy to see that the SHIFTIN/OUT example has possibly helped!

    But I have not used the 18F14K22.

    Have you checked the analog functions of the pins you are using?
    As usual, post the code that is giving you trouble.
    Dave
    Always wear safety glasses while programming.

  4. #4
    Join Date
    Feb 2012
    Posts
    64


    Did you find this post helpful? Yes | No

    Default Re: Problem reading 24FC1025 EEPROM with 18f14k22

    Mackarackit,
    If I have to use your Shiftin/out method I can get by, but I see no reason the I2C commands shouldn't be working. Especially since I need to read a sting of data on each read and I2Cread does that very easily with STR. All the I/O pins are set up correctly (All digital, all interrupts disables, direction correct…). If someone could try reading one of these eeproms on a 18f14k22 I would love to hear of your results.

    I had a similar issue on a 18f46k22 where I was trying to compare all 28 ADC pins with each other pin in turn one at a time and I saw a strange result (Incremented after a certain point) and it turned out that there was a bug in PicBasic pro which got fixed. This is looking like a bug to me as well

  5. #5
    Join Date
    Feb 2012
    Posts
    64


    Did you find this post helpful? Yes | No

    Default Re: Problem reading 24FC1025 EEPROM with 18f14k22

    I still can't get the I2CRead/Write to work with this EEPROM and I have used them with other PICs in the past with no problems. I used my Logic Analyzer to capture both the Shiftin/out and the I2CRead/Write examples. I could follow the working Shiftin/out on the Logic analyzer, but the I2C is either faster than I can capture, or completely messed up. I am using the same program to test both routines.
    I just tried uploading the analyzer screenshots, but it said I didn't have permissions.

    This code works:
    Test_ShiftOut: ' Write "A" byte to EEPROM at Location 0
    ADDR_HB = 0
    ADDR_LB = 0
    Char = "A"
    GOSUB INT_ROM
    SHIFTOUT DPIN,CPIN,1,[Char\8,%1\1]
    GOSUB STOP_ROM
    PAUSE 10
    Return

    Test_ShiftIn:
    GOSUB INT_ROM
    GOSUB START_ROM
    SHIFTOUT DPIN,CPIN,1,[ExtMem0R]
    SHIFTIN DPIN,CPIN,0,[ACK\1,Char\8]
    SHIFTOUT DPIN,CPIN,1,[%1\1]
    GOSUB STOP_ROM
    Return

    INT_ROM:
    GOSUB START_ROM
    SHIFTOUT DPIN,CPIN,1,[ExtMem0W]
    SHIFTIN DPIN,CPIN,0,[ACK\1]
    SHIFTOUT DPIN,CPIN,1,[ADDR_HB]
    SHIFTIN DPIN,CPIN,0,[ACK\1]
    SHIFTOUT DPIN,CPIN,1,[ADDR_LB]
    SHIFTIN DPIN,CPIN,0,[ACK\1]
    RETURN

    START_ROM:
    HIGH CPIN:HIGH DPIN:LOW DPIN
    RETURN

    STOP_ROM:
    HIGH CPIN:LOW DPIN:HIGH DPIN
    RETURN


    This code doesn't work:
    Char = "A"
    I2CWRITE DPIN,CPIN,ExtMem0,ADDR,[Char]
    Pause 10
    I2CREAD DPIN,CPIN,ExtMem0,ADDR,[Char]

    The analyzer shows the I2C commands to be much faster. Maybe the EEPROM is too slow?




    Quote Originally Posted by mackrackit View Post
    I am happy to see that the SHIFTIN/OUT example has possibly helped!

    But I have not used the 18F14K22.

    Have you checked the analog functions of the pins you are using?
    As usual, post the code that is giving you trouble.

  6. #6
    Join Date
    Feb 2012
    Posts
    64


    Did you find this post helpful? Yes | No

    Default Re: Problem reading 24FC1025 EEPROM with 18f14k22

    Trying again to upload the analyzer screenshots:

    I2cWrite:
    Name:  I2CWrite Letter A to EEPROM.jpg
Views: 833
Size:  176.8 KB

    Shiftout (Works):
    Name:  Shiftout Save Letter A to EEPROM.jpg
Views: 848
Size:  183.9 KB

  7. #7
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,588


    Did you find this post helpful? Yes | No

    Default Re: Problem reading 24FC1025 EEPROM with 18f14k22

    (Can't believe I have the PBP manual on my phone. lol )

    You don't mention the osc speed. The manual mentions up to 20MHz, the 18Fs can go much faster.

    Odd that your clock is whacked. What about pull-ups on your pins?

    Robert

  8. #8
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: Problem reading 24FC1025 EEPROM with 18f14k22

    I bet it's that there are no pullup resistors on the SCL and SDA lines when using I2C command. The SHIFTOUT and SHIFTIN command use the pins in a sink and source mode but the I2C mode reverses the the data pin direction at the end of the byte sequence looking for the ACK bit from the slave device. There must be a pullup on the data line to provide sourcing current back to the PIC. If the PIC does not see the proper ACK signal then the command sequence is aborted.
    Dave Purola,
    N8NTA
    EN82fn

  9. #9
    Join Date
    Feb 2012
    Posts
    64


    Did you find this post helpful? Yes | No

    Default Re: Problem reading 24FC1025 EEPROM with 18f14k22

    I am running at 16MHz with the Internal OSC. I do have a 10k pullup on the SDA line. I tried a 2k as well and it did the same thing. I don't have any pullups on the SCL line now, but I did try that before with no luck. I will try it again. I may drop a 16f690 in for testing purposes (Pin compatable with the 18f14k22 and I know they work with this EEPROM).


    Quote Originally Posted by Dave View Post
    I bet it's that there are no pullup resistors on the SCL and SDA lines when using I2C command. The SHIFTOUT and SHIFTIN command use the pins in a sink and source mode but the I2C mode reverses the the data pin direction at the end of the byte sequence looking for the ACK bit from the slave device. There must be a pullup on the data line to provide sourcing current back to the PIC. If the PIC does not see the proper ACK signal then the command sequence is aborted.

  10. #10
    Join Date
    Feb 2012
    Posts
    64


    Did you find this post helpful? Yes | No

    Default Re: Problem reading 24FC1025 EEPROM with 18f14k22

    I am running the Internal OSC at 16MHz. I did try slowing the clock down and it still didn't work. I am not sure if the Clock is whacked or if my Logic Analyzer is just too slow to capture it (500kHz is as fast as it will run on my computer for some reason).

    I am still leaning toward a bug in Picbasic Pro 2.60C (Not because it isn't working at all, but because the value being returned is directly related to to the binary value of the pin it is connected to). If I connect to pin ra.0 I get a return value of 1, ra.1 returns a value of 2, ra.2 = 4... This shouldn't be happening unless I either made some strange mistake with variable ussage, or if there is an internal bug in the compiler. I saw a similar wierd sort of incremental value on the 18f46k22 while reading ADC lines and it turnned out to be a bug in the complier (which got fixed with 2.60c).

    One other thing to note is that the EEPROM address on the Shiftin uses two byte variables while the I2Cread/write uses one 16-bit word variable for the address.

    Jim


    Quote Originally Posted by Demon View Post
    (Can't believe I have the PBP manual on my phone. lol )

    You don't mention the osc speed. The manual mentions up to 20MHz, the 18Fs can go much faster.

    Odd that your clock is whacked. What about pull-ups on your pins?

    Robert

  11. #11
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: Problem reading 24FC1025 EEPROM with 18f14k22

    This routine has worked for me just fine since PBP2.32 w/4 each 24LC1025's. Just exchange the I2CWRITE for I2CREAD and your done....

    CNTRL_BYTE CON $A0 'CONTROL BYTE FOR I2C EEPROM MEMORY (A0/A1 USED FOR CHIP SELECT)

    BLOCK VAR WORD '128 BYTE BLOCK ADDRESS
    ADDRESS VAR WORD 'ADDRESS WORD FOR SERIAL EEPROM
    CNTROL_BYTE VAR BYTE 'CONTROL BYTE TO SEND TO SERIAL EEPROM
    EEDEVICE VAR BYTE 'PHYSICAL DEVICE ADDRESS
    STOR_DATA VAR BYTE[128]'STORAGE DATA ARRAY

    EEDEVICE = BLOCK / 512 'SELECT WHICH PHYSICAL ADDRESS BOUNDRY & EEPROM
    ADDRESS = BLOCK << 7 'CALCULATE 12C ADDRESS TO STORE DATA TO
    CNTROL_BYTE = CNTRL_BYTE 'COPY CONTROL BYTE
    CNTROL_BYTE.1 = EEDEVICE.1 'SET LSB OF HARDWARE ADDRESS
    CNTROL_BYTE.2 = EEDEVICE.2 'SET MSB OF HARDWARE ADDRESS
    CNTROL_BYTE.3 = EEDEVICE.0 'SET 64K BLOCK BIT
    I2CWRITE SDA,SCL,CNTROL_BYTE,ADDRESS,[STR STOR_DATA\128] 'SAVE DATA TO 12C
    PAUSE 6 'ALLOW TIME FOR I2C WRITE ~5Ms.

    Also a MAXIMUM resistance on each SCL and SDA lines to VCC of 2.2k. The faster the bus speed the smaller the resistance.

    Dave Purola,
    Dave Purola,
    N8NTA
    EN82fn

  12. #12
    Join Date
    Feb 2012
    Posts
    64


    Did you find this post helpful? Yes | No

    Default Re: Problem reading 24FC1025 EEPROM with 18f14k22

    Dave & DEMON,
    Problem solved! I added the 10k pull-up resistor to the SCL line as you suggested and everything started working. I did have a 10k on both the SCL and SDA lines originally, but at that time I must have had something else wrong. I checked the datasheet which only stated pullup of 2k-10k on the SDA line so I removed the SCL pull-up and never put it back. I was able to fully load the EEPROM and now I can read an entire string from EEPROM at a time (Much better than the ShiftIn/Out way). I guess since the Shiftin/out was working I assumed the electronics was correct. I have used these EEPROMS in the past and never had an issue. I guess I should have looked at my old schematics before pointing the finger at Pic Basic!

    Thank you all for the help!

    Jim

    Quote Originally Posted by JimAvanti View Post
    I am running at 16MHz with the Internal OSC. I do have a 10k pullup on the SDA line. I tried a 2k as well and it did the same thing. I don't have any pullups on the SCL line now, but I did try that before with no luck. I will try it again. I may drop a 16f690 in for testing purposes (Pin compatable with the 18f14k22 and I know they work with this EEPROM).

Similar Threads

  1. 18F14k22 eTouch
    By warrier in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 28th July 2009, 06:20
  2. Problem reading 93c46 EEprom
    By dj.lambert in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 27th March 2009, 07:10
  3. Reading eeprom
    By Lotondo in forum Off Topic
    Replies: 1
    Last Post: - 21st February 2007, 18:37
  4. problem of reading eeprom 24lc515
    By mike12 in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 1st January 2006, 18:36
  5. Writing / Reading EEPROM 24LC256 Problem
    By schmoddel in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 27th February 2004, 19:55

Members who have read this thread : 1

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts