avr-chat
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-chat] EEprom Read on Tiny13


From: Robert von Knobloch
Subject: [avr-chat] EEprom Read on Tiny13
Date: Mon, 22 Oct 2007 09:47:02 +0200
User-agent: Thunderbird 1.5.0.12 (X11/20060911)

I have solved my problem reading the EEPROM. Here is the answer in case
it helps anyone.
The library functions, defined in "avr-libc-1.4.6/libc/misc/eeprom.S"
always write a 16-Bit address to the EEAR register. This is expressly
forbidden in the Tiny13 datasheet and is the cause of my problems.
My solution was to edit eeprom.S and recompile avr-libc with the
following amendments (starred):

........
#define _EELABEL(x) CONCAT1(__,CONCAT1(x, CONCAT1
(_,__EEPROM_REG_LOCATIONS__)))

/* the same library is used for 2313 and 8515 for now -
   I hope writing 0 to non-existent EEARH doesn't hurt... */

/* AVR Data sheet fot ATTiny13 forbids writing to this reserved address
- RvK */ 
/* Therefore comment out the next 3 lines ******* This may break other
devices ******* */

// #ifndef EEARH
// #define EEARH (EEARL+1)
// #endif


#ifdef L_eeprom_read_byte
/* read one byte from EEPROM.
   addr = r26:r27, result = __tmp_reg__
   Post increment r26:r27.  */

    .section .text.eeprom, "ax", @progbits
    .global _EELABEL(eeprom_read_byte)

_EELABEL(eeprom_read_byte):
    sbic    _SFR_IO_ADDR(EECR), EEWE
    rjmp    _EELABEL(eeprom_read_byte)    /* make sure EEPROM is ready */
#ifdef EEARH
    out    _SFR_IO_ADDR(EEARH),r27
#endif
    out    _SFR_IO_ADDR(EEARL),r26
    sbi    _SFR_IO_ADDR(EECR), EERE
//    adiw    r26,1 /* Increment x register */ /* ******* Wrong place
for the address increment -RvK ******* */
    in    __tmp_reg__, _SFR_IO_ADDR(EEDR)
    ret
#endif /* L_eeprom_read_byte */

#ifdef L_eeprom_read_word
/* read one word from EEPROM.
   addr = r26:r27, result = r30:r31
   Post increment r26:r27.  */

    .section .text.eeprom, "ax", @progbits
    .global _EELABEL(eeprom_read_word)

_EELABEL(eeprom_read_word):
    rcall _EELABEL(eeprom_read_byte)
    mov r30,__tmp_reg__
adiw    r26,1 /* Increment x register  /* ******* Better place for the
address increment - it doesn't waste 2 cycles in a single byte read
******* */
    rcall _EELABEL(eeprom_read_byte)
    mov r31,__tmp_reg__
    ret
#endif
......

Also the header file "avr-libc-1.4.6/include/avr/iotn13.h" must be
amended at line 103 "EIN1D" should read "AIN1D".

As far as I can tell (I have not studied all of the ioxxyy.h header
files) processors with 8-bit eeprom address registers are defined as
having EEAR and EEARL (why this one - I don't know) and processors with
16-bit registers are defined with EEARL and EEARH so my changes seem to
be OK as EEARH being defined is unique to 16.bit machines, at least for
the processors I studied.
Hope this helps somebody,

Robert von Knobloch




reply via email to

[Prev in Thread] Current Thread [Next in Thread]