2015-04-20 01:03 AM
Hi All,
Please see below I2C protocal:I am using STM32F401 Discover Board, the slave is on board CS43L22, the address is 0x94.I try to send 0x01 to register 0x02:Single_WriteI2C(0x02,0x01)
, but only send out address, no data phase.I think it cause by slave not ack
.The low level driver isstm32f4xx_hal_i2c.c
, if I using old stm32f4xx_i2c.c, the result is OK. So I do not know what is going on.The complete code as below:void I2C1_Init(){ __GPIOB_CLK_ENABLE(); GPIO_InitStruct.Pin = GPIO_PIN_6; GPIO_InitStruct.Mode = GPIO_MODE_AF_OD; //GPIO_MODE_OUTPUT_PP GPIO_InitStruct.Pull = GPIO_NOPULL; //GPIO_PULLUP GPIO_InitStruct.Speed = GPIO_SPEED_FAST; GPIO_InitStruct.Alternate = GPIO_AF4_I2C1; //GPIO_MODE_OUTPUT_PP HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); GPIO_InitStruct.Pin = GPIO_PIN_9; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); __I2C1_CLK_ENABLE(); __I2C1_FORCE_RESET(); __I2C1_RELEASE_RESET(); hi2c1.Instance = I2C1; hi2c1.Init.ClockSpeed = 100000; hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2; hi2c1.Init.OwnAddress1 = 0xEE; hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT; hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLED; hi2c1.Init.OwnAddress2 = 0; hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLED; hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLED; HAL_I2C_Init(&hi2c1);}void Single_WriteI2C(uint8_t REG_Address,uint8_t REG_data){ uint8_t TxData[2] = {REG_Address,REG_data}; HAL_StatusTypeDef i; uint8_t j=0; HAL_I2C_Master_Transmit(&hi2c1,0x94,(uint8_t*)TxData,2,4000);}intmain(int argc, char* argv[]){ I2C1_Init(); Single_WriteI2C(0x02,0x01); while (1) { }}Hope someone could help me solve this issue, thanks all. #i2c2015-04-20 06:24 PM
According to some information from internet, I change slave address from 0x94 to 0x96 or 0x4A, the result still the same. I also tried to slow the I2C speed, still useless, I can only see address on the oscilloscope, no data phase. Just like slave not there.
Any idea ??2015-04-21 12:02 AM
Solved...I forgot to set Reset pin at High Level....stupid...