0

I have a problem when I receive data from the eeprom.

first I made the following code :

#include <avr/io.h>
#include <avr/eeprom.h>

char     NAME[5]   EEMEM   = "a001";
char     UNIT[2]   EEMEM   = "C";
uint16_t CYCLICITY EEMEM   = 2000;

int main(void)
{
    while(1)
    {
        //TODO:: Please write your application code 
    }
}

and from this I have extracted a .hex and .eep files. Then I wrote this files with avrdude. First I write this wrong because I put only the .hex file on eerpom:w and I destroy some bytes, this is not so important. After that I write using the correct command and I see part of the data like in the next print screen.

dumpeeprom

I am saving a number , a C and a001 . As you see in the first row there is ..C.a001. which are the 9 bytes I wrote.

now in another program! I try to do this:

char     EEMEM NAME[5]  ;  
char     EEMEM UNIT[2]  ;
uint16_t EEMEM CYCLICITY; 

void _vReadEEPROM(char *au8Name,char *au8Unit,uint16_t *u16Cyclicity)
{
  eeprom_read_block((void *)&au8Name,(const void *)NAME,5);
  eeprom_read_block((void *)&au8Unit,(const void *)UNIT,2);
  *u16Cyclicity = eeprom_read_word(&CYCLICITY);
}

The parametres are in a global struct :

typedef struct 
{
    uint16_t u16Cyclicity;
    uint16_t u16Value;
    char     pu8Name[5];
    char     pu8Unit[2];
}EEH_layout;

In the while of the main I sent on the "Broken UART"(I have another topic on that). Until this code the USART sent the good value and garbage..but when I put this the USART is not sending anything, and as I beleive this is cause because of a 0(null) reading from eeprom. The CPU is working because I have a 1 sec timer that interupts to blink a led. THis is working, so the probelm is that I got 0 from EEPORM.

ALSO I AM NOT SURE I UDERSTAND HOW TO WRITE THE EEPROM BECAUSE EVERYWHERE ARE A LOT OF TUTORIALS ON EEPROM BUT NOWHERE IS TELLING HOW TO CONFIG EEPROM AND ONLY READ. I do not want to have this params in my code, I want them from eeprom that I will write alone!

EDIT: the uint16 parameter is ok, I manage to read it over UART and it is 2000; But the chars are not ok, it is null.

EDIT: TEST OK, the problem was that the params of function was not use ok. I change the function with pau8Name[] instead of *pau8Name, because the pointer wAS bad initialized!!

Community
  • 1
  • 1
  • YES the data is on the first row. D0 07 is 7D0 which is 2000 dec , what I have wrote. 43 00 is C and the \0, 61 30 30 31 00 is a001 and a \0 – Marian-Emanuel Ionascu Jun 09 '14 at 19:09
  • Try making your program itself dump out the first 16 bytes in hex over the UART the way avrdude is and see if that looks as expected. – Chris Stratton Jun 09 '14 at 19:13
  • I am trying this but with no success. Also, if I hit debug mode in AVR Studio(which I believe it simulates my uc) it says that eeprom has 9 bytes of 0. All I got is 0. – Marian-Emanuel Ionascu Jun 09 '14 at 19:54
  • Skip the eprom and test communication by making it print constants or count. Then look at the library source and see if it can block waiting for the eprom or something. – Chris Stratton Jun 09 '14 at 21:13
  • Generally, reading a EEPROM requires a bit of special coding (which is probably buried in the functions eeprom_read_block() and eeprom_read_word() However, the parameters usually sent into those functions would be offset/address within the EEPROM + the data length. I don't see the offset/address being set/used in your function. – user3629249 Jun 09 '14 at 22:12
  • I used the EEMEM parameter that must be ok for the addres. I have a new info, the last parameter wich is an integer is ok, it seams the blok read is not good – Marian-Emanuel Ionascu Jun 10 '14 at 17:59

1 Answers1

0

Always be aware of pointers!

The problem was with the uninitialized pointer. See EDIT in post!