diff --git a/code/Makefile b/code/Makefile index 6f18ee0..6406299 100644 --- a/code/Makefile +++ b/code/Makefile @@ -2,7 +2,10 @@ all: make build make program 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: avrdude -p attiny85 -c usbtiny -U flash:w:counter + +eeprom: + avrdude -p attiny85 -c usbtiny -U eeprom:r:eeprom.hex diff --git a/code/main.c b/code/main.c index 64d7416..9206c3f 100644 --- a/code/main.c +++ b/code/main.c @@ -336,7 +336,7 @@ int main() { ++eeprom_idx; eeprom_idx %= EEPROM_SIZE; - write_eeprom_val(eeprom_idx, (uint32_t)count_value_fine, move_dir); + write_eeprom_val(eeprom_idx, (uint32_t) count_value_fine, move_dir); } count_value = (uint32_t) count_value_fine; @@ -855,7 +855,7 @@ uint16_t find_eeprom_idx() { // Check Last byte for value // 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; } @@ -891,7 +891,8 @@ void read_eeprom_val(uint16_t idx, uint32_t *value, uint8_t *dir) for (i = 0; i < 4; ++i) { curr_byte = eeprom_read_byte((uint8_t *) idx); - (*value) |= (curr_byte << (24 - 8 * i)); + (*value) <<= 8; + (*value) |= curr_byte; ++idx; idx %= EEPROM_SIZE; }