Hello!
Since Nano33 BLE does't have an EEPROM, I am trying to store a value to external EEPROM on DS3231. The code compile without error but after upload, the Com port dissapear and my pc doesn't recognize arduino board anymore. To get the board back I need to press reset button twice and upload a new sketch. Here is a code that I found on a Forum and should work:
#include <RtcDS3231.h>
#include <Wire.h>
#define EEPROM_I2C_ADDRESS 0x57
byte sum = 123;
int readVal = 0;
void setup() {
Serial.begin(9600);
writeEEPROM(0, sum, EEPROM_I2C_ADDRESS);
}
void loop() {
// put your main code here, to run repeatedly:
readVal = readEEPROM(0, EEPROM_I2C_ADDRESS);
Serial.println(readVal);
delay(5000);
}
void writeEEPROM(int address, byte sum, int i2c_address){
// Begin transmission to I2C EEPROM
Wire.beginTransmission(i2c_address);
// Send memory address as two 8-bit bytes
Wire.write((int)(address >> 8)); // MSB
Wire.write((int)(address & 0xFF)); // LSB
// Send data to be stored
Wire.write(sum);
// End the transmission
Wire.endTransmission();
// Add 5ms delay for EEPROM
delay(5);
}
byte readEEPROM(int address, int i2c_address){
// Define byte for received data
byte rcvData = 0x00;
// Begin transmission to I2C EEPROM
Wire.beginTransmission(i2c_address);
// Send memory address as two 8-bit bytes
Wire.write((int)(address >> 8)); // MSB
Wire.write((int)(address & 0xFF)); // LSB
// End the transmission
Wire.endTransmission();
// Request one byte of data at current memory address
Wire.requestFrom(i2c_address, 1);
// Read the data and assign to variable
rcvData = Wire.read();
// Return the data as function output
return rcvData;
}
Does anyone have any working example for Nano 33 BLE?