cancel
Showing results for 
Search instead for 
Did you mean: 

I2C Not Working

Jonathan-Halltech
Associate II

Hello,

I am trying to setup an external ADC/DAC module with an STM32H7 microcontroller. 

I2C Slave - EVAL-AD5593R-PMDZ

I2C Master - STM32H757XIH6 on STM32 Embedded Display by Riverdi

I am struggling to get the very basics of communication to work as I cannot get a return of HAL_OK.

The slave address for the AD5593R should be 0b0010001 as the A0 bit for the IC on the module is always connected to Vcc according to the schematic for the board.

The I2C2 peripheral is setup by STM32IDE and the timing is set for 400 kHz which the AD5593R can work on.

Any thoughts on what may be my issue would be extremely helpful!!! Thanks a lot.

 

What I have tried:

-Swapping slave address bit A0 to 0

-Removing left shift for slave address

-Adding a 0 for write command to the slave address

-Using HAL I2C Master Transmit

 

Hardware Connections:

STM32 Pin 2 +3.3V -> AD5593R Pin 6 Vcc

STM32 Pin 6 GND -> AD5593R Pin 5 GND

STM32 Pin 34 I2C2_SDA -> AD5593R Pin 4 SDA

STM32 Pin 36 I2C2_SCL -> AD5593R Pin 3 SCL

 

Main Code:

static const uint8_t AD5593_ADDR = 0b0010001 << 1;                    // AD5593 address, left shift 1
HAL_StatusTypeDef ret;

ret = HAL_I2C_IsDeviceReady(&hi2c2, AD5593_ADDR, 4, 1000);

 

I2C Initialize:

/* I2C2 init function */
void MX_I2C2_Init(void)
{
hi2c2.Instance = I2C2;
hi2c2.Init.Timing = 0x00501D55;
hi2c2.Init.OwnAddress1 = 0;
hi2c2.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
hi2c2.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
hi2c2.Init.OwnAddress2 = 0;
hi2c2.Init.OwnAddress2Masks = I2C_OA2_NOMASK;
hi2c2.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
hi2c2.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
if (HAL_I2C_Init(&hi2c2) != HAL_OK)
{
Error_Handler();
}

HAL_I2CEx_EnableFastModePlus(I2C_FASTMODEPLUS_I2C1);
}

1 ACCEPTED SOLUTION

Accepted Solutions
Jonathan-Halltech
Associate II

Thank you everyone for the assistance. The Riverdi support noted that the schematic for the AD5593R board shows the pull up resistor circuit but there is a "DNI" written beside the two resistors, meaning do not install. I added pull up resistors and everything is working as expected. I should have tried this from the beginning, unfortunately I was not familiar with DNI markings. Thanks again. 

View solution in original post

15 REPLIES 15
Karl Yamashita
Lead II

The STM32H757XIH6 uses a TFBGA package. The TFBFA pins are labeled Row A-S and Column 1-17. So how are you coming up with Pin 34 and Pin 36?

 

Due to the fact that the microcontroller is embedded in the display, the user only has access to a 40-pin header, covering a variety of peripherals. I have attached a copy of the pinout for the header called STM32H7 Pinout above, where the pin numbers come from. The proper pin names are PB11 (I2C2 SDA) and PH4 (I2C2 SCL). Thanks for taking a look.

Karl Yamashita
Lead II

Have you checked with an oscilloscope to be sure you're getting data and clock from the STM32?

Show some relevant code on what you're trying to do to get HAL driver to return HAL_OK. 

The embedded display uses FreeRTOS to manage all of the display elements. I have added a FreeRTOS Task with normal priority for I2C testing. The contents of the task are the infinite loop below. The voltage variable is passed to the display in another task, and is how I can verify the communication is not working. 

I connected the system to an old oscilloscope and it seems there is no clock or data signal coming from the STM32, just minor noise. Taking a closer look at the pin and clock assignments done by the CubeIDE, I cannot find where the HAL_I2C_MspInit() function is called. I tried calling it myself but it did not change anything. Below is the HAL_I2C_MspInit() function for I2C2. Is it possible a clock source or GPIO setting needs to be changed? I appreciate the assistance!

 

FreeRTOS I2C Task

for(;;)
{

    ret = HAL_I2C_IsDeviceReady(&hi2c2, AD5593_ADDR, 1, 100);
    if(ret != HAL_OK)
    {
        voltage = 666;
    }
    else
    {
        voltage = 777;
    }

}

 

void HAL_I2C_MspInit(I2C_HandleTypeDef* i2cHandle)

else if(i2cHandle->Instance==I2C2)
{
/* USER CODE BEGIN I2C2_MspInit 0 */

/* USER CODE END I2C2_MspInit 0 */

/** Initializes the peripherals clock
*/
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_I2C2;
PeriphClkInitStruct.I2c123ClockSelection = RCC_I2C123CLKSOURCE_D2PCLK1;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
{
Error_Handler();
}

__HAL_RCC_GPIOH_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
/**I2C2 GPIO Configuration
PH4 ------> I2C2_SCL
PB11 ------> I2C2_SDA
*/
GPIO_InitStruct.Pin = GPIO_PIN_4;
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF4_I2C2;
HAL_GPIO_Init(GPIOH, &GPIO_InitStruct);

GPIO_InitStruct.Pin = GPIO_PIN_11;
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF4_I2C2;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

/* I2C2 clock enable */
__HAL_RCC_I2C2_CLK_ENABLE();
/* USER CODE BEGIN I2C2_MspInit 1 */

/* USER CODE END I2C2_MspInit 1 */
}

 

Maybe do a simple test to see if those pins on the header are actually connected to the STM32. I would disable the I2C2 and then set the two pins as a GPIO output. Just toggle the pins in code and see if you can see the pins actually toggle with an oscilloscope/DMM. 

Also, do you have pull-up resistors on the I2C bus?

Pavel A.
Evangelist III

While waiting for more useful answer: try other I2C device with the Riverdi to test your environment.

Connect your device to a simple ST board (Nucleo) to ensure the device is alive.

 

I will try using the pins as GPIO output now, should work as I was using one of them for an external interrupt previously. 

The EVAL-AD5593R-PMDZ has 100k pull-up resistors on the I2C bus.

Andrew Neil
Evangelist III

Please use this button to properly post source code:

AndrewNeil_0-1713916672653.png

 

 

Have you contacted Riverdi for support with their board?

Do they provide some simple I2C example(s)?

 


@Jonathan-Halltech wrote:

 

The EVAL-AD5593R-PMDZ has 100k pull-up resistors on the I2C bus


Really??!

That sounds way too high - a few k is more usual.

Again, looking at the lines with a scope would show any issues there...

Jonathan-Halltech
Associate II

Thank you for the tip about source code. I have tested the I2C channel pins as GPIO outputs and they work fine. I also tried using the other I2C channel and pins (I2C4) and they also show no output on the oscilloscope. 

Riverdi has no example projects that I could find. I have reached out to their support team to provide an example project or any suggestions as to why neither of the I2C channels output any clock or data signals. It seems very strange given that all of the peripherals like I2C are initialized with the proper pins by default, done by the default code generation for the board on TouchGFX. Thanks for all the help.