Possible Bug in SPI_MASTER app

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

cross mob
User11773
Level 4
Level 4
First like received First solution authored
I'm getting no correct data back from SPI_MASTER_Transfer. The data is sent correctly. The SPI slave device responds correctly. I am using a scope to look at signals.
Perhaps I'm doing something wrong, but ... help

  uint8_t SPI_Read_Byte( uint8_t Port, uint8_t RegisterNum )
{
uint8_t SendData[4];
uint8_t GetData[4];
SPI_MASTER_STATUS_t Status;

SendData[0] = (RegisterNum & 0x7F) | 0x80; // MSB is R/nW

SendData[1] = 0xff;
SendData[2] = 0x00;

XMC_USIC_CH_SetFrameLength( SPI_MASTER_0.channel, 24);

if ( Port == SLAVE_0 )
SPI_MASTER_EnableSlaveSelectSignal(&SPI_MASTER_0, SPI_MASTER_SS_SIGNAL_0 );
else
SPI_MASTER_EnableSlaveSelectSignal(&SPI_MASTER_0, SPI_MASTER_SS_SIGNAL_1 );


// Send & receive at same time
Status = SPI_MASTER_Transfer( &SPI_MASTER_0, SendData, GetData, 3 );

// block, wait to complete
while(SPI_MASTER_0.runtime->tx_busy);
while(SPI_MASTER_0.runtime->rx_busy);

return( GetData[0] );

} // SPI_Read_Byte


I've tried with Interrupts & with Direct mode. Also with & without FIFOs.
On a XMC1300 boot card. I've just ordered 10 engineering prototypes of a custom board with XMC1302 Q024.
I need some support.
Thanks in advance.
0 Likes
6 Replies
chismo
Employee
Employee
First like received
Hello,

Yes, there is a bug in SPI_MASTER app.

Please refer to the following thread:
https://www.infineonforums.com/threads/4160-Possible-bug-in-SPI_MASTER-app

The workaround is to replace the mentioned code in the generated DAVE file spi_master.c.
Can you try and see if it fixes the problem?

Regards,
Min Wei
0 Likes
User11773
Level 4
Level 4
First like received First solution authored
That referenced thread is for the XMC4500, can I assume it is the same for XMC1300?
Also, my problem is I get nothing back. Its like the MISO is not connect to the pin.

When debugging, under SPI_MASTER_0.config nothing about the MISO input pin. I've added an extra byte to to see if I can see the data shift as per "the SPI bug". But I can't.

DAVE version 4.2.8
0 Likes
User11773
Level 4
Level 4
First like received First solution authored
Some more detail on problem. Attention Infineon!

I'm using P2.6 as MISO. P2.0 as MOSI, P0.7 as SCLK & P0.9 as Slave Select & P0.12 as Slave Select 1.
DAVE sets DX0CR DSEL to G (6). This means the input "pin" is USIC0_CH0.DX3INS.
BUT - doesn't initialize DX3CR ! So it would default to P2.2.

I've placed a USIC0_CH0->DX3CR = 0x04U; in my initialization code .

Is there a step by step source code on how to initialize a SPI port with using DAVE?
0 Likes
User11773
Level 4
Level 4
First like received First solution authored
Another issue I've found:

When I used "SPI_MASTER_Transfer( &SPI_MASTER_0, SendData, GetData, 2 );"
The first byte sent is correct, but the second byte sent appears to be the same SendData[0], not SendData[1]!
SendData[] = 0x80 , 0xFF, 0x00
I see 0x80 then 0x80 on the scope.
0 Likes
chismo
Employee
Employee
First like received
Hello,

Yes, I see that with P2.6 selected as MISO, DX3CR register is not configured correctly.
To do this, besides the DSEL bit field, INSW bit also has to be set, i.e.:

USIC0_CH0->DX3CR = 0x14U;


I have further tested your code with some adaptations on an XMC1300 boot kit and it worked fine for me.
For the DAVE project, I have:
- used all default DAVE settings (hence only 1 slave select line is configured)
- configure the pin out based on your list
- connect P2.6 to P2.0 with a wire

On the oscilloscope, the output data on P2.0 looks fine for my case too.
My adapted code is as follows:


#include

#define SLAVE_0 0

uint8_t result;

//Precondition: Operation mode should be 'Full Duplex"
//Description:
//Transmits and Receives 10 bytes of data from slave in parallel.

uint8_t SPI_Read_Byte( uint8_t Port, uint8_t RegisterNum )
{
uint8_t SendData[4];
uint8_t GetData[4];
SPI_MASTER_STATUS_t Status;

SendData[0] = (RegisterNum & 0x7F) | 0x80; // MSB is R/nW
SendData[1] = 0xff;
SendData[2] = 0x00;

XMC_USIC_CH_SetFrameLength( SPI_MASTER_0.channel, 24);

if ( Port == SLAVE_0 )
SPI_MASTER_EnableSlaveSelectSignal(&SPI_MASTER_0, SPI_MASTER_SS_SIGNAL_0 );
else
SPI_MASTER_EnableSlaveSelectSignal(&SPI_MASTER_0, SPI_MASTER_SS_SIGNAL_1 );

// Send & receive at same time
Status = SPI_MASTER_Transfer( &SPI_MASTER_0, SendData, GetData, 3 );

// block, wait to complete
while(SPI_MASTER_0.runtime->tx_busy);
while(SPI_MASTER_0.runtime->rx_busy);

return( GetData[0] );

} // SPI_Read_Byte

int main(void)
{
DAVE_STATUS_t status;

status = DAVE_Init(); // SPI_MASTER_Init() is called from DAVE_Init()

if(status == DAVE_STATUS_SUCCESS)
{
}
else
{
XMC_DEBUG("main: Application initialization failed");
while(1U)
{
}
}

USIC0_CH0->DX3CR = 0x14U;
result = SPI_Read_Byte(0, 0);
return 1U;
}


Can you check if this now works for you?

Regards,
Min Wei
0 Likes
User11773
Level 4
Level 4
First like received First solution authored
Sorry for delay.

I've added :
USIC0_CH0->DX3CR = 0x4U;

after SPI init to get it work.
Thanks.
0 Likes