mbed library sources
Dependents: frdm_kl05z_gpio_test
Fork of mbed-src by
Diff: targets/hal/TARGET_Freescale/TARGET_K20D5M/i2c_api.c
- Revision:
- 73:299c67215126
- Parent:
- 68:41613245dfd7
- Child:
- 178:a873352662d8
diff -r 248c61396e08 -r 299c67215126 targets/hal/TARGET_Freescale/TARGET_K20D5M/i2c_api.c --- a/targets/hal/TARGET_Freescale/TARGET_K20D5M/i2c_api.c Mon Jan 13 10:45:05 2014 +0000 +++ b/targets/hal/TARGET_Freescale/TARGET_K20D5M/i2c_api.c Tue Jan 14 20:45:05 2014 +0000 @@ -18,6 +18,7 @@ #include "cmsis.h" #include "pinmap.h" #include "error.h" +#include "clk_freqs.h" static const PinMap PinMap_I2C_SDA[] = { {PTB1, I2C_0, 2}, @@ -165,10 +166,11 @@ } static int i2c_do_read(i2c_t *obj, char * data, int last) { - if (last) + if (last) { i2c_send_nack(obj); - else + } else { i2c_send_ack(obj); + } *data = (obj->i2c->D & 0xFF); @@ -184,7 +186,7 @@ uint32_t ref = 0; uint8_t i, j; // bus clk - uint32_t PCLK = 24000000u; + uint32_t PCLK = bus_frequency(); uint32_t pulse = PCLK / (hz * 2); // we look for the values that minimize the error @@ -237,9 +239,8 @@ } // If not repeated start, send stop. - if (stop) { + if (stop) i2c_stop(obj); - } // last read data[count-1] = obj->i2c->D; @@ -326,11 +327,9 @@ // read addressed case 0xE6: return 1; - // write addressed case 0xE2: return 3; - default: return 0; }