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

Gen2 I2C: fix the issue #2093. #2184

Merged
merged 2 commits into from Sep 8, 2020
Merged

Conversation

XuGuohui
Copy link
Member

@XuGuohui XuGuohui commented Aug 29, 2020

Problem

See: https://github.com/particle-iot/device-os/issues/2093.

Solution

Notify user application on slave receiver worked for a cycle.

Example App

#include "Particle.h"

SYSTEM_MODE(MANUAL);

Serial1LogHandler log(115200, LOG_LEVEL_ALL);

#define I2C_SLAVE_ADDR  0x32

const auto slaveMsg = "This is slave.";
const auto masterMsg = "This is master.";

// Use Photon or Argon the slave device to test
#if PLATFORM_ID == PLATFORM_PHOTON || PLATFORM_ID == PLATFORM_ARGON
void receiveEvent(int howMany) {
    while (1 < Wire.available()) {
        char c = Wire.read();
        Serial1.print(c);
    }
    char x = Wire.read();
    Serial1.println(x);
}

void requestEvent() {
    Wire.write(slaveMsg);
}
#endif

void setup() {
    Log.info("Application started.");

#if PLATFORM_ID == PLATFORM_PHOTON || PLATFORM_ID == PLATFORM_ARGON
    Wire.begin(I2C_SLAVE_ADDR);
    Wire.onReceive(receiveEvent);
    Wire.onRequest(requestEvent);
#else
    int ret;
    Wire.begin();
    Wire.beginTransmission(I2C_SLAVE_ADDR);
    Wire.write("Hello!");
    ret = Wire.endTransmission(false); // Do not send the STOP bit.
    if (ret) {
        Log.error("endTransmission: %d", ret);
    }
    Wire.beginTransmission(I2C_SLAVE_ADDR);
    Wire.write(masterMsg);
    ret = Wire.endTransmission(false); // Do not send the STOP bit.
    if (ret) {
        Log.error("endTransmission: %d", ret);
    }
    Wire.requestFrom(I2C_SLAVE_ADDR, strlen(slaveMsg), true); // Send the stop bit.
    while (1 < Wire.available()) {
        char c = Wire.read();
        Serial1.print(c);
    }
    char x = Wire.read();
    Serial1.println(x);
#endif
}

void loop() {
}

References

https://github.com/particle-iot/device-os/issues/2093


Completeness

  • User is totes amazing for contributing!
  • Contributor has signed CLA (Info here)
  • Problem and Solution clearly stated
  • Run unit/integration/application tests on device
  • Added documentation
  • Added to CHANGELOG.md after merging (add links to docs and issues)

@XuGuohui XuGuohui added this to the 2.0.0 milestone Aug 29, 2020
Copy link
Member

@avtolstoy avtolstoy left a comment

Choose a reason for hiding this comment

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

We should add tests to i2c_master_slave suite to verify this behavior both on Gen 2 and Gen 3.

hal/src/stm32f2xx/i2c_hal.c Outdated Show resolved Hide resolved
Copy link
Member

@avtolstoy avtolstoy left a comment

Choose a reason for hiding this comment

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

LGTM.

@XuGuohui We are still missing tests for this though.

@XuGuohui XuGuohui added ready to merge PR has been reviewed and tested and removed needs review labels Sep 8, 2020
@XuGuohui XuGuohui merged commit 344d2d1 into develop Sep 8, 2020
@XuGuohui XuGuohui deleted the fix/gen2_i2c_restart/ch54456 branch September 8, 2020 08:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug ready to merge PR has been reviewed and tested
Projects
None yet
2 participants