cancel
Showing results for 
Search instead for 
Did you mean: 

Clock / Timing problem in I2C

maya16
Associate

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.

1 REPLY 1
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".