STM32F769i-discovery i2C BSP code question
Hi , I'm trying to use external I2C devices in the Audio_playback_and_record project for STM32F769i-discovery.
I think the code is using the BSP to configure the GPIO's for I2C used for internal devices ( audio codec, screen etc )
I have looked at the I2C example but it sets up the GPIO's directly in main for external I2C.
I have tried to merge the I2C example to the Audio_playback_and_record project but I get nothing on the scope from
the I2C bus. The I2C example works.
I am defining the I2C_HandleTypeDef like this;
I2C_HandleTypeDef I2cHandle;
i'm initialising with;
HAL_I2C_Init(&I2cHandle);
then i'm trying to write or check external I2C devices with line like;
error = HAL_I2C_Master_Transmit (&I2cHandle, devaddress, nulldata, i2cpacketsize, timeout);
uint8_t i2ctest = HAL_I2C_IsDeviceReady(&I2cHandle,devaddress,4,100); // check device 0x38
i'm asuming the BUS opperation sets up the external gpio's for I2C if I2C_HandleTypeDef is anything but &hI2cAudioHandler ?
I'm not really understanding the need for I2C_HandleTypeDef or how it works ? is it so we can define and setup more than one I2C bus? if so , what is the best way to do this? Or can I ignore the &hI2cAudioHandler and just manualy define another I2C bus ?
I'd like to use external and internal and external I2C devices on the STM32F769i-discovery. So I dont think I can simply just merge the I2C example code and expect it to work !
any ideas are welcome , i'm new to STM32F7 although I just got basic external GPIO's working on the board for my project.
/*******************************************************************************
BUS OPERATIONS*******************************************************************************//******************************* I2C Routines *********************************/
/** * @brief Initializes I2C MSP. * @param i2c_handler : I2C handler * @retval None */static void I2Cx_MspInit(I2C_HandleTypeDef *i2c_handler){ GPIO_InitTypeDef gpio_init_structure;if (i2c_handler == (I2C_HandleTypeDef*)(&hI2cAudioHandler))
{ /*** Configure the GPIOs ***/ /* Enable GPIO clock */ DISCOVERY_AUDIO_I2Cx_SCL_GPIO_CLK_ENABLE(); DISCOVERY_AUDIO_I2Cx_SDA_GPIO_CLK_ENABLE(); /* Configure I2C Tx as alternate function */ gpio_init_structure.Pin = DISCOVERY_AUDIO_I2Cx_SCL_PIN; gpio_init_structure.Mode = GPIO_MODE_AF_OD; gpio_init_structure.Pull = GPIO_NOPULL; gpio_init_structure.Speed = GPIO_SPEED_FAST; gpio_init_structure.Alternate = DISCOVERY_AUDIO_I2Cx_SCL_AF; HAL_GPIO_Init(DISCOVERY_AUDIO_I2Cx_SCL_GPIO_PORT, &gpio_init_structure);/* Configure I2C Rx as alternate function */
gpio_init_structure.Pin = DISCOVERY_AUDIO_I2Cx_SDA_PIN; gpio_init_structure.Alternate = DISCOVERY_AUDIO_I2Cx_SDA_AF; HAL_GPIO_Init(DISCOVERY_AUDIO_I2Cx_SDA_GPIO_PORT, &gpio_init_structure);/*** Configure the I2C peripheral ***/
/* Enable I2C clock */ DISCOVERY_AUDIO_I2Cx_CLK_ENABLE();/* Force the I2C peripheral clock reset */
DISCOVERY_AUDIO_I2Cx_FORCE_RESET();/* Release the I2C peripheral clock reset */
DISCOVERY_AUDIO_I2Cx_RELEASE_RESET();/* Enable and set I2C1 Interrupt to a lower priority */
HAL_NVIC_SetPriority(DISCOVERY_AUDIO_I2Cx_EV_IRQn, 0x0F, 0); HAL_NVIC_EnableIRQ(DISCOVERY_AUDIO_I2Cx_EV_IRQn);/* Enable and set I2C1 Interrupt to a lower priority */
HAL_NVIC_SetPriority(DISCOVERY_AUDIO_I2Cx_ER_IRQn, 0x0F, 0); HAL_NVIC_EnableIRQ(DISCOVERY_AUDIO_I2Cx_ER_IRQn); } else { /*** Configure the GPIOs ***/ /* Enable GPIO clock */ DISCOVERY_EXT_I2Cx_SCL_SDA_GPIO_CLK_ENABLE();/* Configure I2C Tx as alternate function */
gpio_init_structure.Pin = DISCOVERY_EXT_I2Cx_SCL_PIN; gpio_init_structure.Mode = GPIO_MODE_AF_OD; gpio_init_structure.Pull = GPIO_NOPULL; gpio_init_structure.Speed = GPIO_SPEED_FAST; gpio_init_structure.Alternate = DISCOVERY_EXT_I2Cx_SCL_SDA_AF; HAL_GPIO_Init(DISCOVERY_EXT_I2Cx_SCL_SDA_GPIO_PORT, &gpio_init_structure);/* Configure I2C Rx as alternate function */
gpio_init_structure.Pin = DISCOVERY_EXT_I2Cx_SDA_PIN; HAL_GPIO_Init(DISCOVERY_EXT_I2Cx_SCL_SDA_GPIO_PORT, &gpio_init_structure);/*** Configure the I2C peripheral ***/
/* Enable I2C clock */ DISCOVERY_EXT_I2Cx_CLK_ENABLE();/* Force the I2C peripheral clock reset */
DISCOVERY_EXT_I2Cx_FORCE_RESET();/* Release the I2C peripheral clock reset */
DISCOVERY_EXT_I2Cx_RELEASE_RESET();/* Enable and set I2C1 Interrupt to a lower priority */
HAL_NVIC_SetPriority(DISCOVERY_EXT_I2Cx_EV_IRQn, 0x0F, 0); HAL_NVIC_EnableIRQ(DISCOVERY_EXT_I2Cx_EV_IRQn);/* Enable and set I2C1 Interrupt to a lower priority */
HAL_NVIC_SetPriority(DISCOVERY_EXT_I2Cx_ER_IRQn, 0x0F, 0); HAL_NVIC_EnableIRQ(DISCOVERY_EXT_I2Cx_ER_IRQn); }}#bus #i2c #external #audio-playback #audio-recording