cancel
Showing results for 
Search instead for 
Did you mean: 

I2C Addr bit not set on 401 Discover Board

mailbox4ad4
Associate II
Posted on April 20, 2015 at 10:03

Hi All,

Please see below I2C protocal:

0690X000006059sQAA.png

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 is

 stm32f4xx_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);

}

int

main(int argc, char* argv[])

{

I2C1_Init();

Single_WriteI2C(0x02,0x01);

while (1)

{

    }

}

Hope someone could help me solve this issue, thanks all.

#i2c
2 REPLIES 2
mailbox4ad4
Associate II
Posted on April 21, 2015 at 03:24

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 ?? 
mailbox4ad4
Associate II
Posted on April 21, 2015 at 09:02

Solved...I forgot to set Reset pin at High Level....stupid...