@@ -548,6 +548,17 @@ void i2c_init_internal(i2c_t *obj, const i2c_pinmap_t *pinmap)
548548        obj_s -> hz  =  100000 ;    // 100 kHz per default 
549549    }
550550
551+     // Set remaining init parameters to defaults 
552+     obj_s -> handle .Init .AddressingMode   =  I2C_ADDRESSINGMODE_7BIT ;
553+     obj_s -> handle .Init .DualAddressMode  =  I2C_DUALADDRESS_DISABLE ;
554+     obj_s -> handle .Init .GeneralCallMode  =  I2C_GENERALCALL_DISABLE ;
555+     obj_s -> handle .Init .NoStretchMode    =  I2C_NOSTRETCH_DISABLE ;
556+     obj_s -> handle .Init .OwnAddress1      =  0 ;
557+     obj_s -> handle .Init .OwnAddress2      =  0 ;
558+ #ifdef  I2C_IP_VERSION_V2 
559+     obj_s -> handle .Init .OwnAddress2Masks  =  I2C_OA2_NOMASK ;
560+ #endif 
561+ 
551562    // Reset to clear pending flags if any 
552563    i2c_hw_reset (obj );
553564    i2c_frequency (obj , obj_s -> hz );
@@ -784,19 +795,15 @@ void i2c_frequency(i2c_t *obj, int hz)
784795    /* hz value is stored for computing timing value next time */ 
785796    obj_s -> current_hz  =  hz ;
786797#endif  // I2C_IP_VERSION_V2 
787- 
788-     // I2C configuration 
789-     handle -> Init .AddressingMode   =  I2C_ADDRESSINGMODE_7BIT ;
790-     handle -> Init .DualAddressMode  =  I2C_DUALADDRESS_DISABLE ;
791-     handle -> Init .GeneralCallMode  =  I2C_GENERALCALL_DISABLE ;
792-     handle -> Init .NoStretchMode    =  I2C_NOSTRETCH_DISABLE ;
793-     handle -> Init .OwnAddress1      =  0 ;
794-     handle -> Init .OwnAddress2      =  0 ;
795- #ifdef  I2C_IP_VERSION_V2 
796-     handle -> Init .OwnAddress2Masks  =  I2C_OA2_NOMASK ;
797- #endif 
798+     
798799    HAL_I2C_Init (handle );
799800
801+     // In slave mode, reenable slave interrupts after calling init 
802+     if (obj_s -> slave  !=  0 )
803+     {
804+         HAL_I2C_EnableListen_IT (& obj_s -> handle );
805+     }
806+ 
800807    /*  store frequency for timeout computation */ 
801808    obj_s -> hz  =  hz ;
802809}
0 commit comments