SAMD21 Mini breakout: Can't get new I2C bus working with SERCOM

Have questions about a SparkFun product or board? This is the place to be.

Moderator: phalanx

Post Reply
agentsmithitaly
Posts: 1
Joined: Sat Jan 19, 2019 11:59 am

SAMD21 Mini breakout: Can't get new I2C bus working with SERCOM

Post by agentsmithitaly » Sat Jan 19, 2019 12:06 pm

Hi to all,
For my new project I need to reconfigure the SERCOMs to get three UART and three I2C buses.

I have been following these guides:
https://learn.adafruit.com/using-atsamd ... a-new-wire
https://www.arduino.cc/en/Tutorial/SamdSercom

The three UART work, however I cannot get the secondary Wire to work.
The hardware is a Sparkfun SAMD21 Mini and three BME280 sensors, connected to pins as follows, with 4k7 pullups (SDA, SCL): (A4, A5), (4, 3), (11, 13)
I carefully selected the pins out of the table in the SAMD21 datasheet, they should be correct.
The first bus is default and works, the 2nd is on SERCOM0 and the 3rd on SERCOM1.

This is the test code for a single Wire:

Code: Select all

#include "wiring_private.h" // pinPeripheral() function
#include <Wire.h>
#include <SparkFunBME280.h>

TwoWire myWire(&sercom0, 4, 3);

BME280 bme1; // I2C

void SERCOM0_Handler(void);

void SERCOM0_Handler(void) {
    myWire.onService();
}

void setup() {
  // put your setup code here, to run once:
 SerialUSB.begin(115200);
  while (!SerialUSB) {
    ; // wait for serial port to connect
  }

  SerialUSB.println("SAMD21 Test Initialization");
  SerialUSB.println();

   SerialUSB.println("Initializing I2C on pin 4, 3");

  
  myWire.begin();
  pinPeripheral(3, PIO_SERCOM);
  pinPeripheral(4, PIO_SERCOM);
  SerialUSB.println("Inizialized, looking for sensor");
   if(bme1.beginI2C(myWire) == false) {
    SerialUSB.println("Sensor NOT found!");
  } else {
    SerialUSB.println("Sensor found");
  }
}

void loop() {
  // put your main code here, to run repeatedly:
    SerialUSB.print("Sensor 2 temp: ");
    SerialUSB.println(bme1.readTempC(), 2);
    delay(5000);
}
The sketch will be stuck at "Inizialized, looking for sensor".
Tried to do the same with Adafrult BME280 library, still stuck.
If I run the I2C scanner code, the device is correctly found at address 0x77 so at least something is clicking.

Need to change anything in variants.cpp / variants.h?
Any other advice?

Thank you!

Nick

Post Reply