Skip to content

Commit 8d7c3da

Browse files
committed
i2c clock from global clock value, syntax corrections
1 parent fba199a commit 8d7c3da

File tree

1 file changed

+5
-7
lines changed
  • libraries/mbed/targets/hal/TARGET_Freescale/TARGET_K20D5M

1 file changed

+5
-7
lines changed

libraries/mbed/targets/hal/TARGET_Freescale/TARGET_K20D5M/i2c_api.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,11 @@ static int i2c_do_write(i2c_t *obj, int value) {
165165
}
166166

167167
static int i2c_do_read(i2c_t *obj, char * data, int last) {
168-
if (last)
168+
if (last) {
169169
i2c_send_nack(obj);
170-
else
170+
} else {
171171
i2c_send_ack(obj);
172+
}
172173

173174
*data = (obj->i2c->D & 0xFF);
174175

@@ -184,7 +185,7 @@ void i2c_frequency(i2c_t *obj, int hz) {
184185
uint32_t ref = 0;
185186
uint8_t i, j;
186187
// bus clk
187-
uint32_t PCLK = 24000000u;
188+
uint32_t PCLK = SystemCoreClock/2;
188189
uint32_t pulse = PCLK / (hz * 2);
189190

190191
// we look for the values that minimize the error
@@ -237,9 +238,8 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
237238
}
238239

239240
// If not repeated start, send stop.
240-
if (stop) {
241+
if (stop)
241242
i2c_stop(obj);
242-
}
243243

244244
// last read
245245
data[count-1] = obj->i2c->D;
@@ -326,11 +326,9 @@ int i2c_slave_receive(i2c_t *obj) {
326326
// read addressed
327327
case 0xE6:
328328
return 1;
329-
330329
// write addressed
331330
case 0xE2:
332331
return 3;
333-
334332
default:
335333
return 0;
336334
}

0 commit comments

Comments
 (0)