File tree Expand file tree Collapse file tree 3 files changed +25
-3
lines changed
hal/targets/hal/TARGET_STM/TARGET_STM32F4
libraries/tests/mbed/i2c_master_slave Expand file tree Collapse file tree 3 files changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -213,8 +213,19 @@ inline int i2c_start(i2c_t *obj) {
213
213
214
214
inline int i2c_stop (i2c_t * obj ) {
215
215
216
+ int timeout ;
216
217
struct i2c_s * obj_s = I2C_S (obj );
217
218
I2C_TypeDef * i2c = (I2C_TypeDef * )obj_s -> i2c ;
219
+ I2C_HandleTypeDef * handle = & (obj_s -> handle );
220
+
221
+ //Wait Byte transfer finished before sending stop
222
+ timeout = FLAG_TIMEOUT ;
223
+ while (__HAL_I2C_GET_FLAG (handle , I2C_FLAG_BTF ) == RESET ) {
224
+ timeout -- ;
225
+ if (timeout == 0 ) {
226
+ return 0 ;
227
+ }
228
+ }
218
229
219
230
// Generate the STOP condition
220
231
i2c -> CR1 |= I2C_CR1_STOP ;
@@ -350,15 +361,21 @@ int i2c_byte_write(i2c_t *obj, int data) {
350
361
351
362
handle -> Instance -> DR = (uint8_t )data ;
352
363
353
- // Wait until the byte is transmitted
364
+ // Wait until the byte (might be the adress) is transmitted
354
365
timeout = FLAG_TIMEOUT ;
355
366
while ((__HAL_I2C_GET_FLAG (handle , I2C_FLAG_TXE ) == RESET ) &&
356
- (__HAL_I2C_GET_FLAG (handle , I2C_FLAG_BTF ) == RESET )) {
367
+ (__HAL_I2C_GET_FLAG (handle , I2C_FLAG_BTF ) == RESET ) &&
368
+ (__HAL_I2C_GET_FLAG (handle , I2C_FLAG_ADDR ) == RESET )) {
357
369
if ((timeout -- ) == 0 ) {
358
370
return 0 ;
359
371
}
360
372
}
361
373
374
+ if (__HAL_I2C_GET_FLAG (handle , I2C_FLAG_ADDR ) != RESET )
375
+ {
376
+ __HAL_I2C_CLEAR_ADDRFLAG (handle );
377
+ }
378
+
362
379
return 1 ;
363
380
}
364
381
Original file line number Diff line number Diff line change 16
16
// pull-up resistors on both lines
17
17
// ********************************************************
18
18
19
+ #if defined(TARGET_NUCLEO_F411RE)
20
+ I2C master (PB_9, PB_8); // I2C_1 (Arduino: D14/D15)
21
+ I2CSlave slave (PB_3, PB_10); // I2C_2 (Arduino: D3/D6)
22
+ #endif
19
23
20
24
int main ()
21
25
{
Original file line number Diff line number Diff line change 87
87
88
88
* i2c_loop:
89
89
* LPC1768: (p28 <-> p9), (p27 <-> p10)
90
+ * NUCLEO_F411RE: (PB_9 <-> PB_3), (PB_8 <-> PB_10)
90
91
91
92
* i2c_eeprom:
92
93
* LPC1*: (SDA=p28 , SCL=p27)
264
265
"id" : "MBED_A20" , "description" : "I2C master/slave test" ,
265
266
"source_dir" : join (TEST_DIR , "mbed" , "i2c_master_slave" ),
266
267
"dependencies" : [MBED_LIBRARIES , TEST_MBED_LIB ,],
267
- "mcu" : ["LPC1768" , "RZ_A1H" ],
268
+ "mcu" : ["LPC1768" , "RZ_A1H" , "NUCLEO_F411RE" ],
268
269
"peripherals" : ["i2c_loop" ]
269
270
},
270
271
{
You can’t perform that action at this time.
0 commit comments