Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

endTransmission() does not return SCL high on NAK #11

Open
muadeeb opened this issue Aug 10, 2017 · 3 comments
Open

endTransmission() does not return SCL high on NAK #11

muadeeb opened this issue Aug 10, 2017 · 3 comments

Comments

@muadeeb
Copy link

muadeeb commented Aug 10, 2017

  • Arduino board: None -- raw ATTiny25

  • Arduino IDE version (found in Arduino -> About Arduino menu): 1.8.3 (Windows Store 1.8.6.0)

-I'm using a Tiny25 to scan for an unknown number of I2C devices so I later can only send data to devices that I know exist. In doing this, I'm sending a known request for version info from the slave devices. The problem is if the device doesn't exist then TinyWireM.endTransmission() does not return the SCL line to high.

You can see the clock not returning to high here:
full data

Close up of where the problem starts:
zoom
Data 0x14 is the reply from a device, address 0x11 is a non-existent possible device.

Snippet of the scanning code:
for (int a = 0x10; a < 0x18; a++) { TinyWireM.beginTransmission(a); TinyWireM.send(0x7F); TinyWireM.endTransmission(); if (TinyWireM.requestFrom(a, 1) > 0) { Addresses[AirChains++] = a; while(TinyWireM.available()) { TinyWireM.receive(); } } delayMicroseconds (50); }

@muadeeb
Copy link
Author

muadeeb commented Aug 10, 2017

I am able to work around the issue by changing the following code in TinyWireM.cpp

uint8_t USI_TWI::endTransmission(uint8_t stop){ // actually sends the buffer
  bool xferOK = false;
  uint8_t errorCode = 0;
  xferOK = USI_TWI_Start_Read_Write(USI_Buf,USI_BufIdx+1); // core func that does the work
  USI_BufIdx = 0;
  if (xferOK) {
    if (stop) {
      errorCode = USI_TWI_Master_Stop();
      if (errorCode == 0) {
        errorCode = USI_TWI_Get_State_Info();
        return errorCode;
      }
    }
    return 0;
  }
  else {                                  // there was an error
    errorCode = USI_TWI_Get_State_Info(); // this function returns the error number
	USI_TWI_Master_Stop(); //Forces a STOP to be sent -- added by Muadeeb
    return errorCode;
  }
}

@manoloaterol
Copy link

Same problem here with a Tiny24a.

Works perfect after the change.

Thanks @muadeeb !

@oomek
Copy link

oomek commented Apr 24, 2020

This workaround does not work on Attiny85 unfortunately, The SCL is still low after NACK. Any clues?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants