cancel
Showing results for 
Search instead for 
Did you mean: 

I2C hangs after Pin reset.

pj
Associate II
Posted on March 14, 2016 at 16:47

Hi guys,

I have maybe not a problem, but small issue with ST32F466RE nucleo board. I do some one way communication with a slave device (only writes). Everything works fine until pin reset. Power on & software resets (software & watchdog) do not couse this problem. After pin reset my uC sometimes hangs when it sends START condition. The code:

GPIOB -> OTYPER |= (1 << 
8
) | (1 << 9);
// SCL code which helps a bit needs to be placed here (the code is below (next listing))
GPIOB -> MODER &= ~((0b11 << 
16
) | (0b11 << 18));
GPIOB -> MODER |= (0b10 << 
16
) | (0b10 << 18);
GPIOB -> AFR[1] |= ((0b0100 << 
0
) | (0b0100 << 4));
I2C1 -> CR1 |= I2C_CR1_SWRST;
while(I2C1 -> SR2);
I2C1 -> CR1 &= ~(I2C_CR1_SWRST);
I2C1 -> CR2 = 45; // clock in megahertz
I2C1 -> TRISE = 46;
I2C1 -> CCR = 225;

GPIOB -> MODER &= ~(0b11 << 16);
GPIOB -> MODER |= (0b01 << 16);
for
(counter = 0; counter < 20; counter++) {
GPIOB -> BSRR = GPIO_BSRR_BS_8;
delay(10); 
//uS
GPIOB -> BSRR = GPIO_BSRR_BR_8;
delay(10);
}
GPIOB -> BSRR = GPIO_BSRR_BS_8;

And the I2C

void
I2C1_start(uint8_t addr) {
uint32_t foo;
I2C1 -> CR1 |= (I2C_CR1_PE | I2C_CR1_START);
while
(!((I2C1 -> SR1) & I2C_SR1_SB));
foo = I2C1 -> SR1;
I2C1 -> DR = addr;
while
(!((I2C1 -> SR1) & I2C_SR1_ADDR));
foo = I2C1 -> SR1;
foo = I2C1 -> SR2;
}

uC clock is 180MHz, I2C clock 45MHz. When I add the code from listing 2 to code in the listing one rougly every 20th pin reset hangs the I2C. next pin reset starts it again. Without the code form listing 2 even another pin reset does not help (I need to power down the device) It is quite strange as such things can happen when sleve is transmitting and slave controls the SDA line (then it is necessary to clock the slave to finish the transmission and release the bus). But I do not read anything from the slave. It never happens on power on, soft or watchdog resets. All peripherals are clocked, and initialized. #stm32f4-i2c-issues-not-solved
0 REPLIES 0