cancel
Showing results for 
Search instead for 
Did you mean: 

[SOLVED] Use the I2C inside TouchGFX application

Is there an example to see how to use the I2C inside a TouchGFX application ?

I have found the following functions but how to select the target I2C port because

I have 4 i2C ports on my 32F746G-DISCO.

I don't know which is the I2C port number for the CN2 connector.

I2C_HandleTypeDef i2c_handler;

I2Cx_Init(&i2c_handler);

I2Cx_WriteData(0x20), 0x11, 0x00);

2 REPLIES 2

Found the solution, add in the file stm32746g_discovery.c these functions and the relative declaration in stm32746g_discovery.h (...\Drivers\BSP\STM32746G-Discovery).

void BSP_I2C_Init()

{

#define I2C_ADDRESS       0x3c

#define I2C_TIMING     0x00B1112E

 hi2c1.Instance = I2C1;

 hi2c1.Init.Timing = I2C_TIMING;

 hi2c1.Init.OwnAddress1 = I2C_ADDRESS;

 hi2c1.Init.OwnAddress1 = 0x78; // an unused address

 hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;

 hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;

 hi2c1.Init.OwnAddress2 = 0;

 hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;

 hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;

 I2Cx_Init(&hi2c1);

}

void BSP_I2C_Write(uint8_t Addr, uint8_t Reg, uint8_t Value)

{

 I2Cx_WriteMultiple(&hi2c1, Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT, (uint8_t*)&Value, 1);

}

The first fuction will be called in the screen file Screen1View.cpp

void Screen1View::setupScreen()

{

   #ifdef SIMULATOR

        printf("LED on\n");

   #else

        BSP_LED_Init(LED_GREEN);

        BSP_I2C_Init();

        BSP_I2C_Write(0x20, 0x11, 0x00);

   #endif

and the other function in the relative action

void Screen1View::buttonOPTClicked()

{

   touchgfx_printf("buttonOPTClicked \n");

   #ifdef SIMULATOR

        printf("OPT\n");

   #else

        BSP_I2C_Write(0x20, 0x04, 0x30 + 1);

   #endif

   buttonPCM.invalidate();

}