Looking at the Wire code for the R4 it appears that setClock(frequency) is not operational, i.e., frequency can be passed but code does not translate to the i2c rate needed.
In wire.cpp
if(is_master) {
if((WireSpeed_t)ws == SPEED_STANDARD) {
m_i2c_cfg.rate = I2C_MASTER_RATE_STANDARD;
}
else if((WireSpeed_t)ws == SPEED_FAST) {
m_i2c_cfg.rate = I2C_MASTER_RATE_FAST;
}
else if((WireSpeed_t)ws == SPEED_VERY_FAST) {
m_i2c_cfg.rate = I2C_MASTER_RATE_FASTPLUS;
}
}
ws is passed as a uint32_t but when used to set the cfg.rate it is converted to the WireSpeed_t enumerator:
typedef enum {
SPEED_STANDARD = 0, //100 kHz
SPEED_FAST, //400 kHz
SPEED_VERY_FAST //1 Mhz
} WireSpeed_t;
which will always fail if just a frequency is passed as is used in most sketches and libraries using I2C.
I can not not test directly as I won't have a minima until tomorrow and a wifi until the day after. But if I extract the code and test on different arm board:
typedef enum {
SPEED_STANDARD = 0, //100 kHz
SPEED_FAST, //400 kHz
SPEED_VERY_FAST //1 Mhz
} WireSpeed_t;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
delay(5000);
speed(SPEED_STANDARD);
speed(400000);
speed(1000000);
speed(75000);
}
void loop() {
// put your main code here, to run repeatedly:
}
void speed(uint32_t ws) {
if((WireSpeed_t)ws == SPEED_STANDARD) {
Serial.println("wire set to 100khz");
}
else if((WireSpeed_t)ws == SPEED_FAST) {
Serial.println("wire set to 400khz");
}
else if((WireSpeed_t)ws == SPEED_VERY_FAST) {
Serial.println("wire set to 1000khz");
} else {
Serial.println("Not supported");
}
}
I get
wire set to 100khz
Not supported
Not supported
Not supported
I don't think this is the desired behaviour. Would think you would pass the frequency and code would check and set the correct rate. Also would have thougth that if you passed an incorrect frequency it would either default to the closest freq and/or return an error/message.
Will be testing I2C more when I get the boards.