mirror of https://github.com/ARMmbed/mbed-os.git
[KL25Z] Fix clock generation for I2C and SPI
Don't set a clock higher than the one requested for the I2C and SPI interfaces, even if this setting is the closest to the requested one. This was causing some issues with the EEPROM test and possibly other issues with the SPI SD test.pull/17/merge
parent
ade7a941e2
commit
1cd95c2467
|
|
@ -202,7 +202,9 @@ void i2c_frequency(i2c_t *obj, int hz) {
|
|||
for (i = 1; i < 5; i*=2) {
|
||||
for (j = 0; j < 0x40; j++) {
|
||||
ref = PCLK / (i*ICR[j]);
|
||||
error = (ref > hz) ? ref - hz : hz - ref;
|
||||
if (ref > hz)
|
||||
continue;
|
||||
error = hz - ref;
|
||||
if (error < p_error) {
|
||||
icr = j;
|
||||
mult = i/2;
|
||||
|
|
|
|||
|
|
@ -127,15 +127,16 @@ void spi_frequency(spi_t *obj, int hz) {
|
|||
|
||||
for (prescaler = 1; prescaler <= 8; prescaler++) {
|
||||
divisor = 2;
|
||||
for (spr = 0; spr <= 8; spr++) {
|
||||
for (spr = 0; spr <= 8; spr++, divisor *= 2) {
|
||||
ref = PCLK / (prescaler*divisor);
|
||||
error = (ref > hz) ? ref - hz : hz - ref;
|
||||
if (ref > hz)
|
||||
continue;
|
||||
error = hz - ref;
|
||||
if (error < p_error) {
|
||||
ref_spr = spr;
|
||||
ref_prescaler = prescaler - 1;
|
||||
p_error = error;
|
||||
}
|
||||
divisor *= 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue