Strange START/REP_START condition in I2C code

This forum is dedicated to software development related to MultiWii.
It is not the right place to submit a setup problem.
Software download
Post Reply
SVentas
Posts: 13
Joined: Fri Sep 16, 2011 5:29 pm
Location: Lithuania

Strange START/REP_START condition in I2C code

Post by SVentas »

Hi!

Sorry for my bad english :).

I'm developing a very simple MultiWii compatible board with Invensense 3-axis digital gyroscope ITG3205 and with FreeScale digital 3-axis accelerometer MMA8452Q. Both sensors are connected through I2C lines. The ITG3205 gyroscope works perfect, but data from the MMA8452Q accelerometer seems to be random values. The problem completely disappears when code in i2c_rep_start routine (Sensors.pde) is changed from

Code: Select all

void i2c_rep_start(uint8_t address) {
  TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN) | (1<<TWSTO); // send REPEAT START condition 

to

Code: Select all

void i2c_rep_start(uint8_t address) {
  TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN); // send REPEAT START condition

Why TWSTA (START) and TWSTO (STOP) condition bits are set simultaneously in i2c_rep_start routine? I have never seen any tutorial or application note with such a strange START/REP_START configuration.
It seems like a minor bug :).

Alexinparis
Posts: 1630
Joined: Wed Jan 19, 2011 9:07 pm

Re: Strange START/REP_START condition in I2C code

Post by Alexinparis »

Hi,

It's a feature :)
viewtopic.php?f=8&t=267

To be short:
- I's maybe not in the I2C norm
- It works with most I2C sensors
- it's a way to avoid STOP request (less time spent to retrieve data)

SVentas
Posts: 13
Joined: Fri Sep 16, 2011 5:29 pm
Location: Lithuania

Re: Strange START/REP_START condition in I2C code

Post by SVentas »

OK!

Thank You Alex!

Post Reply