2018-03-02 12:52 AM
STM32F031 is configurated as SPI Slave, CRC result can not be send out correctly. Attached the whole project.
I also designed one SPI master by another STM32F031 for this testing. The waveform that master sent is right.
MxCube Initial code:
SPI_InitStruct.TransferDirection = LL_SPI_FULL_DUPLEX;
SPI_InitStruct.Mode = LL_SPI_MODE_SLAVE; SPI_InitStruct.DataWidth = LL_SPI_DATAWIDTH_16BIT; SPI_InitStruct.ClockPolarity = LL_SPI_POLARITY_Low; SPI_InitStruct.ClockPhase = LL_SPI_PHASE_1EDGE; SPI_InitStruct.NSS = LL_SPI_NSS_HARD_INPUT; SPI_InitStruct.BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV128; SPI_InitStruct.BitOrder = LL_SPI_MSB_FIRST; SPI_InitStruct.CRCCalculation = LL_SPI_CRCCALCULATION_ENABLE; SPI_InitStruct.CRCPoly = 0x1021; LL_SPI_Init(SPI1, &SPI_InitStruct);LL_SPI_SetStandard(SPI1, LL_SPI_PROTOCOL_MOTOROLA);
LL_SPI_SetCRCWidth(SPI1, LL_SPI_CRC_16BIT);
LL_SPI_DisableNSSPulseMgt(SPI1);
Send data and Enable CRCNext in Main function.
for(TxCnt=3;TxCnt<11;TxCnt++)
{ while(LL_SPI_GetTxFIFOLevel(SPI1)==LL_SPI_TX_FIFO_FULL); LL_SPI_TransmitData16(SPI1,TxCnt); if(TxCnt==10) { while(LL_SPI_GetTxFIFOLevel(SPI1)!=LL_SPI_TX_FIFO_EMPTY); i=LL_SPI_GetTxCRC(SPI1); LL_SPI_SetCRCNext(SPI1); } }