Like this:
union LongIntOr4Bytes {
uint32_t longInt;
byte bytes[4];
};
//----------------------------------SRAM WRITE Function---------------------------------------------------//
void sramWrite(uint32_t intVal) {
union LongIntOr4Bytes longOrBytes;
longOrBytes.longInt = intVal;
RTC.writeEN(true);
if (RTC.writeEN())
Serial.println("ready");
else
Serial.println("No write");
for (int i = 0; i < 4; i++) {
RTC.writeRTC(DS1302_RAM_START + (i << 1), longOrBytes.bytes[i]);
}
}
//------------------------------------SRAM READ Function-----------------------------------------------//
uint32_t sramRead()
{
union LongIntOr4Bytes longOrBytes;
for (int x = 0; x < 4; x++) {
longOrBytes.bytes[x] = RTC.readRTC(DS1302_RAM_START + (x << 1));
}
return longOrBytes.longInt;
}