i2c Protocol implementation

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
ziss_dm
Posts: 529
Joined: Tue Mar 08, 2011 5:26 am

i2c Protocol implementation

Post by ziss_dm »

Hi Alex,
I have probably stupid question regarding i2c implementation in WMC. As I understand WMC always working in "Repeated start" mode (http://www.i2c-bus.org/repeated-start-condition/). So it is never releases the bus and never issuing Stop Condition and never finishes transaction. This fine, but I have questions:
1) Why we setting TWSTO bit here?

Code: Select all

inline void i2c_rep_start(uint8_t address) {
  TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN) | (1<<TWSTO); // send REAPEAT START condition
  waitTransmissionI2C(); // wait until transmission completed
  checkStatusI2C(); // check value of TWI Status Register
  TWDR = address; // send device address
  TWCR = (1<<TWINT) | (1<<TWEN);
  waitTransmissionI2C(); // wail until transmission completed
  checkStatusI2C(); // check value of TWI Status Register
}

2) There are some users, who reporting issues with WMP/NK not working in repeated start mode. (The symptomps are: WMC not working, but other examples from inet, or BaronPilot which uses Wire library working fine). Shell we implement 2 modes for i2c protocol and switch them using conditional defines? I mean, optionally issue Stop condition for i2c, it would be slower but will allow users to use existing hardware.

regards,
ziss_dm

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

Re: i2c Protocol implementation

Post by Alexinparis »

Hi,

ziss_dm wrote:1) Why we setting TWSTO bit here?

Code: Select all

inline void i2c_rep_start(uint8_t address) {
  TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN) | (1<<TWSTO); // send REAPEAT START condition
  waitTransmissionI2C(); // wait until transmission completed
  checkStatusI2C(); // check value of TWI Status Register
  TWDR = address; // send device address
  TWCR = (1<<TWINT) | (1<<TWEN);
  waitTransmissionI2C(); // wail until transmission completed
  checkStatusI2C(); // check value of TWI Status Register
}


The TWSTO bit is here to apply both a STOP and a START request (ie repeat START).
As you said, for a mono master conf, it's a way to avoid one STOP request.

2) There are some users, who reporting issues with WMP/NK not working in repeated start mode. (The symptomps are: WMC not working, but other examples from inet, or BaronPilot which uses Wire library working fine). Shell we implement 2 modes for i2c protocol and switch them using conditional defines? I mean, optionally issue Stop condition for i2c, it would be slower but will allow users to use existing hardware.

you're again right :)
Quax noticed and suggested also the same.
It won't however solve the need to hard reset the device in case of failure, which is typical with those difficult devices.

Post Reply