Hi,
I have 2 XMC4500. 1 configured as Master, 1 as Slave.
I can receive the words, which are sent by the master in the slave.
But as soon i want to write data back via "SPI003_WriteData", the data, which the slave writes into the buffer will be transmitted completely different and the received bytes from the master will also be different.
And i dont understand why.
Can someone tell me, what i am doing wrong or what i am missing in the Slave implementation?
Using Dave 3.1.10
Used Configuration:
- Standard FullDuplex Mode
- Word length: 16
- Frame Length: 16
- Clock Phase Control: No Delay
- Clock Polarity Control: No Inversion
- Transmit/Receive LSB first
- Transmit and Receive FIFO: Size 2, Trigger Limit 1
Slave:
- Falling Edge trigger ( for triggering DX2T interrupt)
- Enable Slave Select Input Polarity
Master:
Slave: This Function will be called as often according my protocol length
I have 2 XMC4500. 1 configured as Master, 1 as Slave.
I can receive the words, which are sent by the master in the slave.
But as soon i want to write data back via "SPI003_WriteData", the data, which the slave writes into the buffer will be transmitted completely different and the received bytes from the master will also be different.
And i dont understand why.
Can someone tell me, what i am doing wrong or what i am missing in the Slave implementation?
Using Dave 3.1.10
Used Configuration:
- Standard FullDuplex Mode
- Word length: 16
- Frame Length: 16
- Clock Phase Control: No Delay
- Clock Polarity Control: No Inversion
- Transmit/Receive LSB first
- Transmit and Receive FIFO: Size 2, Trigger Limit 1
Slave:
- Falling Edge trigger ( for triggering DX2T interrupt)
- Enable Slave Select Input Polarity
Master:
Code:
void cSpiMaster::WriteMessage(const uint16_t *pSPISendData, const uint16_t& len)
{
uint16_t tmp, i;
uint8_t Status1 = 0;
uint8_t Status2 = 0;
/* Enable start of frame */
EnableStartOfFrame(spi);
/* Start sending len bytes of data from buffer */
for (i=0; i<len-1; i++)
{
SPI001_ClearFlag(&spi,SPI001_RECV_IND_FLAG);
SPI001_ClearFlag(&spi,SPI001_ALT_RECV_IND_FLAG);
SPI001_WriteData(&spi, pSPISendData,SPI001_STANDARD);
do
{
Status1 = SPI001_GetFlagStatus(&spi,SPI001_RECV_IND_FLAG);
Status2 = SPI001_GetFlagStatus(&spi,SPI001_ALT_RECV_IND_FLAG);
}while(!((Status1 == SPI001_SET) || (Status2 == SPI001_SET)));
SPI001_ReadData(&spi,&tmp); // dummy read
pSPISendData++;
}
/* Enable end of frame */
EnableEndOfFrame(spi);
SPI001_ClearFlag(&spi,SPI001_RECV_IND_FLAG);
SPI001_ClearFlag(&spi,SPI001_ALT_RECV_IND_FLAG);
/* Send the last byte
* After sending this data, frame will be finished since we
* enable end of frame
* */
SPI001_WriteData(&spi, pSPISendData,SPI001_STANDARD);
do
{
Status1 = SPI001_GetFlagStatus(&spi,SPI001_RECV_IND_FLAG);
Status2 = SPI001_GetFlagStatus(&spi,SPI001_ALT_RECV_IND_FLAG);
}while(!((Status1 == SPI001_SET) || (Status2 == SPI001_SET)));
SPI001_ReadData(&spi, &tmp); // dummy read
}
Slave: This Function will be called as often according my protocol length
Code:
bool cSpiSlave::ReadWord(uint16_t* word)
{
*word = SPI_DUMMY_READ_WORD;
uint16_t tmp = 0;
uint8_t Status1 = 0;
uint8_t Status2 = 0;
do
{
Status1 = SPI003_GetFlagStatus(&spi,SPI003_RECV_IND_FLAG);
Status2 = SPI003_GetFlagStatus(&spi,SPI003_ALT_RECV_IND_FLAG);
}while(!((Status1 == SPI003_SET) || (Status2 == SPI003_SET)));
/* Read data received from flash chip to buffer */
SPI003_ReadData(&spi,&tmp);
*word = tmp;
// Clear flag
SPI003_ClearFlag(&spi,SPI003_RECV_IND_FLAG);
SPI003_ClearFlag(&spi,SPI003_ALT_RECV_IND_FLAG);
// Send read data back
SPI003_WriteData(&spi,&tmp,SPI003_STANDARD);
return true;
}