• AVR Freaks

Hot!ATTINY25 EEPROM READ/WRITE

Author
FerrariLuigi
Starting Member
  • Total Posts : 63
  • Reward points : 0
  • Joined: 2015/07/16 11:19:30
  • Location: 0
  • Status: offline
2020/05/24 10:48:56 (permalink)
0

ATTINY25 EEPROM READ/WRITE

Dear all,
I have a little problem with ATTINY25 EEPROM
I developed a very simple program
 
#include <stdio.h>
#include <stdlib.h>
#include <avr/sfr_defs.h>
#include <avr/io.h>
#include <avr/eeprom.h>


unsigned char EEPROM_read(unsigned char ucAddress){
    /* Wait for completion of previous write */
    while(EECR & (1<<EEPE));
    /* Set up address register */
    EEAR = ucAddress;
    /* Start eeprom read by writing EERE */
    EECR |= (1<<EERE);
    /* Return data from data register */
    return EEDR;
}
void EEPROM_write(unsigned char ucAddress, unsigned char ucData){
        /* Wait for completion of previous write */
    while(EECR & (1<<EEPE));
    /* Set Programming mode */
    EECR = (0<<EEPM1)|(0<<EEPM0);
    /* Set up address and data registers */
    EEAR = ucAddress;
    EEDR = ucData;
    /* Write logical one to EEMPE */
    EECR |= (1<<EEMPE);
    /* Start eeprom write by setting EEPE */
    EECR |= (1<<EEPE);
}

unsigned char Parameters;
unsigned char Parameters1;

int main(int argc, char** argv) {
    EEPROM_write((unsigned char)0, Parameters);
    Parameters1=EEPROM_read(0);
    while(1);
            
    return (EXIT_SUCCESS);
}

 
The routines EEPROM_write and EEPROM_read are copyed and paste from ATTYNY 25/45/85 data sheet.

The program should write 5 in the first location of EEPROM and then read the same location.

Unfortunately after reading Parameters1 value is 0xff and no data is written into EEPROM (I read it fom MPLAB-X IDE Windoes->Target memory vew->EEPROM memory)
 
Did you have a similar problem ? How did you fix it ?
Thank you very much for your help and cooperation
regards
Luigi Ferrari
 
 
 
 
#1

6 Replies Related Threads

    upand_at_them
    Super Member
    • Total Posts : 576
    • Reward points : 0
    • Joined: 2005/05/16 07:02:38
    • Location: Pennsylvania
    • Status: offline
    Re: ATTINY25 EEPROM READ/WRITE 2020/05/24 11:21:13 (permalink)
    +2 (2)
    It doesn't look like you're setting the value of "Parameters".  So that uninitialized value (probably 0xff) is what gets passed to the "write" function.
    #2
    ric
    Super Member
    • Total Posts : 27929
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: ATTINY25 EEPROM READ/WRITE 2020/05/24 13:32:25 (permalink)
    +1 (1)
    FerrariLuigi
    The program should write 5 in the first location of EEPROM and then read the same location.



    As above. This value "5" does not appear anywhere in your source code...
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #3
    FerrariLuigi
    Starting Member
    • Total Posts : 63
    • Reward points : 0
    • Joined: 2015/07/16 11:19:30
    • Location: 0
    • Status: offline
    Re: ATTINY25 EEPROM READ/WRITE 2020/05/24 15:30:30 (permalink)
    0
    Ok. thank you. I modified the software inserting the initialization of Parameters
    Parameters=5;
    before calling EEPROM_write((unsigned char)0, Parameters);
    without success
     
     
    #4
    ric
    Super Member
    • Total Posts : 27929
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: ATTINY25 EEPROM READ/WRITE 2020/05/24 15:37:42 (permalink)
    +1 (1)
    Does the compiler allow you to place an initial value into the EEPROM so you can test your read routine?
    Or alternatively, can you read out the EEPROM memory with the programmer to see if your write routine is working?
    Otherwise you have two unknowns, and you don't know which one is at fault.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #5
    ric
    Super Member
    • Total Posts : 27929
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: ATTINY25 EEPROM READ/WRITE 2020/05/24 15:40:21 (permalink)
    +1 (1)

    Unfortunately after reading Parameters1 value is 0xff and no data is written into EEPROM (I read it fom MPLAB-X IDE Windoes->Target memory vew->EEPROM memory)

    The EEPROM view in MPLABX is not a live view.
    You must tell it to read the info from the chip if code running in the chip has changed the memory.
     
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #6
    FerrariLuigi
    Starting Member
    • Total Posts : 63
    • Reward points : 0
    • Joined: 2015/07/16 11:19:30
    • Location: 0
    • Status: offline
    Re: ATTINY25 EEPROM READ/WRITE 2020/05/27 00:13:52 (permalink)
    0
    Ok, thank you. I solved the problem.
    I moved the project from MPLAB-X to AtmelStudio 7 and it works.
    Then I moved back the project from AtmelStudio7 to MPLAB-X and it works.
     
    Thank you.
    regards,
     
    #7
    Jump to:
    © 2020 APG vNext Commercial Version 4.5