Reputation: 81
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.
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!!
Upvotes: 0
Views: 1856
Reputation: 81
Always be aware of pointers!
The problem was with the uninitialized pointer. See EDIT in post!
Upvotes: 0