I am having problem while using I2C1. I have connected MPU6000 on I2C1. I am using I2C scanner to determine on which address sensor is connected.
I2C config Part:
Code: Select all
static const I2CConfig i2cfg1 = {
OPMODE_I2C,
400000,
STD_DUTY_CYCLE,
};
void I2CInitialize(void){
i2cInit();
i2cStart(&I2CD1, &i2cfg1);
// Link PB8 and PB9 to I2C1 function
palSetPadMode(GPIOB, 8, PAL_MODE_ALTERNATE(4));//
palSetPadMode(GPIOB, 9, PAL_MODE_ALTERNATE(4));//
// startups. Pauses added just to be safe
chThdSleepMilliseconds(100);*/
}
I2C Scanner Function:
Code: Select all
void i2c_scanner1(void){
uint8_t x = 0, txbuf[2],rxbuf[2];
int32_t messages = 0;
chprintf((BaseChannel *)&SD1,"inside i2c1 scanner");
for(x=0;x<128;x++){
txbuf[0] = 0x00;
txbuf[1] = 0x00;
messages = i2cMasterTransmit(&I2CD1, x, txbuf, 2, rxbuf, 0);
if(messages == 0)chprintf((BaseChannel *)&SD1, "I2C1: Sensor is available on Address: %x \r\n", x, messages);
chThdSleepMilliseconds(1);
}
chThdSleepMilliseconds(1000);
}
I have used this function for I2C3 and it works perfectly fine. Returns address on which sensors are connected.
While doing same for I2C1 program get stuck at this point: while ((dp->SR2 & I2C_SR2_BUSY) || (dp->CR1 & I2C_CR1_STOP))
How to fix this?
Sapan