Hi, I have some problem about I2C Communication with STM32F746NG-DISCO.
I wrote following programs with mbed library based on DISCO-F746NG_LCDTS_demo.
A I2C device is connected to the I2C1(D14, D15:PB_9, PB_8).
The external pull up resistors are not attached because this disco board has them.
*****
(Part of programs )
I2C i2c(I2C_SDA, I2C_SCL);
i2c.start();
i2c.write(0x5A<<1);
i2c.write(0x07);
i2c.start();
i2c.write(0x5A<<1|0x01);
buf[0]=i2c.read(1);
buf[1]=i2c.read(1);
buf[2]=i2c.read(0);
i2c.stop();
*******
In this case, the data of i2c_write is empty.
Finally, I found the answer to communicate with the I2C device.
*****
(Part of programs )
I2C i2c(I2C_SDA, I2C_SCL);
I2C_HandleTypeDef hi2c1;
static void MX_I2C1_Init(void)
{
hi2c1.Instance = I2C1;
hi2c1.Init.Timing = 0x2000090E;
hi2c1.Init.OwnAddress1 = 0;
hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
hi2c1.Init.OwnAddress2 = 0;
hi2c1.Init.OwnAddress2Masks = I2C_OA2_NOMASK;
hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
HAL_I2C_Init(&hi2c1) ;
HAL_I2CEx_ConfigAnalogFilter(&hi2c1, I2C_ANALOGFILTER_ENABLE) ;
}
MX_I2C1_Init();
i2c.frequency(100000);In case of only HAL, the speed is 500k. Need re-setting.
HAL_I2C_Mem_Read(&hi2c1,(uint16_t)(0x5A<<1),0x07,I2C_MEMADD_SIZE_8BIT,(uint8_t*) buf,3,3000);
*****
Using HAL Library functions,
the communication of i2c is worked well and I can get good data from the device.
Is it a bug of mbed library?
Or Is it some interference of I2C port?
(the mixed code of mbed and HAL is not elegant... )
Hi, I have some problem about I2C Communication with STM32F746NG-DISCO.
I wrote following programs with mbed library based on DISCO-F746NG_LCDTS_demo.
A I2C device is connected to the I2C1(D14, D15:PB_9, PB_8).
The external pull up resistors are not attached because this disco board has them.
***** (Part of programs )
I2C i2c(I2C_SDA, I2C_SCL);
i2c.start();
i2c.write(0x5A<<1);
i2c.write(0x07);
i2c.start();
i2c.write(0x5A<<1|0x01);
buf[0]=i2c.read(1);
buf[1]=i2c.read(1);
buf[2]=i2c.read(0);
i2c.stop();
*******
In this case, the data of i2c_write is empty.
Finally, I found the answer to communicate with the I2C device.
***** (Part of programs )
I2C i2c(I2C_SDA, I2C_SCL);
I2C_HandleTypeDef hi2c1;
static void MX_I2C1_Init(void)
{
hi2c1.Instance = I2C1;
hi2c1.Init.Timing = 0x2000090E;
hi2c1.Init.OwnAddress1 = 0;
hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
hi2c1.Init.OwnAddress2 = 0;
hi2c1.Init.OwnAddress2Masks = I2C_OA2_NOMASK;
hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
HAL_I2C_Init(&hi2c1) ;
HAL_I2CEx_ConfigAnalogFilter(&hi2c1, I2C_ANALOGFILTER_ENABLE) ;
}
MX_I2C1_Init();
i2c.frequency(100000);In case of only HAL, the speed is 500k. Need re-setting.
HAL_I2C_Mem_Read(&hi2c1,(uint16_t)(0x5A<<1),0x07,I2C_MEMADD_SIZE_8BIT,(uint8_t*) buf,3,3000);
*****
Using HAL Library functions, the communication of i2c is worked well and I can get good data from the device.
Is it a bug of mbed library? Or Is it some interference of I2C port? (the mixed code of mbed and HAL is not elegant... )