File tree Expand file tree Collapse file tree 1 file changed +6
-10
lines changed
targets/TARGET_STM/TARGET_STM32F4 Expand file tree Collapse file tree 1 file changed +6
-10
lines changed Original file line number Diff line number Diff line change @@ -404,19 +404,13 @@ void i2c_reset(i2c_t *obj) {
404
404
#if DEVICE_I2CSLAVE
405
405
406
406
void i2c_slave_address (i2c_t * obj , int idx , uint32_t address , uint32_t mask ) {
407
-
408
- uint16_t tmpreg = 0 ;
409
407
struct i2c_s * obj_s = I2C_S (obj );
408
+ I2C_HandleTypeDef * handle = & (obj_s -> handle );
410
409
I2C_TypeDef * i2c = (I2C_TypeDef * )obj_s -> i2c ;
411
410
412
- // Get the old register value
413
- tmpreg = i2c -> OAR1 ;
414
- // Reset address bits
415
- tmpreg &= 0xFC00 ;
416
- // Set new address
417
- tmpreg |= (uint16_t )((uint16_t )address & (uint16_t )0x00FE ); // 7-bits
418
- // Store the new register value
419
- i2c -> OAR1 = tmpreg ;
411
+ // I2C configuration
412
+ handle -> Init .OwnAddress1 = address ;
413
+ HAL_I2C_Init (handle );
420
414
}
421
415
422
416
void i2c_slave_mode (i2c_t * obj , int enable_slave ) {
@@ -429,6 +423,8 @@ void i2c_slave_mode(i2c_t *obj, int enable_slave) {
429
423
430
424
/* Enable Address Acknowledge */
431
425
i2c -> CR1 |= I2C_CR1_ACK ;
426
+ } else {
427
+ obj_s -> slave = 0 ;
432
428
}
433
429
}
434
430
You can’t perform that action at this time.
0 commit comments