Hot!PIC18F4520 with external EEPROM

Author
john_ive
New Member
  • Total Posts : 15
  • Reward points : 0
  • Joined: 2017/05/22 22:22:08
  • Location: 0
  • Status: offline
2017/08/09 21:12:09 (permalink)
0

PIC18F4520 with external EEPROM

In home automation project i'm using PIC18F4520 chip.In that for backup,i'm using external EEPROM 24LC512 to store the datas.
It working fine.I wrote 189 in 1st EEPROM's address and 240 in 2nd EEPROM's address.

When I read the data from both address means I can get 189,but I can't get 240 from storage.
My doubts are:
1.Is this possible to write three digit number in EEPROM's address
2.Writing three digit number at an address is same as writing single digit..?
3.Is this affect the total write/read cycle.
4.why I can't get 240 from the EEPROM.


#1

18 Replies Related Threads

    qhb
    Superb Member
    • Total Posts : 5492
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: online
    Re: PIC18F4520 with external EEPROM 2017/08/09 21:17:35 (permalink)
    +3 (3)
    john_ive
    1.Is this possible to write three digit number in EEPROM's address

    It is not the number of digits that matter, it's the number of bits.
    Each location can store a byte, which is 8 bits. That is any value from 0 to 255.
     

    2.Writing three digit number at an address is same as writing single digit..?

    See previous answer.
     

    3.Is this affect the total write/read cycle.

    Each write counts, regardless of the value written.
     

    4.why I can't get 240 from the EEPROM.

    There's a bug in your code, which you didn't bother showing to us.
     
    #2
    john_ive
    New Member
    • Total Posts : 15
    • Reward points : 0
    • Joined: 2017/05/22 22:22:08
    • Location: 0
    • Status: offline
    Re: PIC18F4520 with external EEPROM 2017/08/09 22:14:10 (permalink)
    +1 (1)
    sorry qhb their was an mistake in code to read 240.Now it was rectified.
     
    Let us assume writing two datas in 1,2 address of EEPROM.
    At these location(1,2) data will be overwrite at periodic time interval.The write/read cycle for the two address are different or if any one of the address reached its maximum write/read cycle means,remaining will affect..?
     
    How to find the address to store the data in EEPROM..?I can't find any address details.
    #3
    qhb
    Superb Member
    • Total Posts : 5492
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: online
    Re: PIC18F4520 with external EEPROM 2017/08/09 22:22:36 (permalink)
    +3 (3)
    john_ive
    sorry qhb their was an mistake in code to read 240.Now it was rectified.

    I was pretty sure there would be. ;)
     

    Let us assume writing two datas in 1,2 address of EEPROM.
    At these location(1,2) data will be overwrite at periodic time interval.The write/read cycle for the two address are different or if any one of the address reached its maximum write/read cycle means,remaining will affect..?

    In general, you can overwrite EACH location one million times, but you should be designing to get nowhere near this figure.
     

    How to find the address to store the data in EEPROM..?I can't find any address details.

    I have no idea what you are trying to ask.
    A 24LC512 has 64 kilobytes of storage in it. It is totally up to you what you put in each location.
    This chip seems like a huge overkill if you only want to store two bytes.
     
    #4
    john_ive
    New Member
    • Total Posts : 15
    • Reward points : 0
    • Joined: 2017/05/22 22:22:08
    • Location: 0
    • Status: offline
    Re: PIC18F4520 with external EEPROM 2017/08/10 00:13:21 (permalink)
    0
    While I'm writing data to EEPROM's memory,we will use an address to store the data to EEPROM.
    See this code:eeprom_write(6, a);
    Here 6 is address,"a" is the data.
     
    My doubt is for mentioning the address(6 - from code) we can use simple numbers like 1,2,3... or it having some specific address like 0A,1A... like this...
     
     
    #5
    qhb
    Superb Member
    • Total Posts : 5492
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: online
    Re: PIC18F4520 with external EEPROM 2017/08/10 00:24:50 (permalink)
    +3 (3)
    As I said, it's YOUR choice.
    You added the EEPROM. What you put into it is your decision, and WHERE you put it is also your decision.
    The whole EEPROM is yours do use as you want.
    You have not shown the code for that function. Are you sure it is accessing the external EEPROM, and not the EEPROM inside the PIC?
    Is there any reason why you are NOT using the EEPROM inside the PIC?
     
    #6
    john_ive
    New Member
    • Total Posts : 15
    • Reward points : 0
    • Joined: 2017/05/22 22:22:08
    • Location: 0
    • Status: offline
    Re: PIC18F4520 with external EEPROM 2017/08/10 00:49:05 (permalink)
    0
    Yes qhb,you are correct I can choose everything.
    But I'm in small confusion if I'm going to use 12 address means,shall i declare like 1,2,3,4,5...12 or after 10 I have to use like 0A,A1,A2 like that.
    see this image its PIC16F877A's data sheet.In that for address they mentioned sequence of numbers.Like this we have to use or we can simple use 1,2,3,4.....?

    Attached Image(s)

    #7
    1and0
    Access is Denied
    • Total Posts : 6838
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: PIC18F4520 with external EEPROM 2017/08/10 00:55:59 (permalink)
    +3 (3)
    Like @qhb said, the 24LC512 has 64K bytes. So the address is from 0 to 65535 in decimal or 0x0000 to 0xFFFF in hexadecimal. These address values take 16 bits to represent; that is two bytes to transmit to the eeprom.
     
     
    #8
    qhb
    Superb Member
    • Total Posts : 5492
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: online
    Re: PIC18F4520 with external EEPROM 2017/08/10 01:29:52 (permalink)
    +3 (3)
    john_ive
    Yes qhb,you are correct I can choose everything.
    But I'm in small confusion if I'm going to use 12 address means,shall i declare like 1,2,3,4,5...12 or after 10 I have to use like 0A,A1,A2 like that.

    They are different ways of representing the same numbers.
    You could pass 10 or 0x0A, and it would represent the same address, they are just normal C numbers
     

    see this image its PIC16F877A's data sheet.In that for address they mentioned sequence of numbers.Like this we have to use or we can simple use 1,2,3,4.....?

    That is the internal RAM memory. That has no relation to what you place into your EEPROM.
    #9
    1and0
    Access is Denied
    • Total Posts : 6838
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: PIC18F4520 with external EEPROM 2017/08/10 01:36:24 (permalink)
    +3 (3)
    If you are still confused, decimal number like 10 or hexadecimal like 0x0A are for human. An 8-bit PIC device sees only binary number 0b00001010. These are just different ways of representing numbers: 10 = 0x0A = 0b00001010.
     
    <edit> It is like "hello" in English = "hola" in Spanish = "bonjour" in French.
    post edited by 1and0 - 2017/08/10 01:39:36
    #10
    john_ive
    New Member
    • Total Posts : 15
    • Reward points : 0
    • Joined: 2017/05/22 22:22:08
    • Location: 0
    • Status: offline
    Re: PIC18F4520 with external EEPROM 2017/09/07 02:38:23 (permalink)
    0
    Friends,
    I used PIC18F4520 smd in my project.For loading the program into chip I provided pins to connect with PICKIT2.But When I tried to load the program into controller all other circuits are switched on which linked with controller and I can't load the program into chip.
     
    But I observed in so many board they are provided with header pins to load the program.
    #11
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 1202
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: PIC18F4520 with external EEPROM 2017/09/07 05:14:36 (permalink)
    +1 (1)
    Bad Wiring, without a circuit diagram it could be anything.

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #12
    qhb
    Superb Member
    • Total Posts : 5492
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: online
    Re: PIC18F4520 with external EEPROM 2017/09/07 14:35:34 (permalink)
    +1 (1)
    It sounds like you connected other things to the PGD and PGC pins, and assumed powered down chips wouldn't load those pins. That's a rookie mistake.
     
    As Gort suggested, show us your schematic, and we may be able to suggest some solutions.
     
    #13
    john_ive
    New Member
    • Total Posts : 15
    • Reward points : 0
    • Joined: 2017/05/22 22:22:08
    • Location: 0
    • Status: offline
    Re: PIC18F4520 with external EEPROM 2017/09/08 06:10:46 (permalink)
    0
     
     
    void eeprom_init(){
    SCL_DIR = 1; //Set C3 & C4 as input pins
    SDA_DIR = 1;
    SSPADD = 49; //Baud Rate = 100KHz @20.000MHz clock
    //SSP1ADD = (Fosc/BitRate)/4-1 = 20M/100k/4 - 1 = 49
    SSPSTAT = 0b10000000; //Disable slew rate control for 100kHz speed
    SSPCON2 = 0b000000000; //Clear flags
    SSPCON1 = 0b00101000; //Master mode, Enable I2C
    // SSPCON1 = 0b00100001; //Master mode, Enable I2C
    }
     
    PIC18F4520 connected with 24LC512 External EEPROM.
    By using this function to connect with external EEPROM.But while writing datas some of the datas  are skipping to write in the EEPROM.I tired it but I can't find any solution.Please give me solution to solve this problem.
     
    I'm using 20MHZ crystal for controller
    #14
    jack@kksound
    code tags!
    • Total Posts : 1990
    • Reward points : 0
    • Joined: 2014/05/14 10:03:19
    • Location: 0
    • Status: offline
    Re: PIC18F4520 with external EEPROM 2017/09/08 07:48:26 (permalink)
    +1 (1)
    while writing datas some of the datas  are skipping to write

    You must wait for the eeprom write cycle to finish before starting the next write.
    #15
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 1202
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: PIC18F4520 with external EEPROM 2017/09/08 08:42:00 (permalink)
    +1 (1)
    Look at the 24LC512 pdf again.  You won't get a response if it is busy.
    wait_ack:
        call    _startI2C
        mov     ChipSel,w0
        call    _writeI2C
        btsc    I2C1STAT,#ACKSTAT
        bra     wait_ack
        call    _stopI2C
        retlw   #EPERROR_OK,w0




    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #16
    john_ive
    New Member
    • Total Posts : 15
    • Reward points : 0
    • Joined: 2017/05/22 22:22:08
    • Location: 0
    • Status: offline
    Re: PIC18F4520 with external EEPROM 2017/09/09 02:52:07 (permalink)
    0
    Friends how to upload image for reference sorry for inconvenient.I can't find the upload option to upload image from computer
     
    #17
    john_ive
    New Member
    • Total Posts : 15
    • Reward points : 0
    • Joined: 2017/05/22 22:22:08
    • Location: 0
    • Status: offline
    Re: PIC18F4520 with external EEPROM 2017/09/13 02:59:41 (permalink)
    +1 (1)
    While trying to upload image for reference means i'm facing
    " You don't have permission to access "http://www.microchip.com/forums/upload.aspx?" on this server.
    Reference #18.25460317.1505296700.de2f8c"
    this error on upload page..Please provide the way to upload the image or to solve the issue..
    #18
    katela
    Super Member
    • Total Posts : 454
    • Reward points : 0
    • Joined: 2013/06/11 05:25:18
    • Location: South Africa
    • Status: online
    Re: PIC18F4520 with external EEPROM 2017/09/13 05:06:48 (permalink)
    +1 (1)
    john_ive
    While trying to upload image for reference means i'm facing
    " You don't have permission to access "http://www.microchip.com/forums/upload.aspx?" on this server.
    Reference #18.25460317.1505296700.de2f8c"
    this error on upload page..Please provide the way to upload the image or to solve the issue..


    Try to read this thread maybe it can assist you: http://www.microchip.com/forums/m781454.aspx
     

    Free online Microcontroller Tutorials and Projects for Hobbyists and students. From beginners to advanced. Website: www.studentcompanion.co.za
    Youtube Tutorials: http://www.youtube.com/user/StudentCompanionSA/videos
    #19
    Jump to:
    © 2017 APG vNext Commercial Version 4.5