Infineion xmc4500 relax kit spi communication

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

cross mob
Not applicable
hi

i m try to communicate with peripheral device using xmc4500 relax kit spi and not able to communicate, i need help.
Below is my source code and configurations of the device.I am not sure if data send through SPI001_WriteData(&SPI001_Handle0,&data,SPI001_STANDARD); to the peripheral device.

can anyone help me in undestanding the procedure to write MOS,MISO,CLKOUT and SLAVE_SELECT pins.






#include //Declarations from DAVE3 Code Generation (includes SFR declaration)

uint16_t rdata,data[]={0x01,0x0c,0x03,0x00};
uint16_t tbrb;
int main(void)
{
// status_t status; // Declaration of return variable for DAVE3 APIs (toggle comment if required)
uint8_t i;

DAVE_Init(); // Initialization of DAVE Apps
PORT0->IOCR0 |= 0x80UL <<8 ;
PORT0->PDR0 |= 0x02UL <<8;
PORT0->HWSEL &= ~(0x0CUL);
SPI001_Handle0.USICRegs->DX2CR &= ~(0x10UL);
//SPI001_Handle0.USICRegs->DX2CR &= ~(0x0FUL);
SPI001_Handle0.USICRegs->BRG &= ~(0xFCUL <<24);
SPI001_Handle0.USICRegs->PCR_SSCMode |=0x07UL;
SPI001_Handle0.USICRegs->DX1CR &= ~(0x08UL);
SPI001_Handle0.USICRegs->SCTR |= (0x01UL << 8);
SPI001_Handle0.USICRegs->KSCFG |= 0x01UL;
SPI001_Handle0.USICRegs->CCR |= 0x01UL;

//slave select = 1
SPI001_Handle0.USICRegs->PCR_SSCMode |= 0x01UL << 16;
tbrb=SPI001_Handle0.USICRegs->CCFG;

for(i=0;i<4;i++)
{
SPI001_WriteData(&SPI001_Handle0,&data,SPI001_STANDARD);
rdata=data;
}
// SPI001_Handle0.USICRegs->PCR_SSCMode &= ~(0x01UL << 16);
while(1)
{

}
return 0;
}


Regards

Rinku
0 Likes
5 Replies
Marillion
Employee
Employee
5 sign-ins First solution authored First like given
Hello Rinku,
You are using DAVE 🙂 but why not using the “Manual Pin Assignment” feature of DAVE in order to connect the pins and to make your code example running?
Your main.c can be reduced to the following code:

#include //Declarations from DAVE3 Code Generation (includes SFR declaration)
uint16_t rdata,data[]={0x01,0x0c,0x03,0x00};
uint16_t tbrb;
int main(void)
{
uint8_t i;
DAVE_Init(); // Initialization of DAVE Apps
for(i=0;i<4;i++)
{
SPI001_WriteData(&SPI001_Handle0,&data,SPI001_STANDARD); //send one byte
}
while(1);
return 0;
}

1) Create a new project: File > New > Project >Infineon > DAVE Project. Choose a project name and select “DAVE CE Project”. Select the divice which is mounted on your relax kit.
2) Add SPI App to your project: App Selection View > SPI001
3) Assign pins to the SPI: S/W App Connectivity View > SPI001/0 > (right click mouse) Manual Pin Assignment. Assign pins for ChipSelect, Clk, MTSR (Master Transmit Slave Receive = MOSI) and MRST (Master Receive Slave Transmit=MISO)
4) Configure SPI with GUI: Double click on SPI001/0 in “S/W App Connectivity View “ (in the first test I would recommend to work with the default settings)
5) Generate the code (flash icon)
6) Compile the code (bin icon)
7) Flash and debug the code (bug icon). Run your main.

Which pins do you need for SPI in SPI Master Mode:
MOSI=MTSR= UxCy.DOUT0
MISO=MRST= UxCy.DX0
Chip Select = UxCy.SELOz
Clock=SCLKOUT

Which pins do you need for SPI in SPI Slave Mode:
MOSI=MTSR= UxCy.DX0
MISO=MRST= UxCy.DOUT0
Chip Select = UxCy.DX2
Clock= UxCy.DX1

I hope this will help to make your SPI code running.

Marillion
0 Likes
Not applicable
Hello Marillion,

Thanks for the reply. but still i have some issues.

I have already configured the SPI as you said above.I am using Full Duplex SPI. I have manually assigned my pins to PORT0 as listed below :

MRST = P0.0
MTSR = P0.1
SCK(clock) = P0.10
CS(Chip Select) = P0.9

Used settings in SPI GUI
transmit/receive MSB first.
TX FIFO and RX FIFO size ==32
RX and TX Trigger limit =1



Now I want to send a command (data[]={0x01,0x0C,0x03,0x00}) to my peripheral controller and in response to that i expect to receive 6 bytes of data from peripheral controller but i am not getting anything but FIFO Receive Buffer interrupt.

Issue:
Below is my sample program to send and receive data and I am not able to receive data( from peripheral). getting interrupt (2 times) but not getting any data.

#include //Declarations from DAVE3 Code Generation (includes SFR declaration)
uint16_t rdata[6],data[]={0x01,0x0c,0x03,0x00};

int main(void)
{
uint8_t i;
DAVE_Init(); // Initialization of DAVE Apps
for(i=0;i<4;i++)
{
SPI001_WriteData(&SPI001_Handle0,&data,SPI001_STANDARD); //send one byte
}
while(1);
return 0;
}


void receive(void) ///ISR to receive.......... FIFO Receive Buffer Interrupt
{
for(j=0;j<6;j++)
{
SPI001_ReadData(&SPI001_Handle0,&r);
}
}

Regards

Rinku
0 Likes
Marillion
Employee
Employee
5 sign-ins First solution authored First like given
Hi Rinku,

each time you send a byte via SPI you also receive one byte via SPI!

In the first step I propose to switch off the interrupts and do the write and read in a sequence in main:
- send 4 bytes
- flush the receive FIFO
- send 6 dummy bytes
- read the 6 bytes out of the receive FIFO.

or

- send 4 command bytes
- send 6 dummy bytes (to get the response)
- read the 10 bytes out of the receive FIFO (this is what SPI001_ReadData is doing)

Marillion
0 Likes
Not applicable
Hi Marillion

Is it necessary to send 6 dummy bytes to receive the response data from peripheral controller??

When the data is received, it will be shifted to RECEIVE FIFO buffer(6 bytes), so cant i read it directly from buffer??

and i don't want to wait to read data in main, want to read it in interrupt whenever the data is received... Please advise..

Thanks
Rinku
0 Likes
Marillion
Employee
Employee
5 sign-ins First solution authored First like given
Hi Rinku,

"Is it necessary to send 6 dummy bytes to receive the response data from peripheral controller??"
This is how SPI always works. The master device (XMC) has to provide the clock. The slave device is able to send data only on clock provided by the master..


"When the data is received, it will be shifted to RECEIVE FIFO buffer(6 bytes), so cant i read it directly from buffer??"
Data are shifted to the RECEIVE FIFO. SPI001_ReadData will read the data from the RECEIVE FIFO.


"and i don't want to wait to read data in main, want to read it in interrupt whenever the data is received"
The data can be read from FIFO alos in interrupt. But the transmission of data from the Slave to the Master must be initiated by the master (sending dummy bytes).

Marillion
0 Likes