cancel
Showing results for 
Search instead for 
Did you mean: 

Problems getting I2C pins configured on STM32F427 (Solved- dumb mistake)

geof
Associate II
Posted on August 27, 2015 at 16:07

EDIT: Problem solved. When calling GPIO_PinAFConfig in lines 19 and 20 below, I used GPIO_Pin_# rather than the correct GPIO_PinSource#. All my other uses of AF peripherals was correct- I just messed this one up. It took me two long days of debugging to find that... #@#$&@#!!!

-------------------------------------------------- Hello, I am having problems getting the I2C2 pins configured on an STM32F427, specifically on pins B10 and B The initialization sequence is below. Note that GPIO clocks have already been enabled elsewhere before getting to this code. I am using a board of my own design. Other peripherals used in this project (GPIOs, SPI, and UART) all work. I have pull up resistors on the two I2C lines. I've tried both 2k and 10k with the same result. I stepped through the code to see what happens. When I reset the code, the I2C lines go high, as expected due to the pull up resistors. Then when I execute the two GPIO_Init(GPIOB,&GPIO_InitStructure) commands, the corresponding I2C line gets pulled down to 0. They never get released. If I run the code without stepping through, the result is the same. What is bizarre is that I've used essentially the same initialization sequence on other projects boards using an STM32F405, so I don't know why they wouldn't work here. Is there something different about the '427? I am using version 1.5.1 of the peripheral libraries, with the proper #define for using the STM32F4 For development tools I am using IAR EWARM Cortex edition and an ST-Link v2 debugger. I've also tried, line 14, using GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL with the same result. Can anyone please provide an insight as to what is happening? Thank You in advance! -Geof


//////////////////////////////////////////////////////////////

// I2C2 on pins B10 and B11

// Note: GPIO clocks have already been enabled elsewhere

// release reset and enable peripheral clock for I2C2

RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C2, ENABLE); 

RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C2, ENABLE);

RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C2, DISABLE);

// Step 1: Connect pins

// set I2C pins

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;

GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //GPIO_PuPd_NOPULL;

GPIO_Init(GPIOB, &GPIO_InitStructure); // B10 drops to 0 when this is executed

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;

GPIO_Init(GPIOB, &GPIO_InitStructure); // B11 drops to 0 when this is executed

// Connect I2C pins to alternate function 5 (AF5) 

GPIO_PinAFConfig(GPIOB, GPIO_Pin_10, GPIO_AF_I2C2);

GPIO_PinAFConfig(GPIOB, GPIO_Pin_11, GPIO_AF_I2C2);


// Step 2: initialize I2C peripheral 

// initialize I2C2 for fast mode

I2CInitSt.I2C_Mode = I2C_Mode_I2C;

I2CInitSt.I2C_DutyCycle = I2C_DutyCycle_2; // high / low = 2

I2CInitSt.I2C_OwnAddress1 = 0x2C; // set device address CHANGE

I2CInitSt.I2C_Ack = I2C_Ack_Enable; // enable ACK response

I2CInitSt.I2C_ClockSpeed = 400000; // 400kHz (PCLK1 must be mult. of 10MHz)

I2CInitSt.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit; // 7-bit addressing

I2C_Init(I2C2, &I2CInitSt); 

// set I2C2 options

//I2C_NACKPositionConfig(I2C2, I2C_NACKPosition_Current); // CHECK

I2C_DMACmd(I2C2, DISABLE); // disable DMA

I2C_StretchClockCmd(I2C2, ENABLE); // enable clock stretching

I2C_DualAddressCmd(I2C2, DISABLE); // disable dual addressing

// enable I2C2 event and error interrupts (buffer interrupts will be enabled later)

// BUF: TxE / RxNE

// EVT: ADDR / STOPF / BTF (with no TxE/RxNE) / TxE / RxNE (if BUF, dual?)

// ERR: BERR / ARLO / AF / OVR / PECERR / TIMEOUT / SMBALERT

I2C_ITConfig(I2C2, (I2C_IT_EVT | I2C_IT_ERR), ENABLE);

// enable I2C2

I2C_Cmd(I2C2, ENABLE);

#i2c #stm32f427 #gpio
1 REPLY 1
Nesrine M_O
Lead II
Posted on August 28, 2015 at 11:02

Hi,

Thank you for posting your findings and how you fixed the issue, it is good to hear that it was solved. 

-Syrine-