XMC1100 SPI Problem

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

cross mob
Not applicable
Hi!

I am currently working on a SPI-Configuratoin on the XMC1100.
When I start debugging the program and take a look at the Registers, I see that CGATSTAT0.USIC0 = 0..

I am also measuring the output clock and see absolutely nothing.

Can anybody help me configurating the SPI correctly?


#include "XMC1100.h"


int main(void)
{
// Clock configuration
SCU_GENERAL->PASSWD = 0x000000C0UL; // disable bit protection
SCU_CLK->CLKCR = 0x3FF00100UL; // MCLK = 32MHz, PCLK = 32MHz
while((SCU_CLK->CLKCR & SCU_CLK_CLKCR_VDDC2LOW_Msk));
SCU_GENERAL->PASSWD = 0x000000C3UL; // enable bit protection
SystemCoreClockUpdate();

/* USIC0 Channel 1 is used as SSC
SPI-Clock: P1.4 am XMC1100 (USIC0_CH1.SCLKOUT ALT2)
SPI-MTSR : P1.3 am XMC1100 (USIC0_CH1.DOUT0 ALT7)
SPI-MRST : P1.2 am XMC1100 (USIC0_CH1.DX0B INPUT)
*/

// Disable THE CLOCK for USIC0
SCU_GENERAL->PASSWD = 0x000000C0UL;
SCU_CLK->CGATCLR0 = 0x8; //USIC0=1; Disable Gating
SCU_GENERAL->PASSWD = 0x000000C3UL;

//P1.1 CH1 SPI-Slave Select, OUT ALT7
PORT1->IOCR0 = 23 << 11;
//P1.2 CH1 SPI-MISO, IN
// Default input
//P1.3 CH1 SPI-MOSI, OUT ALT7
PORT1->IOCR0 = 23 << 19;
//P1.4 CH1 SPI-CLK, OUT ALT2
PORT1->IOCR4 = 18 << 3;


// Switch on the USIC Module (bit protection)
USIC0_CH1->KSCFG =0x3; //MODEN=1, BPMODEN=1;

// Channel control register
USIC0_CH1->CCR = 0x0001; // Select SSC Mode for USIC Channel 0

// BAUDRATE config: 200 kbit/s
USIC0_CH1->FDR = 0x000081F3UL; // DM=10 (Fraction div. mode) Step= 499
USIC0_CH1->BRG = 0x80260000UL; // SCLKCFG=10 (passiv low, stable data at rising edge), PDIV=38

// Input Control Register for MRST
USIC0_CH1->DX0CR = 0x0011; // INSW=1 (connect pin to SSC), DSEL= 011 (for DX0B input)

// Protocol Control register for SSC
USIC0_CH1->PCR = 0x0001 | 1 << 16 | 2; // MSLSEN=1 (needed for master mode), Activate Slave Select 0 (P1.1), Set Slave Select to direct mode

//Transmit Control Register
USIC0_CH1->TCSR = 0x0502; // TDEN=01 (enable transmission), TDSSM = 1 (send TBUF only once, IMPORTANT FOR LEIA)

// Shift Control Register
USIC0_CH1->SCTR = 0x0F0F0101; // FLE=WLE= 0xF (Frame=Word-Length = 16 bit) TRM=01 (allow data transfer) ,SDIR=1 (MSB First)

// Enable interrupt node 9 (USIC0) with priority 1 and enable alternative receive interrupt (NOT RIEN IF WORD=FRAME LENGTH)
NVIC->IP[2] = 1<<8; // set priority for node 9 to 1 (great priority)
NVIC->ISER[0] = 1<<9; // Interrupt node 9 enable

// Enable alternative Receive Interrupt
USIC0_CH1->CCR |= 0x01UL<<15; // AIEN enable .... alternativ -> USIC0_CH0->CCR |= USIC_CH_CCR_TSIEN_Msk; // TSIEN erfolgt nach erfolgreichem Senden -> neue Daten können in TBUF geschrieben werden


USIC0_CH1->TBUF[0] = 0x4010;
USIC0_CH1->TBUF[0] = 0x0000;

USIC0_CH1->TBUF[0] = 0x4019;
USIC0_CH1->TBUF[0] = 0xFF00;

/* Placeholder for user application code. The while loop below can be replaced with user application code. */
while(1U)
{
USIC0_CH1->TBUF[0] = 0x4010;
while(USIC0_CH1->TRBSR & (1 << 11));
USIC0_CH1->TBUF[0] = 0x0000;
while(USIC0_CH1->TRBSR & (1 << 11));

USIC0_CH1->TBUF[0] = 0x4019;
while(USIC0_CH1->TRBSR & (1 << 11));
USIC0_CH1->TBUF[0] = 0xFF00;
while(USIC0_CH1->TRBSR & (1 << 11));
}
}
0 Likes
5 Replies
chismo
Employee
Employee
First like received
Hello,

