cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F407 as i2c slave

michal239955_stm1_st
Associate II
Posted on February 25, 2013 at 09:23

Hi, does someone have experience with unable to clear STOPF bit, what causes continually jumps into i2c IRQ?

I am trying to do it this way:

 

I2C_ClearFlag(I2C1,I2C_FLAG_STOPF);

,but it does not work.

The reference manual says, the STOPF bit is:

Cleared by software reading the SR1 register followed by a write in the CR1 register, or by hardware when PE=0.

The reading of SR1 works ok, but after writing to CR1 using: 

I2C_Cmd(I2C1, ENABLE); 

the STM pulls the SCL constantly LOW.

Michal
8 REPLIES 8
Posted on February 25, 2013 at 14:23

Please post a minimal but complete code exhibiting the problem.

JW

michal239955_stm1_st
Associate II
Posted on February 26, 2013 at 08:51

Well, I try to describe situation.

Slave is STM32F407 discovery kit, which only transmitts data (should simulate some dummy sensor). Master is some another controller board, which sends commands in two parts: 1. Master sends SLAVE_ADDR + WRITE (''0'') - serves to wake-up sensor 2. Then wait 40ms. 3. Master sends SLAVE_ADDR + READ (''1'') and expect to return 4 Bytes from slave. The first part works well, slave sends ACK, and master can apply STOP condition. 0690X00000602eyQAA.jpg But in second part, slave send ACK and after that starts to hold SCL low. 0690X00000602nnQAA.jpg My interrupt rutine:

void I2C1_EV_IRQHandler(void) {
 static

uint32_t index = 0;
uint32_t event = I2C_GetLastEvent(I2C1);
switch (event) {
case I2C_EVENT_SLAVE_RECEIVER_ADDRESS_MATCHED:
I2C_ReceiveData(I2C1);
break;
case I2C_EVENT_SLAVE_TRANSMITTER_ADDRESS_MATCHED:
I2C_SendData(I2C1, I2C_DATA[index++]);
break;
case I2C_EVENT_SLAVE_BYTE_TRANSMITTED:
I2C_SendData(I2C1, I2C_DATA[index++]);
break;
case I2C_EVENT_SLAVE_STOP_DETECTED:
index = 0;
I2C_Cmd(I2C1, ENABLE);
break;
default:
break;
}
}

michal239955_stm1_st
Associate II
Posted on February 26, 2013 at 09:08

I forgot to mention, first reading from slave is success, slave sends 4bytes. The communication is corrupt in second reading.

Posted on March 04, 2013 at 10:34

Please post a minimal but complete code exhibiting the problem.

JW

m_pontz
Associate
Posted on November 20, 2013 at 13:50

Hi Michal,

has your problem been solved, or did you find a workaround?

Cheers

Michael

suhas_sajjan
Associate II
Posted on November 20, 2013 at 15:15

Hi,I am working on project''Evaluation of a 3 axis accelerometer and gyroscope'' using STM32F407 and MPU6050.can someone you please tell me the code for interfacing these two using I2C bus and also hooking up connections....

emalund
Associate III
Posted on November 20, 2013 at 15:47

<i>

can someone you please tell me the code for interfacing these two using I2C bus</i>

a consultant can 

<i>also hooking up connections....</i>

looking at your scope pictures it seems that smaller pull-up resistors might help.

Erik

Posted on November 20, 2013 at 15:59

You are off topic, start a new thread if your posting is irrelevant to the thread.

If you need someone to code your project, ST does maintain a list of contractors/consultants.

http://www.st.com/web/en/support/mcu_design_consultants.html

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..