Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <EEPROM.h>
- void EEPROMWrite32bit(uint8_t address, uint32_t value)
- {
- uint8_t bytes[4];
- bytes[0] = (value >> 24) & 0xFF;
- bytes[1] = (value >> 16) & 0xFF;
- bytes[2] = (value >> 8) & 0xFF;
- bytes[3] = value & 0xFF;
- for (int i=0; i < 4; i++)
- {
- EEPROM.write(address + i, bytes[i]);
- }
- }
- uint32_t EEPROMRead32bit(uint8_t address)
- {
- // Crucial point: Values are shifted in place, so variable needs to be able to contain the shifted value
- uint32_t bytes[4];
- uint32_t value;
- for (int i=0; i < 4; i++)
- {
- bytes[i] = EEPROM.read(address + i);
- }
- value = (bytes[3] + (bytes[2] << 8) + (bytes[1] << 16) + (bytes[0] << 24));
- return value;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement