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

Working with ESP chips #63

Open
BrotherV opened this issue Dec 16, 2021 · 4 comments
Open

Working with ESP chips #63

BrotherV opened this issue Dec 16, 2021 · 4 comments
Assignees

Comments

@BrotherV
Copy link

BrotherV commented Dec 16, 2021

Adding new begin() method for selectable pins of Wire library
To communicate ESP chips to MCP7940, we need to set up pins, which means we need to pass the number of GPIO to the MCP7940 class

Adding a new begin(SDA_PIN, SCL_PIN) method to the library
To connect the chips, in which i2C pins can be selected, a new method should be added to the library in both .h and .cpp files

Adding begin(SDA_PIN, SCL_PIN) header file
bool begin(int sda, int scl, const uint32_t i2cSpeed = I2C_STANDARD_MODE) const;

I have changed and tested your library with ESP chips and have attached them here.
MCP7940.zip

@SV-Zanshin
Copy link
Collaborator

I see what you mean, even for other devices user might want an alternative SDA and SCL pin. I can add an overloaded begin() to define these.

You attached a .zip file which is unreadable. Perhaps you could just add the code you wrote for the begin() method and I'll add in the rest.

@BrotherV
Copy link
Author

Thanks for your consideration. I have added codes here.

Adding begin(SDA_PIN, SCL_PIN) to MCP7940.h file

    bool begin(int sda, int scl, const uint32_t i2cSpeed = I2C_STANDARD_MODE) const;

Adding begin(SDA_PIN, SCL_PIN) method to MCP7940.cpp file

    bool MCP7940_Class::begin(int sda, int scl, const uint32_t i2cSpeed) const
    {
      /*!
          @brief     Start I2C device communications
          @details   Starts I2C comms with the device, using a default speed if one is not specified
          @param[in] i2cSpeed defaults to I2C_STANDARD_MODE, otherwise use speed in Herz
          @return    true if successfully started communication, otherwise false
      */
      Wire.begin(sda, scl);                    // Start I2C as master device
      Wire.setClock(i2cSpeed);                 // Set the I2C bus speed
      Wire.beginTransmission(MCP7940_ADDRESS); // Address the MCP7940
      if (Wire.endTransmission() == 0)         // If there a device present
      {
        clearRegisterBit(MCP7940_RTCHOUR, MCP7940_12_24); // Use 24 hour clock
        setRegisterBit(MCP7940_CONTROL, MCP7940_ALMPOL);  // assert alarm low, default high
        return true;                                      // return success
      }
      else
      {
        return false; // return error if no device found
      }               // of if-then-else device detected
    } // of method begin()

SV-Zanshin pushed a commit that referenced this issue Dec 16, 2021
Added support for SDA and SCL definitions for the ESP8266
@SV-Zanshin
Copy link
Collaborator

I've solved it a bit differently so that the begin() functions have only one code base. I think that what I've just uploaded to the main branch should work for the ESP8266 as well as for any other devices and also be backwards compatible. Can you check the changes to the library .c and .h files?

SV-Zanshin pushed a commit that referenced this issue Dec 16, 2021
Corrected clang-formatting on new code
SV-Zanshin pushed a commit that referenced this issue Dec 18, 2021
Correct pin macro so that it works with all boards
SV-Zanshin pushed a commit that referenced this issue Dec 18, 2021
Remove library references to PIN_WIRE_SDA, PIN_WIRE_SCL
SV-Zanshin pushed a commit that referenced this issue Dec 18, 2021
I can't believe a simple trailing space on one line caused the build to fail :)
@SV-Zanshin
Copy link
Collaborator

clang-format is quite finicky! But I've got a correct version on the master branch for you to try out. It compiles correctly on all platforms.

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

No branches or pull requests

2 participants