This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

SPI hanging up

Hello!

I am trying to use SPI between my ATSAMD21G18A (Cortex M0) as master and a radio module as slave. I am able to initiate the SPI, but having trouble enabling the receiver (RXEN). The manual states:

Writing a one to CTRLB.RXEN when the SPI is disabled will set CTRLB.RXEN immediately. When the SPI is enabled, CTRLB.RXEN will be cleared, SYNCBUSY.CTRLB will be set and remain set until the receiver is enabled. When the receiver is enabled CTRLB.RXEN will read back as one.

After enabling the SPI, SYNCBUSY.CTRLB is always set to one and the receiver is not being enabled.

My suspicion is that I'm wrongly configuring the clocks for the SPI. Here is the code below for the clocks and SPI configuration I have.

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/* Enable clock for SPI */
PM->APBCMASK.reg |= SPI_BUS_CLOCK_INDEX;
GCLK->CLKCTRL.reg = GCLK_CLKCTRL_ID(SERCOM4_GCLK_ID_CORE) | // Generic Clock for SERCOM4
GCLK_CLKCTRL_GEN_GCLK0 | // Generic Clock Generator 0 is source
GCLK_CLKCTRL_CLKEN;
while ( GCLK->STATUS.reg & GCLK_STATUS_SYNCBUSY )
{
/* Wait for synchronization */
}
/* Wait for synchronization */
while(SERCOM4->SPI.SYNCBUSY.bit.ENABLE);
/* Disable the SERCOM SPI module */
SERCOM4->SPI.CTRLA.bit.ENABLE = 0;
/* Wait for synchronization */
while(SERCOM4->SPI.SYNCBUSY.bit.SWRST);
/* Perform a software reset */
SERCOM4->SPI.CTRLA.bit.SWRST = 1;
/* Wait for synchronization */
while(SERCOM4->SPI.CTRLA.bit.SWRST);
/* Wait for synchronization */
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Any help is appreciated!

Best regards,

Barry

0