I think there are 3 issues with the code:

1) P1_IOCR0 configuration:
- the bit field for P1.1 is being overwritten with the second write (for P1.2/3?). I think it is better to use "OR equals" instead.
- P1.2 is being configured for MOSI, but in the comments, P1.3 is mentioned.

2) TCSR configuration:
- SELMD bit is being set to 1. This enables the dynamic selection of SELO lines based on the TBUF input location.
- In the subsequent code, you are using TBUF[0] which effectively clears PCR.SELO to 0.
- I will suggest to either disable the SELMD or write to TBUF[1].

3) TRBSR status
- I assume the actual transmission is taking place in the while loop, i.e. the write to TBUF outside of the while loop should be commented off.
- In the while loop, TRBSR is being checked for the status but this register is applicable only when TXFIFO is being used. From the code, I see that you are using the standard buffer instead (TBUF).
- in this case, it is better to check for TCSR.TDV bit instead to know when the next transmit data can be written.
For example:

USIC0_CH1->TBUF[1] = 0x4010;
while((USIC0_CH1->TCSR & 0x80)>>7);


I hope this helps.

Regards,
Min Wei
0 Likes
Not applicable
Thank you very much for your quick response!

I changed everything according to what you said.

Now I can see something clock like on the oscilloscope but it has just a ~ 100 mV peak and doesn't look rectangular at all.

#include "XMC1100.h"


