cancel
Showing results for 
Search instead for 
Did you mean: 

Clock / Timing problem in I2C

maya16
Associate II

I am trying to run a loopback test with 2 i2c's on the same board. The onboard leds need to light up on successful transmission and reception, the problem is the leds light up when in debug mode, going line by line, but not in stand

#define I2C1_ADD (0x15<<1)
#define I2C2_ADD (0x42<<1)

uint8_t I2C1_tx='1';
uint8_t I2C2_tx='2';
uint8_t I2C1_rx,I2C2_rx;

HAL_I2C_Slave_Receive_IT(&hi2c2,&I2C2_rx,sizeof(I2C1_tx));
HAL_Delay(100);
HAL_I2C_Master_Transmit(&hi2c1,I2C2_ADD,&I2C1_tx,sizeof(I2C1_tx),1000);


HAL_I2C_Slave_Receive_IT(&hi2c1,&I2C1_rx,sizeof(I2C2_tx));
HAL_Delay(100);
HAL_I2C_Master_Transmit(&hi2c2,I2C1_ADD,&I2C2_tx,sizeof(I2C2_tx),1000);


while(1)
{
 if(I2C2_rx==I2C1_tx)
 {
	 HAL_GPIO_WritePin(GPIOG,GPIO_PIN_13,SET);
 HAL_Delay(100);
	
 }
 if(I2C1_rx==I2C2_tx)
  {
 	 HAL_GPIO_WritePin(GPIOG,GPIO_PIN_14,SET);
 	 HAL_Delay(500);
  }
}

alone. Can someone plz suggest what might be wrong.

3 REPLIES 3
TDK
Super User

Don't switch between slave and master. Leave I2C1 as master and I2C2 as slave.

 

Try declaring I2C1_rx I2C2_rx as volatile, since they are being modified by the DMA.

volatile uint8_t I2C1_rx;
volatile uint8_t I2C2_rx;

 

If you feel a post has answered your question, please click "Accept as Solution".
Saket_Om
ST Employee

Hello @maya16 

Please ensure that the interrupt priorities are configured correctly. The interrupt priority for receive should be higher (i.e., numerically lower) than the interrupt priority for transmit.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
Saket_Om
Andrew Neil
Super User

You already have a thread on this - marked as solved:

I2C Loopback Test using STM32F429ZI

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.