Problem with I2C1

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

sapan
Posts: 56
Joined: Sat Dec 24, 2011 1:22 pm

Problem with I2C1

Post by sapan »

Hi,

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
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Problem with I2C1

Post by Giovanni »

Could it be an electrical problem? (conflicts, pull-ups etc)

Giovanni
sapan
Posts: 56
Joined: Sat Dec 24, 2011 1:22 pm

Re: Problem with I2C1

Post by sapan »

I am trying it on discovery board and its not giving clock on PB8. Do I need to change DMA priority or do i need to do something in initialization part? Will check for connection once again
User avatar
barthess
Posts: 861
Joined: Wed Dec 08, 2010 7:55 pm
Been thanked: 7 times

Re: Problem with I2C1

Post by barthess »

sapan wrote: Do I need to change DMA priority

First try some more trivial steps. For example, ensure that you correctly initialize pins for this I2C cell.
sapan
Posts: 56
Joined: Sat Dec 24, 2011 1:22 pm

Re: Problem with I2C1

Post by sapan »

Have initialize I2C pins and checking whether clock is coming or not. Any other way to ensure correct initialization?
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Problem with I2C1

Post by Giovanni »

What ChibiOS version are you using, 2.4.0 had a bug related to I2C1 using alternate DMA channels.

Giovanni
sapan
Posts: 56
Joined: Sat Dec 24, 2011 1:22 pm

Re: Problem with I2C1

Post by sapan »

I am using 2.4.0
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Problem with I2C1

Post by Giovanni »

Well, try the 2.4.1 just in case you are hitting that bug.

Giovanni
sapan
Posts: 56
Joined: Sat Dec 24, 2011 1:22 pm

Re: Problem with I2C1

Post by sapan »

Same issue with 2.4.1. How can I check whether port initialization is correct??
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Problem with I2C1

Post by Giovanni »

Are you using a STM32F4-Discovery board? if so, PA9 is not available because it is connected to VBUS.

Giovanni
Post Reply