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

Re: Problem with I2C1

Post by sapan »

Yes I am using discovery board. To debug, I configured PB8 and PB9 as GPIO and toggle them

Code: Select all

  palSetPadMode(GPIOB, 8, PAL_MODE_OUTPUT_PUSHPULL);
  palSetPadMode(GPIOB, 9, PAL_MODE_OUTPUT_PUSHPULL);

  while (TRUE){
     palClearPad(GPIOB, 8);
     palSetPad(GPIOB, 9);
     chThdSleepMilliseconds(1);
     palSetPad(GPIOB, 8);
     palClearPad(GPIOB, 9);
     chThdSleepMilliseconds(1);
  }



And got output as expected.
Attachments
PB8 and PB9 Toggle.png
PB8 and PB9 Toggle.png (92.27 KiB) Viewed 7800 times
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 »

On the discovery I2C1 is used to access the audio DAC using pins PB6 and PB9, you may try to access that device. Probably you should use PB6 instead of PB8 or the two devices could create problems each other being on different SDA lines bust sharing SCK.

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

Re: Problem with I2C1

Post by sapan »

Disabled I2C1 related part in board.h file and declared those pins as inputs in board.h files. Its working now...:). I am able to communicate via I2C1 on PB8 and PB9.
sapan
Posts: 56
Joined: Sat Dec 24, 2011 1:22 pm

Re: Problem with I2C1

Post by sapan »

Got one question while debugging for this issue. What register should I read in order to ensure that correct configuration is set for each peripherals ?

Will following registers do?
    VAL_GPIOx_MODER
    VAL_GPIOx_OTYPER
    VAL_GPIOx_OSPEEDR
    VAL_GPIOx_PUPDR
    VAL_GPIOx_ODR
    VAL_GPIOx_AFRL
    VAL_GPIOx_AFRH
Or do I need to read other registers as well?
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 »

Just those.

Your problem was that there were two pins assigned to the same alternate function.

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

Re: Problem with I2C1

Post by sapan »

Thanks....will diagnose those registers first if stuck with such kind of issues next time....thanks again :)
User avatar
Nemesis2065
Posts: 20
Joined: Fri Nov 15, 2013 9:53 am

Re: Problem with I2C1

Post by Nemesis2065 »

Hi,

I'm working on the I2C1 for a LTC2945 component on the STM32F4 discovery board and I'm facing a similar issue.
You wrote that you modified the board.h file concerning the IC21, what did you modified to get it working ?
How can I ensure that I don't have 2 pins assigned to the same alternate function ? (eg. audio DAC)

For the moment I have this config (not working):

Code: Select all

const I2CConfig i2c1_cfg =
{
    OPMODE_I2C,
    400000,
    STD_DUTY_CYCLE,
};

chThdSleepMilliseconds(50);
i2cStart(&I2CD1, &i2c1_cfg);
palSetPadMode(GPIOB, 8, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN);   /* SCL */
palSetPadMode(GPIOB, 9, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN);   /* SDA */



And here the part of the code for reading the desired register:

Code: Select all

msg_t status = RDY_OK;
systime_t timeout = MS2ST(50);
i2cflags_t error = 0;

uint8 buff_Tx_ui8 = 0;
uint8 buff_Sense_Rx_ui8[2] = {0,0};
uint8 buff_Volt_Rx_ui8[2] = {0,0};
uint16 dVSense_ui16 = 0;

buff_Tx_ui8 = LTC2945_DELTA_SENSE_MSB_REG;
i2cAcquireBus(&I2CD1);   
status = i2cMasterTransmit(&I2CD1, LTC2945_ADDR, buff_Tx_ui8, 1, buff_Sense_Rx_ui8, 2);
i2cReleaseBus(&I2CD1);
if (status != RDY_OK)
{
   error = i2cGetErrors(&I2CD1);
   chprintf((BaseSequentialStream*) &SD3, "I2C1 DELTA_SENSE_MSB_REG error : %x \r\n", error);
}

And I get the following error code : I2CD_ACK_FAILURE 0x04

Thanks in advance :)
steved
Posts: 834
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 12 times
Been thanked: 138 times

Re: Problem with I2C1

Post by steved »

One favourite with I2C - what is the value of LTC2945_ADDR?

In ChibiOS it's a 7-bit value (i.e. bits 7..1 of the first byte sent, shifted right one).

Some people express the address as an 8-bit value, usually with bit 0 forced to zero, to reflect the first byte.

Your error could simply mean the device isn't responding, possibly because of incorrect addressing.
User avatar
Nemesis2065
Posts: 20
Joined: Fri Nov 15, 2013 9:53 am

Re: Problem with I2C1

Post by Nemesis2065 »

Hi steved !

The value of LTC2945_ADDR is 0x6B.
User avatar
Nemesis2065
Posts: 20
Joined: Fri Nov 15, 2013 9:53 am

Re: Problem with I2C1

Post by Nemesis2065 »

Small update,
I just saw I was using a wrong address... :oops: I will test again tonight with the good one this time and see if it's better.

another question: if I want to read a register, can I use i2cMasterTransmit and read back the rxbytes ?
Or should I use i2cMasterReceive instead ?
Post Reply