Hi,
I got a problem about SPI slave component with 9S08DZ16, the MISO always outputs garbage data when I call SS1_SendBlock() function, and it also causes the SS1_RecvBlock() function receives wrong data. If I don't use the SS1_SendBlock() function, the data received from SS1_RecvBlock() function is correct, my test environment as below:
MC9S12XDG512 is the SPI master, it uses SM1_SendBlock() to send 4 bytes data every 1.5ms.
MC9S08DZ16 is the SPI slave, SPI interrupt is enabled, it receives 4 bytes data and then send 4 bytes data(const variable) in the SS1_OnFullRxBuf() function, here is the code of the function.
void SS1_OnFullRxBuf(void){ /* Write your code here ... */ char buf[4]; word rcv_len, snd_len; SS1_RecvBlock(buf, 4, &rcv_len); SS1_SendBlock(buf_tx, 4, &snd_len);}
Below comment is the SPI component setting of the ProcessorExpert
[ SPI slave setting ]
/*** ===================================================================** Method : SS1_Init (bean SynchroSlave)**** Description :** Initializes the associated peripheral(s) and the bean internal ** variables. The method is called automatically as a part of the ** application initialization code.** This method is internal. It is used by Processor Expert only.** ===================================================================*/void SS1_Init(void){ SerFlag = 0; /* Reset all flags */ ErrFlag = 0; /* Reset all flags in mirror */ SS1_EnEvent = TRUE; /* Enable events */ SS1_InpLen = 0; /* No char in the receive buffer */ InpIndxW = InpIndxR = 0; /* Set the indices to the start of the receive buffer */ SS1_OutLen = 0; /* No char in the transmit buffer */ OutIndxW = OutIndxR = 0; /* Set the indices to the start of the transmit buffer */ #pragma MESSAGE DISABLE C4002 /* Disable warning C4002 "Result not used" */ (void)SPIS; /* Read the status register */ (void)SPID; /* Read the data register */ /* SPIC2: ??=0,??=0,??=0,MODFEN=0,BIDIROE=0,??=0,SPISWAI=0,SPC0=0 */ setReg8(SPIC2, 0x00); /* Configure the SPI port - control register 2 */ /* SPIC1: SPIE=1,SPE=0,SPTIE=0,MSTR=0,CPOL=0,CPHA=1,SSOE=0,LSBFE=0 */ setReg8(SPIC1, 0x84); /* Configure the SPI port - control register 1 */ SPIC1_SPE = 1; /* Enable device */ SPID = SS1_EOF; /* Store the empty char to the transmit register */}
[ SPI Master setting ]
/*** ===================================================================** Method : SM1_Init (component SynchroMaster)**** Description :** Initializes the associated peripheral(s) and the component ** internal variables. The method is called automatically as a ** part of the application initialization code.** This method is internal. It is used by Processor Expert only.** ===================================================================*/void SM1_Init(void){ /* SPI0CR1: SPIE=0,SPE=0,SPTIE=0,MSTR=0,CPOL=0,CPHA=1,SSOE=0,LSBFE=0 */ SPI0CR1 = 0x04U; /* Reset the device register */ (void)SPI0SR; /* Read the status register */ (void)SPI0DR; /* Read the device register */ /* SPI0BR: ??=0,SPPR2=1,SPPR1=0,SPPR0=0,??=0,SPR2=0,SPR1=1,SPR0=0 */ SPI0BR = 0x42U; /* Set the baud rate register */ /* SPI0CR2: ??=0,??=0,??=0,MODFEN=1,BIDIROE=0,??=0,SPISWAI=0,SPC0=0 */ SPI0CR2 = 0x10U; /* Set control register 2 */ /* SPI0CR1: SPIE=1,SPE=1,SPTIE=0,MSTR=1,CPOL=0,CPHA=1,SSOE=1,LSBFE=0 */ SPI0CR1 = 0xD6U; /* Set control register 1 */ SerFlag = 0U; /* Reset all flags */ ErrFlag = 0U; /* Reset all flags in mirror */ OnFreeTxBuf_semaphore = FALSE; /* Clear the OnFreeTxBuf_semaphore */ SM1_InpLen = 0U; /* No char in the receive buffer */ InpPtrR = InpBuffer; /* Set read pointer on the first item in the receive buffer */ InpPtrW = InpBuffer; /* Set write pointer on the first item in the receive buffer */ SM1_OutLen = 0U; /* No char in the transmit buffer */ OutPtrR = OutBuffer; /* Set read pointer on the first item in the transmit buffer */ OutPtrW = OutBuffer; /* Set write pointer on the first item in the transmit buffer */}
Do I have any wrong usage of SS1_SendBlock() function?