MCUdude / MiniCore

Arduino hardware package for ATmega8, ATmega48, ATmega88, ATmega168, ATmega328 and ATmega328PB
Other
995 stars 245 forks source link

Could you define Second i2c bus with using TwoWire class? #149

Closed asukiaaa closed 4 years ago

asukiaaa commented 4 years ago

Some libraries (ex: Adafruit_BME280, SparkFun_ICM-20948_ArduinoLibrary) support using second i2c bus but this platform use different class(TwoWire1) for second i2c bus so I cannot assign it to the libraries.(It causes type error.) To solve the problem, could you define second i2c bus with using TwoWire class not with TwoWre1? (Serial1 and SPI1 also have same problem.)

Thank you for sharing useful platform. I use this platform for ATmega328PB on PlatformIO.

MCUdude commented 4 years ago

I do understand that this will cause some issues, but it is a lot of work to rewrite the entire SPI and Wire library to fix this. BTW Serial1 does not have the same problems. All serial ports use HardwareSerial as their class.

It's not something I'll prioritize doing at the moment, but I'll keep it in mind.

MCUdude commented 4 years ago

However, If you're capable of doing it, feel free to submit a PR!

mhmayyan commented 4 years ago

@asukiaaa It might be easier for you to modify the libraries (Adafruit_BME280, SparkFun_ICM-20948_ArduinoLibrary). You need, for example, to replace "TwoWire" with "TwoWire1", and "#include " with "#include ".

asukiaaa commented 4 years ago

Thank you for understanding. Sorry, I didn't check Serial1. It is already no problem.

OK, I try to update code about Wire on this weekend.

asukiaaa commented 4 years ago

I created a PR. Please check it. https://github.com/MCUdude/MiniCore/pull/150

MCUdude commented 4 years ago

Closed in 0cad0c6

asukiaaa commented 4 years ago

@MCUdude Could you release new version that includes the merging.

Closed in 0cad0c6

MCUdude commented 4 years ago

@asukiaaa there is still a few minor things I'm working on. Expect a new release in a few days!

asukiaaa commented 4 years ago

I see, I wait releasing.

MCUdude commented 4 years ago

Release 2.0.7 is now available!

asukiaaa commented 4 years ago

Thank you for releasing :)

adoconnection commented 3 years ago

So, should this snippet work if I connect SDA0 and SDA1, SCL0 and SCL1? (it does not for me)


#include <Wire.h>
#include <Wire1.h>

void setup()
{
  Wire1.begin(); // join i2c bus (address optional for master)
  Wire.begin(4);
  Wire.onReceive(receiveEvent);
  Serial.begin(9600);
  Serial.println("Wire1=master, Wire=slave");
}

byte x = 0;

void loop()
{
  Wire1.beginTransmission(4); // transmit to device #4
  Serial.println("1");
  Wire1.write("x is ");        // sends five bytes
  Wire1.write(x);              // sends one byte  
  Serial.println("2");
  Wire1.endTransmission();    // stop transmitting
  Serial.println("3");

  x++;
  delay(500);
}

void receiveEvent(int)
{
  while(1 < Wire.available())
  {
    char c = Wire.read();
    Serial.print(c);
  }
  int x = Wire.read();
  Serial.println(x);
}