Go Down

Topic: [SOLVED] I2C Communication on pins D3/D4 (Read 2783 times) previous topic - next topic

Rfuzer

Jun 26, 2015, 04:55 pm Last Edit: Jul 06, 2015, 03:54 pm by cmaglie
Hi,

Is there a functionally I2C Communication on Arduino Zero?

In Arduino Zero's Schematic there is two ports with I2C communication, D3/D4(PA09/PA08) e I2C_SDA/I2C_SCL(PA22/PA23). The two ports are marked as I2C. Can I use D3/D4 ports for I2C communitacion without any change in variant.cpp?

cmaglie

The two pins SDA/SCL can be used with the usual Wire library.

The other two pins requires a change in the variant.h and to the Wire.h/cpp, in particular the begin() method do not yet support multiple I²C pins definitions from the variant.h. Moreover we must figure out how to share the SERCOM instances between multiple I²C / SPI / UARTS, and allocate them only as needed.
Making this simple for the final user is a complex topic :-), if you have any suggestion, you're more than welcome!
C.

Rfuzer

I tried to change the variant.h in this line:

...

#define PIN_WIRE_SDA         (4u)
#define PIN_WIRE_SCL         (3u)

...

for use the D3/D4 as I2C ports, and not work! I want to use just one device in communication I2C, but i need to use this pins (D3/D4). Is there other change that i need to do for work?

Rfuzer

#3
Jul 02, 2015, 02:20 pm Last Edit: Jul 06, 2015, 03:53 pm by cmaglie
SOLVED!

I solved my problem by changing the following code lines:

in "variant.h" :


#define PIN_WIRE_SDA         (4u) 
#define PIN_WIRE_SCL         (3u)


in variant.cpp


  { PORTA,  9, PIO_SERCOM_ALT, (PIN_ATTR_DIGITAL/*|PIN_ATTR_PWM|PIN_ATTR_TIMER*/), No_ADC_Channel, NOT_ON_PWM,   NOT_ON_TIMER,     EXTERNAL_INT_9 },
  { PORTA,  8, PIO_SERCOM_ALT, (PIN_ATTR_DIGITAL/*|PIN_ATTR_PWM|PIN_ATTR_TIMER*/), No_ADC_Channel, NOT_ON_PWM,   NOT_ON_TIMER,     EXTERNAL_INT_NMI },


in Wire.cpp


TwoWire Wire(&sercom2);

void SERCOM2_Handler(void) {
  Wire.onService();
}


Now, I have the I2C communication working on ports D3/D4(PA09/PA08) very well!

Regards!

cmaglie

Rfuzer,

thank you for sharing your solution!  8)
C.

Go Up