小伙伴们,谁做过把stm32f401RE开发板作为i2c的从端,和linux设备(i2c主)进行通信.采用的是HAL_I2C_Slave_Receive和HAL_I2C_Slave_Transmit库函数,目前的问题是两块stm32开发板可以通信,但是和linux设备无法通信,i2c配置如下: int I2C1Configure() { int status; GPIO_InitTypeDef GPIO_InitStruct3; __GPIOB_CLK_ENABLE(); __I2C1_CLK_ENABLE(); GPIO_InitStruct3.Pin = GPIO_PIN_6|GPIO_PIN_7; GPIO_InitStruct3.Mode = GPIO_MODE_AF_OD; GPIO_InitStruct3.Pull = GPIO_PULLUP; GPIO_InitStruct3.Speed = GPIO_SPEED_MEDIUM; GPIO_InitStruct3.Alternate = GPIO_AF4_I2C1; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct3); I2cHandle.Instance = I2C1; I2cHandle.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT; I2cHandle.Init.ClockSpeed = 100000; I2cHandle.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE; I2cHandle.Init.DutyCycle = I2C_DUTYCYCLE_2; I2cHandle.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE; I2cHandle.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE; I2cHandle.Init.OwnAddress1 = I2C_ADDRESS; I2cHandle.Init.OwnAddress2 = 0xFE; status= HAL_I2C_Init(&I2cHandle); return 0; } |
评分
查看全部评分