Send Repeated Start condition over i2c

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderators: RoccoMarco, barthess

ep.hobbyiest
Posts: 94
Joined: Sun Jun 26, 2016 5:22 pm
Has thanked: 4 times
Been thanked: 1 time

Send Repeated Start condition over i2c

Postby ep.hobbyiest » Mon Aug 07, 2017 7:09 pm

Hi,

I am using STM32F103xx processor. I am using I2C driver for temp. sensor and eeprom as well. But i am confused to use start condition over i2c.
which API i can use for that.
I am using chibi studio 17.7 and chibi os 3. I have configured i2c1 for that (PB6 and PB7).

right now, processor is getting stuck at i2c read function only. (i think because i missed this repeated start condition).

ep.hobbyiest
Posts: 94
Joined: Sun Jun 26, 2016 5:22 pm
Has thanked: 4 times
Been thanked: 1 time

Re: Send Repeated Start condition over i2c

Postby ep.hobbyiest » Tue Aug 08, 2017 5:34 pm

Hi,

if i don't give timeout that is TIME_INFINITE then it get stuck i2cMasterReceiveTimeout function.
When i give timeout then i gets some value 21845 (0x5555).

Code: Select all

static const I2CConfig i2cfg1 = {
    OPMODE_I2C,
    400000,
    FAST_DUTY_CYCLE_2,
};

void initI2cc(void)
{
  palSetPadMode(GPIOB, 6, PAL_MODE_STM32_ALTERNATE_OPENDRAIN);     
  palSetPadMode(GPIOB, 7, PAL_MODE_STM32_ALTERNATE_OPENDRAIN);   
  i2cStart(&I2CD1, &i2cfg1);
}

uint16_t readObjectTemp(uint8_t reg, uint16_t *dat)
{
  uint32_t tmo;
  tmo = MS2ST(4);
  uint8_t data[3];
 
  MSG_TIMEOUT == i2cMasterReceiveTimeout(&I2CD1, MLX90614_ADD,
                          data, 3, tmo)
  *dat = (data[1]<<8) | data[0];
}


I got I2C error as 4 that is I2C_ACK_FAILURE.
When i compile and checked wuth arduino then it was working fine with the same setup.
1.8 Kohm pull up is provided.

>epy.

steved
Posts: 823
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 12 times
Been thanked: 135 times

Re: Send Repeated Start condition over i2c

Postby steved » Wed Aug 09, 2017 8:44 am

I don't think you need to worry about the repeated start condition; that's handled automatically (I assume; and I've never found it to be an issue when talking to I2C devices).
Favourite problem when getting started is specifying the I2C address properly. It's a 7-bit value, which some APIs expect to be in bits 1..7 of a byte. Chibi expects it to be in bits 0..6.

Do you have pullups on both of SDA and SCL?

I don't know that particular sensor; do you have to send it a command value of some sort before it will return data? If so, use i2cMasterTransmitTimeout() to send data then get a response in the same transaction.

ep.hobbyiest
Posts: 94
Joined: Sun Jun 26, 2016 5:22 pm
Has thanked: 4 times
Been thanked: 1 time

Re: Send Repeated Start condition over i2c

Postby ep.hobbyiest » Thu Aug 17, 2017 7:23 pm

Yes. Now it is working with the same way. pull up went wrong.


Return to “STM32 Support”

Who is online

Users browsing this forum: No registered users and 23 guests