Facing problems when working on 16Mhz


(Daniel kirubakaran) #1

Some codes are not working at 16Mhz in arduino ide.
Example : I used the following code using software i2c, it worked well in 256Mhz but not working in 16Mhz may i know the reason why?

EEPROM used 24LC512

#include <SlowSoftWire.h>

SlowSoftWire Wire = SlowSoftWire(2, 3);

#define EEPROM_I2C_ADDRESS 0x50
// address 33 , 34, 35 has characters “j” “m” “B”
void setup()
{
Serial.begin(57600);
Wire.begin();
Wire.setClock(400000L); // not setting this clock also works well
delay(250);

int address1 = 33;
// byte val = 110;
int address2 = 34;
// byte val2 = 25;
int address3 = 35;
//writeAddress(address1, val);
// writeAddress(address2, val2);
byte readVal = readAddress(address1);
byte readVal2 = readAddress(address2);
byte readVal3 = readAddress(address3);
Serial.print("The returned value1 is ");
Serial.println(readVal);
Serial.print("The returned value2 is ");
Serial.println(readVal2);
Serial.print("The returned value3 is ");
Serial.println(readVal3);

}

void loop()
{

}
void writeAddress(int address, byte val)
{
Wire.beginTransmission(EEPROM_I2C_ADDRESS);
Wire.write((int)(address >> 8)); // MSB
Wire.write((int)(address & 0xFF)); // LSB

Wire.write(val);
Wire.endTransmission();

delay(5);
}

byte readAddress(int address)
{
byte rData = 0xFF;

Wire.beginTransmission(EEPROM_I2C_ADDRESS);

Wire.write((int)(address >> 8)); // MSB
Wire.write((int)(address & 0xFF)); // LSB
Wire.endTransmission();
Wire.requestFrom(EEPROM_I2C_ADDRESS, 1);

rData = Wire.read();

return rData;
}