我测得是MMA8451传感器的,这是我的I2C初始化:
void I2C_Init(void)
{
SYS->IPRSTC2 |= SYS_IPRSTC2_I2C1_RST_Msk; //C: Peripheral Reset Control Resister 2: I2C-bit = 1 => controller reset
SYS->IPRSTC2 &= ~SYS_IPRSTC2_I2C1_RST_Msk;//C: Peripheral Reset Control Resister 2: I2C-bit = 0 => set controller to normal mode
I2C1->I2CON |= I2C_I2CON_ENS1_Msk;
I2C1->I2CLK = I2C_I2CLK_DIV4(120); /* 48000000Hz / 4 / 120 = 100000Hz */
_I2C_ENABLE_TIMEOUT_COUNTER(I2C1);
}
这是我的端口初始化:
SYS->P4_MFP = SYS_MFP_P44_SCL1 | SYS_MFP_P45_SDA1; |