[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
Bogdan Marinescu 2013-07-29 18:20:04 +03:00
parent ade7a941e2
commit 1cd95c2467
2 changed files with 7 additions and 4 deletions

View File

@ -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;

View File

@ -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;
}
}