Why does the wire library disregard the restart option

Discussion about Z-Uno product. Visit http://z-uno.z-wave.me for more details.
Post Reply
petemilligan
Posts: 4
Joined: 23 May 2019 21:13

Why does the wire library disregard the restart option

Post by petemilligan »

All,

Having worked with a rather fussy I2C component. I need to use a restart, rather than a stop.
I've looked at the wire.c library supplied, but whilst the stop param is supplied, it doesn't seem to be used. Any theories behind this?

Code: Select all

uint8_t TwoWire::endTransmission(uint8_t stop)
{
    // We already stopped I2C
    if(state == STATE_TRANSMITION_STOPPED)
        return sucess_code;
    // We have to send one byte if user dind't do it...
    if(state == STATE_TRANSMITION_INIT)
    {
        p_driver->start();
        if(!p_driver->write(txAddress))
        {
            sucess_code |= NACK_ON_ADDRESS;
        }   
    }
    // We have open connection for reading bytes
    // Some devices will have bad inner state if we don't say "NACK" 
    // at the end.
    if((state == STATE_TRANSMITION_READMODE) && (sucess_code == 0) && available_bytes)
    {
        // Send NACK
        p_driver->read(0x00);
    }    
    // Send stop sequence
	
		p_driver->stop();
	

		state = STATE_TRANSMITION_STOPPED;
	
    return sucess_code;
Thanks,

Pete
p0lyg0n1
Posts: 242
Joined: 04 Aug 2016 07:14

Re: Why does the wire library disregard the restart option

Post by p0lyg0n1 »

Hi,
There is no difference between stop&start sequence and restart() in this realization of I2C. This realization is fully synchronous and does the start/stop sequence when you call appropriate function. Please try it with your device this way:call
endTransmission() and then start the transmission once more using beginTransmissio(...) or requestFrom(...).
petemilligan
Posts: 4
Joined: 23 May 2019 21:13

Re: Why does the wire library disregard the restart option

Post by petemilligan »

I really need a restart like this: (this is standard Arduino Wire library)
Capture.PNG
Capture.PNG (13.71 KiB) Viewed 3691 times
petemilligan
Posts: 4
Joined: 23 May 2019 21:13

Re: Why does the wire library disregard the restart option

Post by petemilligan »

I get a restart with Z-Uno like this:
Capture2.PNG
Capture2.PNG (12.58 KiB) Viewed 3690 times
The device is an MMA8452Q XYZ. The 1st example works fine, I cannot get the Z-Uno to replicate using the supplied libraries. Please help.

Thanks,

Pete
petemilligan
Posts: 4
Joined: 23 May 2019 21:13

Re: Why does the wire library disregard the restart option

Post by petemilligan »

Messy but working. Bit banged a restart & then told Wire library that we're in a STOPPED state;

Code: Select all

  Wire.beginTransmission(0x1D);
  Wire.write(0X0D); //WHO_AM_I
  //Wire.endTransmission(false); 
        digitalWrite(10, HIGH); //sda
        delayMicroseconds(5);
        digitalWrite(9, HIGH); //scl
        delayMicroseconds(5); 
        digitalWrite(10, LOW); //sda
        delayMicroseconds(5);
        digitalWrite(9, LOW); //scl
        delayMicroseconds(5); 
        Wire.stateStop(); // temporary workaround to enable requestFrom to write txAddress
 Wire.requestFrom(0x1D, 1);
 if (Wire.available()) {
      byte c = Wire.read(); 
  }
  Wire.endTransmission(); 
Function in Wire.cpp;

Code: Select all

void TwoWire::stateStop(void)
{
	 state = STATE_TRANSMITION_STOPPED;
}
Results in correct communication.
Capture.PNG
Capture.PNG (13.62 KiB) Viewed 3669 times
Perhaps this helps to diagnose the problem when communicating with these devices.

Pete
Post Reply