Go Down

Topic: SAMD21 and SPI, assign the SCK clock to two pins? (Read 1 time) previous topic - next topic

LC200

Hi

Due to an issue with logic level shifting and wanting a neater fix to a home design compatible with the Arduino Zero, I'm wondering if it is possible for the SPI clock to be outputted on two pins simultaneously?

With SPI set up currently the SCK is output on PA12 (pin 21), which needs to continue, but could I also configure another pin to output the same clock.  Pins broken out and available are PA07, PA06, PB23, PB22,  and PA15.  It seems the SERCOM is fairly flexible so hoping there is a way.

Many thanks.

MartinL

Hi LC200,

Yes, it's possible to output the SPI clock on two pins simultaneously, but the pins must support the same SERCOM and PAD number. This is detailed in the PORT Function Multiplexing table in the SAMD21 datasheet.

Assuming you're using SERCOM4, SPI SCK on PA12 uses SERCOM4/PAD[0].

SERCOM4/PAD[0] is also available on port pins PB08 and PB12.

To activate a given pin, it's first necessary to enable the port mutliplexer:

Code: [Select]
PORT->Group[PORTB].PINCFG[12].bit.PMUXEN = 1;
...then set the port multiplexer switch to either peripheral C (SERCOM) or D (SERCOM ALT):

Code: [Select]
PORT->Group[PORTB].PMUX[12 >> 1].reg |= PORT_PMUX_PMUXE_C;

LC200

Hi Martin

Many thanks will give that a go.

Regards

Lee

LC200

Hi Martin

Hi LC200,

Yes, it's possible to output the SPI clock on two pins simultaneously, but the pins must support the same SERCOM and PAD number. This is detailed in the PORT Function Multiplexing table in the SAMD21 datasheet.

Assuming you're using SERCOM4, SPI SCK on PA12 uses SERCOM4/PAD[0].

Just got around to revisiting this project, but having no joy.  On my board I'm using PB11 for the clock, which is on SERCOM-ALT as SERCOM4/PAD3.  Looking in the datasheet I can see that PA15 is also SERCOM4/PAD3 so tried enabling it with:

Code: [Select]

PORT->Group[PORTA].PINCFG[15].bit.PMUXEN = 1;
PORT->Group[PORTA].PMUX[15 >> 1].reg |= PORT_PMUX_PMUXE_D;


However it doesn't seem to be outputting the clock on that pin, have I understood correctly?

Regards

Lee

MartinL

Hi Lee,

As port PA15 is an odd numbered port, you just need peripheral multiplexer (PMUX) register bitfield from even:

Code: [Select]
PORT_PMUX_PMUXE_D
to odd:

Code: [Select]
PORT_PMUX_PMUXO_D
Kind regards,
Martin

LC200

Hi Martin

Hi Lee,

As port PA15 is an odd numbered port, you just need peripheral multiplexer (PMUX) register bitfield from even:

Code: [Select]
PORT_PMUX_PMUXE_D
to odd:

Code: [Select]
PORT_PMUX_PMUXO_D
Kind regards,
Martin
Just was going to update my post as found some info on the net and played about with using pinPeripheral(5, PIO_SERCOM_ALT) which did the job on it's own (need to import #include "wiring_private.h"), and your fix using PMUXO also now works, completely missed the issue odd/even!

Many thanks, job done.

Regards

Lee

Go Up