Skip to content

Conversation

@dsanders11
Copy link
Contributor

The changes in #137 don't work with trying to use stopBit = false. Minor change to allow doing a requestFrom in multiple parts. This is necessary due to limited buffer sizes.

Example usage of what this allows (which doesn't currently work):

uint8_t buffer[20];

Wire.requestFrom(address, 10, false);
for (uint8_t i=0; i < 10; i++) {
    buffer[i] = Wire.read();
}

// Do something else, then finish reading

Wire.requestFrom(address, 10);
for (uint8_t i=0; i < 10; i++) {
    buffer[10 + i] = Wire.read();
}

@carlosperate, any thoughts on this PR? It's tested and works, but it's kind of quick and dirty as I needed it working ASAP.

@dlabun
Copy link
Collaborator

dlabun commented Aug 12, 2017

@sandeepmistry Do you think this is a serious enough issue to include in v0.4.0?

@sandeepmistry
Copy link
Owner

@dlabun yes, I think so.

@dsanders11 thanks for submitting! Do we need a similar change for endTransmission(bool stopBit)?
Apart from that, your changes look good to me (although I haven't tried them on a physical board yet).

@dsanders11
Copy link
Contributor Author

@sandeepmistry, probably needed in endTransmission(bool stopBit) as well, yea. I'm testing this on the nRF52832 Breakout Board from Sparkfun, and using Wire_nRF51.cpp despite it being nRF52 since that file was most recently improved and fixed, and works just fine since that API is available on nRF52. These changes could be applied to Wire_nRF52.cpp as well, but that file is still using the interrupt version which Wire_nRF51.cpp switched off of, so it may not cleanly apply.

Copy link
Owner

@sandeepmistry sandeepmistry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, this looks good to me!

I've tested with the micro:bit:

#include <Wire.h>

void setup() {
  Serial.begin(9600);
  Wire.begin();

  int address = 0x0E;

  Wire.beginTransmission(address);
  Wire.write(0x11);
  Wire.write(0x0f);
  Wire.endTransmission(false);

  Wire.beginTransmission(address);
  Wire.write(0x11);
  Wire.write(0x0e);
  Wire.endTransmission(false);

  Wire.beginTransmission(address);
  Wire.write(0x11);
  Wire.endTransmission();

  Serial.println("requestFrom false");
  Serial.println(Wire.requestFrom(address, 1, false));
  Serial.println((byte)Wire.read(), HEX);

  Serial.println("requestFrom true");
  Serial.println(Wire.requestFrom(address, 1, true));
  Serial.println((byte)Wire.read(), HEX);

  Serial.println("done");
}

void loop() {
}

It was a built-in MAG3110 compass sensor on I2C address 0x0E. Without these changes the sketch hangs, with them it works!

I haven't used a logic analyzer, but a TX with stop bits seems to work as is.

@sandeepmistry sandeepmistry merged commit 4f5f026 into sandeepmistry:master Aug 18, 2017
@sandeepmistry
Copy link
Owner

@dsanders11 thanks!

It would be awesome if you could spend some time on seeing what's wrong with the nRF52 Wire file. Maybe a combination of this PR and #137 need to be applied?

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

Successfully merging this pull request may close these issues.

3 participants