Added eeprom dump. Fixed incorrect reading of EEPROM

This commit is contained in:
DWW 2021-07-01 00:49:56 +03:00
parent 2bbbeec873
commit d6fa80e21f
2 changed files with 8 additions and 4 deletions

View File

@ -2,7 +2,10 @@ all:
make build make build
make program make program
build: build:
avr-gcc main.c i2c_master.c -o counter -mmcu=attiny85 avr-gcc main.c i2c_master.c -o counter -mmcu=attiny85 -Wall -Wextra
program: program:
avrdude -p attiny85 -c usbtiny -U flash:w:counter avrdude -p attiny85 -c usbtiny -U flash:w:counter
eeprom:
avrdude -p attiny85 -c usbtiny -U eeprom:r:eeprom.hex

View File

@ -855,7 +855,7 @@ uint16_t find_eeprom_idx()
{ {
// Check Last byte for value // Check Last byte for value
// FF XX ... FF ?? // FF XX ... FF ??
if (0xFF != eeprom_read_byte((uint8_t *) EEPROM_SIZE - 1)) if (0xFF != eeprom_read_byte((uint8_t *) (EEPROM_SIZE - 1)))
{ {
idx = EEPROM_SIZE - 1; idx = EEPROM_SIZE - 1;
} }
@ -891,7 +891,8 @@ void read_eeprom_val(uint16_t idx, uint32_t *value, uint8_t *dir)
for (i = 0; i < 4; ++i) for (i = 0; i < 4; ++i)
{ {
curr_byte = eeprom_read_byte((uint8_t *) idx); curr_byte = eeprom_read_byte((uint8_t *) idx);
(*value) |= (curr_byte << (24 - 8 * i)); (*value) <<= 8;
(*value) |= curr_byte;
++idx; ++idx;
idx %= EEPROM_SIZE; idx %= EEPROM_SIZE;
} }