@@ -36,6 +36,9 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl)
36
36
{
37
37
uint32_t i2c_sda = pinmap_peripheral (sda , PinMap_I2C_SDA );
38
38
uint32_t i2c_scl = pinmap_peripheral (scl , PinMap_I2C_SCL );
39
+ PORT_Type * port_addrs [] = PORT_BASE_PTRS ;
40
+ PORT_Type * base = port_addrs [sda >> GPIO_PORT_SHIFT ];
41
+
39
42
obj -> instance = pinmap_merge (i2c_sda , i2c_scl );
40
43
obj -> next_repeated_start = 0 ;
41
44
MBED_ASSERT ((int )obj -> instance != NC );
@@ -49,10 +52,11 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl)
49
52
pinmap_pinout (sda , PinMap_I2C_SDA );
50
53
pinmap_pinout (scl , PinMap_I2C_SCL );
51
54
52
- #if defined( FSL_FEATURE_PORT_HAS_OPEN_DRAIN ) && FSL_FEATURE_PORT_HAS_OPEN_DRAIN
53
- PORT_Type * port_addrs [] = PORT_BASE_PTRS ;
54
- PORT_Type * base = port_addrs [ sda >> GPIO_PORT_SHIFT ] ;
55
+ /* Enable internal pullup resistor */
56
+ base -> PCR [ sda & 0xFF ] |= ( PORT_PCR_PE_MASK | PORT_PCR_PS_MASK ) ;
57
+ base -> PCR [ scl & 0xFF ] |= ( PORT_PCR_PE_MASK | PORT_PCR_PS_MASK ) ;
55
58
59
+ #if defined(FSL_FEATURE_PORT_HAS_OPEN_DRAIN ) && FSL_FEATURE_PORT_HAS_OPEN_DRAIN
56
60
base -> PCR [sda & 0xFF ] |= PORT_PCR_ODE_MASK ;
57
61
base -> PCR [scl & 0xFF ] |= PORT_PCR_ODE_MASK ;
58
62
#endif
0 commit comments