Code: Select all
import pyb, stm, time
i2c = pyb.I2C(1, pyb.I2C.MASTER, baudrate=20000)
''' opening internal pull-up for I2C '''
PUPDR = stm.mem32[stm.GPIOB + stm.GPIO_PUPDR]
PUPDR &= ~((3 << 6*2) | (3 << 7*2))
PUPDR |= ((1 << 6*2) | (0 << 7*2))
stm.mem32[stm.GPIOB + stm.GPIO_PUPDR] = PUPDR
time.sleep(1)
PUPDR |= ((1 << 6*2) | (1 << 7*2))
stm.mem32[stm.GPIOB + stm.GPIO_PUPDR] = PUPDR
while(1): i2c.scan()
note 2: when open internal pull-up, you need make a I2C STOP signal. otherwise, the busy flag of I2C will set, and I2C will not work
is there an esay way to open the internal pull-up for I2C?