c - Reading EEPROM AVR -
i have problem when receive data eeprom.
first made 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 application code } }
and have extracted .hex , .eep files. wrote files avrdude. first write wrong because put .hex file on eerpom:w , destroy bytes, not important. after write using correct command , see part of data in next print screen.
i saving number , c , a001 . see in first row there ..c.a001. 9 bytes wrote.
now in program! try 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 in global struct :
typedef struct { uint16_t u16cyclicity; uint16_t u16value; char pu8name[5]; char pu8unit[2]; }eeh_layout;
in while of main sent on "broken uart"(i have topic on that). until code usart sent value , garbage..but when put usart not sending anything, , beleive cause because of 0(null) reading eeprom. cpu working because have 1 sec timer interupts blink led. working, probelm got 0 eeporm.
also not sure uderstand how write eeprom because everywhere lot of tutorials on eeprom telling how config eeprom , read. not want have params in code, want them eeprom write alone!
edit: uint16 parameter ok, manage read on uart , 2000; chars not ok, null.
edit: test ok, problem params of function not use ok. change function pau8name[] instead of *pau8name, because pointer bad initialized!!
always aware of pointers!
the problem uninitialized pointer. see edit in post!
Comments
Post a Comment