int main(void)
{
// Clock configuration
SCU_GENERAL->PASSWD = 0x000000C0UL; // disable bit protection
SCU_CLK->CLKCR = 0x3FF00100UL; // MCLK = 32MHz, PCLK = 32MHz
while((SCU_CLK->CLKCR & SCU_CLK_CLKCR_VDDC2LOW_Msk));
SCU_GENERAL->PASSWD = 0x000000C3UL; // enable bit protection
SystemCoreClockUpdate();

/* USIC0 Channel 1 is used as SSC
SPI-Clock: P1.4 am XMC1100 (USIC0_CH1.SCLKOUT ALT2)
SPI-MTSR : P1.3 am XMC1100 (USIC0_CH1.DOUT0 ALT7)
SPI-MRST : P1.2 am XMC1100 (USIC0_CH1.DX0B INPUT)
*/

// Disable THE CLOCK for USIC0
SCU_GENERAL->PASSWD = 0x000000C0UL;
SCU_CLK->CGATCLR0 = 0x8; //USIC0=1; Disable Gating
SCU_GENERAL->PASSWD = 0x000000C3UL;

//P1.1 CH1 SPI-Slave Select, OUT ALT7
PORT1->IOCR0 |= 23 << 11;
//P1.2 CH1 SPI-MISO, IN
// Default input
//P1.3 CH1 SPI-MOSI, OUT ALT7
PORT1->IOCR0 |= 23 << 27;
//P1.4 CH1 SPI-CLK, OUT ALT2
PORT1->IOCR4 |= 18 << 3;


// Switch on the USIC Module (bit protection)
USIC0_CH1->KSCFG =0x3; //MODEN=1, BPMODEN=1;

// Channel control register
USIC0_CH1->CCR = 0x0001; // Select SSC Mode for USIC Channel 0

// BAUDRATE config: 200 kbit/s
USIC0_CH1->FDR = 0x000081F3UL; // DM=10 (Fraction div. mode) Step= 499
USIC0_CH1->BRG = 0x80260000UL; // SCLKCFG=10 (passiv low, stable data at rising edge), PDIV=38

// Input Control Register for MRST
USIC0_CH1->DX0CR = 0x0011; // INSW=1 (connect pin to SSC), DSEL= 011 (for DX0B input)

// Protocol Control register for SSC
USIC0_CH1->PCR = 0x0001 | 1 << 16 | 2; // MSLSEN=1 (needed for master mode), Activate Slave Select 0 (P1.1), Set Slave Select to direct mode

//Transmit Control Register
USIC0_CH1->TCSR = 0x0500; // TDEN=01 (enable transmission), TDSSM = 1 (send TBUF only once, IMPORTANT FOR LEIA)

// Shift Control Register
USIC0_CH1->SCTR = 0x0F0F0101; // FLE=WLE= 0xF (Frame=Word-Length = 16 bit) TRM=01 (allow data transfer) ,SDIR=1 (MSB First)

// Enable interrupt node 9 (USIC0) with priority 1 and enable alternative receive interrupt (NOT RIEN IF WORD=FRAME LENGTH)
NVIC->IP[2] = 1<<8; // set priority for node 9 to 1 (great priority)
NVIC->ISER[0] = 1<<9; // Interrupt node 9 enable

// Enable alternative Receive Interrupt
USIC0_CH1->CCR |= 0x01UL<<15; // AIEN enable .... alternativ -> USIC0_CH0->CCR |= USIC_CH_CCR_TSIEN_Msk; // TSIEN erfolgt nach erfolgreichem Senden -> neue Daten können in TBUF geschrieben werden

/* Placeholder for user application code. The while loop below can be replaced with user application code. */
while(1U)
{
;
USIC0_CH1->TBUF[1] = 0x4010;

while((USIC0_CH1->TCSR & 0x80) >> 7);
/*
USIC0_CH1->TBUF[1] = 0x0000;
while((USIC0_CH1->TCSR & 0x80) >> 7);

USIC0_CH1->TBUF[1] = 0x4019;
while((USIC0_CH1->TCSR & 0x80) >> 7);
USIC0_CH1->TBUF[1] = 0xFF00;
while((USIC0_CH1->TCSR & 0x80) >> 7);
*/
}
}
0 Likes
chismo
Employee
Employee
First like received
Hello,

From your description, it is not clear what is wrong.

Is there another pin with SCLKOUT function that you can test with? Are the DOUT, SELO lines also showing similar problems?
And is the baud rate correct at ~200kbits/s?

Regards,
Min Wei
0 Likes
Not applicable
I think it would be easier if I had a working SPI configuration which I can adapt to my needs.

Is there a working configuration out there for the XMC1100 Boot Kit?
Has anyone tried it without APPs and manged to measure a correct signal?

All examples I found so far were not very helpful and the XMC1100 user manual isn't developer friendly.

I would be very thankful.
0 Likes
lock attach
Attachments are accessible only for community members.
chismo
Employee
Employee
First like received
Hello,

You can use the following example code that is using just the XMC Lib, without any DAVE apps.

This code is taken from the list of XMC Lib examples provided in the download file (http://dave.infineon.com/Libraries/XMCLib/XMC_Peripheral_Library_v2.1.2.zip) but adapted for the tx pin from P1.0 to P0.14.

Alternatively, you can also find a SPI loopback example from the following link:
http://www.infineon.com/dgdl/Infineon-XMC1100_SPI_Master_Loopback-AE-v01_00-EN.zip?fileId=5546d46250...

Both should work.

Regards,
Min Wei
0 Likes