Proper configuration for I2C Pins on the Arduino Zero (normally reserved pins)

464 views Asked by At

I am using an Arduino Zero core on my SAMD21 with Atmel Studio. I have an I2C device hooked up to pins PB02 (Arduino Zero pin 19) and PB03 (Arduino Zero pin 25). As a side note, this exact same device functions without issue on the regular wire (sercom3, 20, 21).

The first thing I did was disable the RX light pin by commenting out sections using PIN_LED_RXL.

I then tried the typical:

TwoWire myWire(&sercom5, 19, 25 ); //create an I2C on SERCOM5, PA16, PA17
    
void setup() {

  //...
  myWire.begin(); //pressure sensor 1
  pinPeripheral(19, PIO_SERCOM_ALT); //change functionality of PIO, SDA1
  pinPeripheral(25, PIO_SERCOM_ALT); //SCL1
   
  //...
}

Then I try to read 4 from the I2C component:

unsigned int recv[4] = {0};
    
          
myWire.requestFrom(INTERFACE_ADDR,4,1); //get 4 bytes of data

while (ps1_wire.available()) {
  recv[i++] = ps1_wire.read();
}

And the result is always 0. I do not get a response and it tells me that the slave device sends a NACK - the INTFLAG.MB (master on bus interrupt enable) bit has been set and there is no data in the data register.

Curiously enough, when I set the pinPeripherals of the pins to PIO_SERCOM_ALT, the PINCFG register of PB02 (pin 19) does not get set properly - input enable (INEN) is still set and drive strength (DRVSTR) is not driven high, although the MUX enable (PMUXEN) is set.

I know that pinPeripheral() does not set DRVSTR or INEN but it leads me to think that there is something else going on with this pin or the other that may affect its ability to act as an I2C elsewhere during the enabling of the chip. 

The PMUX register is set properly and indicates MUX setting 3, which is correct for SERCOM5 PAD[0] and PAD[1] according to the datasheet - it is MUX Function D (pg 34).

The initialization of the Sercom registers looks fine. For good measure I did change variant.h to include the Sercom5 interrupt for I2C:

#define WIRE_INTERFACES_COUNT 2  
#define PIN_WIRE_SDA         (20u)
#define PIN_WIRE_SCL         (21u)
#define PERIPH_WIRE          sercom3
#define WIRE_IT_HANDLER      SERCOM3_Handler

static const uint8_t SDA = PIN_WIRE_SDA;
static const uint8_t SCL = PIN_WIRE_SCL;

#define PIN_WIRE1_SDA               (19u)
#define PIN_WIRE1_SCL               (25u)
#define PERIPH_WIRE1                sercom5
#define WIRE1_IT_HANDLER            SERCOM5_Handler

static const uint8_t SDA1 = PIN_WIRE1_SDA;
static const uint8_t SCL1 = PIN_WIRE1_SCL;

Still faced with the same issue - the device does not get return data when calling requestFrom().

If anyone has any insight about the way I'm trying to use these pins and how to get the I2C to work on PB02 and PB03 for Sercom5 I would very much appreciate any help.

Thank you!

0

There are 0 answers