Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. #include <EEPROM.h>
  2.  
  3. void EEPROMWrite32bit(uint8_t address, uint32_t value)
  4. {
  5. uint8_t bytes[4];
  6.  
  7. bytes[0] = (value >> 24) & 0xFF;
  8. bytes[1] = (value >> 16) & 0xFF;
  9. bytes[2] = (value >> 8) & 0xFF;
  10. bytes[3] = value & 0xFF;
  11.  
  12. for (int i=0; i < 4; i++)
  13. {
  14. EEPROM.write(address + i, bytes[i]);
  15. }
  16. }
  17.  
  18. uint32_t EEPROMRead32bit(uint8_t address)
  19. {
  20. // Crucial point: Values are shifted in place, so variable needs to be able to contain the shifted value
  21. uint32_t bytes[4];
  22. uint32_t value;
  23.  
  24. for (int i=0; i < 4; i++)
  25. {
  26. bytes[i] = EEPROM.read(address + i);
  27. }
  28.  
  29. value = (bytes[3] + (bytes[2] << 8) + (bytes[1] << 16) + (bytes[0] << 24));
  30.  
  31. return value;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement