Third I²C via SERCOM on a Feather M0 Express

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
JulianDt
 
Posts: 2
Joined: Sun Jan 29, 2023 12:06 pm

Third I²C via SERCOM on a Feather M0 Express

Post by JulianDt »

I am trying to set up three separate I²C buses on a Feather M0 Express board.

The first two are no problem (SERCOM 1.0/1.1, Pins D11/D13 and SERCOM 3.0/3.1, pins D20/D21).

SERCOM 2 is hooked up to the onboard flash memory, so pins D3 and D4 are not available. On SERCOM 5 pad 5.1 is not available, so it won't work for I²C either.

Is it possible to use SERCOM 4.0/4.1 on pins D15(A1) and D16(A2) for I²C?
Would I need to comment out the respective lines in variant.cpp similar to "Freeing up SERCOM5" in this tutorial?
https://learn.adafruit.com/using-atsamd ... xing-it-up

I didn't find any more on this in a forum/web search, so I'd be very happy if you had any suggestions for me.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Third I²C via SERCOM on a Feather M0 Express

Post by adafruit_support_mike »

JulianDt wrote: Sun Jan 29, 2023 12:25 pm Is it possible to use SERCOM 4.0/4.1 on pins D15(A1) and D16(A2) for I²C?
You'll lose the SPI port doing that.. it uses SERCOM-4.[0,2,3]:

Code: Select all

PA12	D22 / MISO	SERCOM2.0	SERCOM4.0
PB10	D23 / MOSI			SERCOM4.2
PB11	D24 / SCK			SERCOM4.3
JulianDt wrote: Sun Jan 29, 2023 12:25 pm Would I need to comment out the respective lines in variant.cpp similar to "Freeing up SERCOM5" in this tutorial?
Hmm.. nothing you do in the variant files will be useful. The SPI interfaces are created in the SPI library:

https://github.com/adafruit/ArduinoCore ... #L539-L570

They're created in a series of #defines based on the number of interfaces available, so you might have to comment out the line that creates the default interface:

https://github.com/adafruit/ArduinoCore ... I.cpp#L554

User avatar
westfw
 
Posts: 2008
Joined: Fri Apr 27, 2007 1:01 pm

Re: Third I²C via SERCOM on a Feather M0 Express

Post by westfw »

I've been working on getting multiple serial ports working on SAMD21 boards, so I've been staring at the sercom stuff pretty intently, recently... (I've got six UARTS running on a Sparkfun SAMD21 board, but haven't been looking at I2C yet.)
SERCOM 2 is hooked up to the onboard flash memory,
The on-board flash on a Metro M0 uses Sercom5.

Be careful, because which Sercoms are used for which purposes changes from board to board. I made this: https://docs.google.com/spreadsheets/d/ ... sp=sharing
(and also: https://docs.google.com/spreadsheets/d/ ... edit#gid=0 )

You should be able to use Sercom0 on A3/A4 if you're not using Serial1, Sercom2 on D3 and D4, or Sercom4 on MISO and A2.
I believe you'd only have to touch variant.cpp if you want to use pins that aren't currentl designated as Sercom pins in there (D3, D4, A2, A3, A4.) Or, I think you can call pinPeripheral() youself as I do here: https://github.com/WestfW/WestfW_SerCom ... rt.ino#L84 (works for UART. Not sure about I2C.) (I am contemplating submitting a bug where I rant about how useless the current gPindescription[].ulPinType variable is. But it seems unlikely that it would be changed. Sigh.)

User avatar
JulianDt
 
Posts: 2
Joined: Sun Jan 29, 2023 12:06 pm

Re: Third I²C via SERCOM on a Feather M0 Express

Post by JulianDt »

Thanks both of you for your quick and helpful replies!
I can go without SPI for this project, so I will try pinPeripheral() with Sercom4. That should work with I²C as well. There appears to be EDBG debugging linked to Pin D16 as well, could this be a problem (with this board)? No need for debugging on my side.

USB communication appears to be independent of Sercom0/hardware serial, so it wouldn't be affected if I re-used that for I²C, right?

@westfw Thanks for your extensive tables and example! Mine is a Feather M0 Express - i'm pretty sure the flash is on D3/D4, are you sure it isn't? In any case, those two are not accessible from the headers.

User avatar
westfw
 
Posts: 2008
Joined: Fri Apr 27, 2007 1:01 pm

Re: Third I²C via SERCOM on a Feather M0 Express

Post by westfw »

Huh. You did say "Feather"; I wonder how I managed to read it wrong so consistently!
Fortunately, the Feather and Metro pinouts are very similar (but the feather is missing some pins), and Sercom5 is still flash.
There appears to be EDBG debugging linked to Pin D16 as well
EDBG is the "debug chip" that is present only on the Arduino Zero (or "M0 Pro"); it's not present on any of the Adafruit boards, so there won't be any interference...

I've updated the spreadsheets a bit, paying more attention to the Feather. Some of my labels were from pins marked on the schematic that weren't actually connected anywhere (TXLed, RXLed.)

Locked
Please be positive and constructive with your questions and comments.

Return to “Feather - Adafruit's lightweight platform”