AnsweredAssumed Answered

I2C2 busy - SDA being pulled low without any slave attached

Question asked by lillie.jacob on Jun 20, 2014
Latest reply on Jun 20, 2014 by Clive One
I'm trying to configure the I2C2 on an STM32F401 chip. The I2C1 is working fine, but the I2C2 is always returning HAL_BUSY. After initializing the GPIO port the SDA line is being pulled low, but no slave device is attached to the I2C bus. I have 2.2k pull ups.
In the code below, the SDA will be pulled low at line 32, but this is not correct I think.

I have tried resetting the I2C2 in the RCC registers, but to no success.
It should be noted, that the SDA is GPIOB 3, which is also JTDO. My understanding was that when changing the GPIO mode this would overwrite the JTAG functions.

Any help is greatly appreciated

01./*##-1- Configure the I2C peripheral ######################################*/
02.I2c2Handle.Instance             = I2C2;
03.I2c2Handle.Init.AddressingMode  = I2C_ADDRESSINGMODE_7BIT;
04.I2c2Handle.Init.ClockSpeed      = 200000;
05.I2c2Handle.Init.DualAddressMode = I2C_DUALADDRESS_DISABLED; 
06.I2c2Handle.Init.DutyCycle       = I2C_DUTYCYCLE_16_9;  //I2C_DUTYCYCLE_2 / I2C_DUTYCYCLE_16_9
07.I2c2Handle.Init.GeneralCallMode = I2C_GENERALCALL_ENABLED;  //I2C_GENERALCALL_ENABLED /
08.I2c2Handle.Init.NoStretchMode   = I2C_NOSTRETCH_ENABLED; //I2C_NOSTRETCH_ENABLED / I2C_NOSTRETCH_DISABLED
09.I2c2Handle.Init.OwnAddress1     = 0x34;
10.I2c2Handle.Init.OwnAddress2     = 0;
11. 
12.    __GPIOB_CLK_ENABLE();
13.    /* Enable I2C2 clock */
14.    __I2C2_CLK_ENABLE();
15.  //RCC->APB1RSTR |= 0x00400000; // Reset i2c peripheral
16.  //RCC->APB1RSTR &= 0xFFBFFFFF;
17.    __DMA1_CLK_ENABLE();
18. 
19.    /*##-2- Configure peripheral GPIO ##########################################*/ 
20.    /* I2C TX GPIO pin configuration  */
21.    GPIO_InitStruct.Pin       = GPIO_PIN_10;
22.    GPIO_InitStruct.Mode      = GPIO_MODE_AF_OD;   
23.    GPIO_InitStruct.Pull      = GPIO_NOPULL;
24.    GPIO_InitStruct.Speed     = GPIO_SPEED_FAST;
25.    GPIO_InitStruct.Alternate = GPIO_AF4_I2C2;
26.    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
27. 
28.    /* I2C SDA GPIO pin configuration  */
29.    GPIO_InitStruct.Pin       = GPIO_PIN_3;
30.    GPIO_InitStruct.Mode      = GPIO_MODE_AF_OD;    //GPIO_MODE_INPUT //GPIO_MODE_AF_OD
31.    GPIO_InitStruct.Alternate = GPIO_AF4_I2C2;
32.    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);       //this causes the SDA line to go Low.
33. 
34.        /*##-3- Configure the DMA streams ##########################################*/
35.    /* Configure the DMA handler for Transmission process */
36.    hdma_tx.Instance                 = DMA1_Stream7;
37.    hdma_tx.Init.Channel             = DMA_CHANNEL_7;
38.    hdma_tx.Init.Direction           = DMA_MEMORY_TO_PERIPH;
39.    hdma_tx.Init.PeriphInc           = DMA_PINC_DISABLE;
40.    hdma_tx.Init.MemInc              = DMA_MINC_ENABLE;
41.    hdma_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
42.    hdma_tx.Init.MemDataAlignment    = DMA_MDATAALIGN_BYTE;
43.    hdma_tx.Init.Mode                = DMA_NORMAL;
44.    hdma_tx.Init.Priority            = DMA_PRIORITY_LOW;
45.    hdma_tx.Init.FIFOMode            = DMA_FIFOMODE_DISABLE;        
46.    hdma_tx.Init.FIFOThreshold       = DMA_FIFO_THRESHOLD_FULL;
47.    hdma_tx.Init.MemBurst            = DMA_MBURST_SINGLE;  
48.    hdma_tx.Init.PeriphBurst         = DMA_PBURST_SINGLE;  
49. 
50.    HAL_DMA_Init(&hdma_tx);  
51. 
52.    /* Associate the initialized DMA handle to the the I2C handle */
53.    __HAL_LINKDMA(hi2c, hdmatx, hdma_tx);
54. 
55.    /* Configure the DMA handler for Transmission process */
56.    hdma_rx.Instance                 = DMA1_Stream3;
57.    hdma_rx.Init.Channel             = DMA_CHANNEL_7;
58.    hdma_rx.Init.Direction           = DMA_PERIPH_TO_MEMORY;
59.    hdma_rx.Init.PeriphInc           = DMA_PINC_DISABLE;
60.    hdma_rx.Init.MemInc              = DMA_MINC_ENABLE;
61.    hdma_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
62.    hdma_rx.Init.MemDataAlignment    = DMA_MDATAALIGN_BYTE;
63.    hdma_rx.Init.Mode                = DMA_NORMAL;
64.    hdma_rx.Init.Priority            = DMA_PRIORITY_HIGH;
65.    hdma_rx.Init.FIFOMode            = DMA_FIFOMODE_DISABLE;        
66.    hdma_rx.Init.FIFOThreshold       = DMA_FIFO_THRESHOLD_FULL;
67.    hdma_rx.Init.MemBurst            = DMA_MBURST_SINGLE;
68.    hdma_rx.Init.PeriphBurst         = DMA_PBURST_SINGLE;
69. 
70.    HAL_DMA_Init(&hdma_rx);
71. 
72.    /* Associate the initialized DMA handle to the the I2C handle */
73.    __HAL_LINKDMA(hi2c, hdmarx, hdma_rx);
74. 
75.    /*##-4- Configure the NVIC for DMA #########################################*/
76.    /* NVIC configuration for DMA transfer complete interrupt (I2C1_TX) */
77.    HAL_NVIC_SetPriority(DMA1_Stream7_IRQn, 0, 1);
78.    HAL_NVIC_EnableIRQ(DMA1_Stream7_IRQn);  
79. 
80.    /* NVIC configuration for DMA transfer complete interrupt (I2C1_RX) */
81.    HAL_NVIC_SetPriority(DMA1_Stream3_IRQn, 0, 0); 
82.    HAL_NVIC_EnableIRQ(DMA1_Stream3_IRQn);  

Outcomes