AnsweredAssumed Answered

SPI: 24bit SPI Slave for KEA, different power on sequence of slave & master, different SO frame

Question asked by Martin Zhang on Oct 24, 2018
Latest reply on Oct 30, 2018 by Kerry Zhou

I have 2xFRDM-KEAZ128Q80, one used as SPI master, one used as SPI Slave. I want to simulate 24bit SPI communication, but I find that different power-on sequence results in different SO outputing SPI bytes' sequence.

I have no idea about what's wrong. How can I ensure the right SO output sequence?

 

KEA DEMO Board: FRDM-KEAZ128Q80,

Test Device: Logic Analyzer LA1010

IDE: CW11

 

SPI Port : master port connect to same slave port (PTG4-4, 5-5, 6-6, 7-7)

SPI Master Port:SPI1 , PTG_4_5_6_7

SPI Slave Port:SPI1 , PTG_4_5_6_7

 

I have uploaded the demo code to attachments.

Main SPI Master Code:

void SPIMaster_Task()
{
 uint8_t i = 0;
 for(i = 0; i < SPI1_TX_DATA_SIZE; i++)
 {
  gu8SPI1_TxBuff[i] = 0x55 + i;
 }
 
 // control cs manually
 GPIO_PinClear(GPIO_PTG7); //enable cs
 SPI_TransferWait(SPI1,gu8SPI1_RxBuff,gu8SPI1_TxBuff,SPI1_TX_DATA_SIZE); // size=3
 GPIO_PinSet(GPIO_PTG7);   //diable cs

}

 

Main SPI Slave Code:

void SPISlave_Task()
{
 uint32_t i = 0;
 gu8SPI1_TxBuff[0] = 0x55;
 gu8SPI1_TxBuff[1] = 0x80;
 gu8SPI1_TxBuff[2] = 0xAA;

 for(i = 0; i < SPI1_TX_DATA_SIZE; i++)
 {
  while(!SPI_IsSPRF(SPI1)){rxIntCnt ++;};
  gu8SPI1_RxBuff[i] = SPI_ReadDataReg(SPI1);
  while(!SPI_IsSPTEF(SPI1)){txIntCnt ++;};
  SPI_WriteDataReg(SPI1,gu8SPI1_TxBuff[i]);
 }

}

 

Result:

Right  SO sequence  should be 0x55 0x80 0xAA.

1.Master Power-on first:

1) error: 0xAA 0x55 0x80

MasterPowerOnFirst_1

 

2)error: 0xAA 0x55 0x80

MasterPowerOnFirst_2

 

2. SPI poweron first

1)error: 0x80 0xAA 0x55

SlavePowerOnFirst_1

 

2)right: 0x55 0x80 0xAA

SlavePowerOnFirst_2

Outcomes