XMC4500 SPI Slave

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
User15090
Level 1
Level 1
Hi,

I am trying currently to create a SPI Slave on a XMC4500 but somehow i cannot get it to work. This in part of an attempt to get DMA working with SPI. The sender (Master) side, I have already sucessfully programmed and it is running without a problem.

Following is my code to configure the slave:


#define SPI_SLAVE_PIN_MISO P2_14
#define SPI_SLAVE_PIN_MOSI P2_15
#define SPI_SLAVE_PIN_SS P0_6
#define SPI_SLAVE_PIN_SCLK P0_11

#define SR_LINE_DMA_MASTER 0
#define DMA_CHANEL_MASTER 1

const uint16_t _blocksize = 1;
const uint8_t sendData[_blocksize] = {0xAA};//, 0x02, 0x03, 0x04};
uint8_t recvData[10] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};


void USIC1_0_IRQHandler(void)
{
//TODO cleanup
XMC_SPI_CH_ClearStatusFlag(XMC_SPI0_CH1, XMC_SPI_CH_EVENT_STANDARD_RECEIVE | XMC_SPI_CH_EVENT_ALTERNATIVE_RECEIVE);
return;
}

XMC_SPI_CH_CONFIG_t spi_config_slave =
{
.bus_mode = XMC_SPI_CH_BUS_MODE_SLAVE,
.selo_inversion = XMC_SPI_CH_SLAVE_SEL_INV_TO_MSLS,
.parity_mode = XMC_USIC_CH_PARITY_MODE_NONE
};

int main(void)
{
XMC_SPI_CH_Init(XMC_USIC1_CH0, &spi_config_slave);

XMC_SPI_CH_SetInputSource(XMC_USIC1_CH0,XMC_SPI_CH_INPUT_DIN0,USIC1_C0_DX0_P2_15);
XMC_SPI_CH_SetInputSource(XMC_USIC1_CH0,XMC_SPI_CH_INPUT_SLAVE_SCLKIN,USIC1_C0_DX1_P0_11);
XMC_SPI_CH_SetInputSource(XMC_USIC1_CH0,XMC_SPI_CH_INPUT_SLAVE_SELIN,USIC1_C0_DX2_P0_6);


XMC_GPIO_SetMode(SPI_SLAVE_PIN_MOSI, XMC_GPIO_MODE_INPUT_TRISTATE);
XMC_GPIO_SetMode(SPI_SLAVE_PIN_SS, XMC_GPIO_MODE_INPUT_TRISTATE);
XMC_GPIO_SetMode(SPI_SLAVE_PIN_SCLK, XMC_GPIO_MODE_INPUT_TRISTATE);
XMC_GPIO_SetMode(SPI_SLAVE_PIN_MISO, XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT2);

XMC_SPI_CH_EnableEvent(XMC_USIC1_CH0, XMC_SPI_CH_EVENT_STANDARD_RECEIVE);
XMC_SPI_CH_EnableEvent(XMC_USIC1_CH0, XMC_SPI_CH_EVENT_ALTERNATIVE_RECEIVE);
XMC_SPI_CH_EnableEvent(XMC_USIC1_CH0, XMC_SPI_CH_EVENT_RECEIVE_START);

XMC_SPI_CH_Start(XMC_USIC1_CH0);
}


btw: I am using the infineon Relax Kit with Keil DFP 2.10.0 for this example.

Following Screen shows the signals which are being outputted on the SPI Channels by the SPI Master
3123.attach

Blue Signal: Slave Select singal from master -> P0.6
Yellow Signal: CLK Signal -> P0.11
Red Signal: MOSI Signal -> P2.15
Green Signal: MISO Signal -> P2.14


I have tried using the CMSIS Driver to implement a slave but also that was without any success. My long term goal is to also use DMA on the slave side to receive the data from the master.

I hope somebody can help me with this matter.

Thanks in advance
Best Regards
0 Likes
2 Replies
DRubeša
Employee
Employee
First solution authored First like received
Hi,

I suggest you first to check the SPI_SLAVE_EXAMPLE_XMC4500 that is exactly written for your board and uses DMA mode which is also exactly what your application uses. What I can tell by a quick look is that you have issue in your interrupt service routine where you should clear the flag from "XMC_SPI1_CH0" module not "XMC_SPI0_CH1". However, this is a small thing and I guess the problem is that you´re not receiving anything from master. Take a look at the example, I´m sure you will find it beneficial.

Regards,
Deni
0 Likes
User15090
Level 1
Level 1
Hi Deni,

I sat down yesterday and read the SPI Chapter again from the reference manual and found out my problem. I forgot to invert the CS singal on the slave side. Adding this one line to the code fixed the problem 🙂

AndThanks for your quick answer and the link. It for sure seems interessting as a reference examples.

Greetings
adit
0 Likes