AnsweredAssumed Answered

SPI CRC problem with dma on stm32f0

Question asked by Jenabzadeh.Morteza on Dec 31, 2016
Latest reply on Jan 2, 2017 by Jenabzadeh.Morteza

Hello

I have connected two uc through SPI .

My target is to send data with DAM+CRC.

one of them is slave stm32f030 and the other one  is stm32f429.

I'm using cubeMX for confige spi and dma  registers .

 

Here is slave config:

 

* SPI1 init function */
static void MX_SPI1_Init(void)
{

hspi1.Instance = SPI1;
hspi1.Init.Mode = SPI_MODE_SLAVE;
hspi1.Init.Direction = SPI_DIRECTION_2LINES_RXONLY;
hspi1.Init.DataSize = SPI_DATASIZE_16BIT;
hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
hspi1.Init.NSS = SPI_NSS_SOFT;
hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_ENABLE;
hspi1.Init.CRCPolynomial = 50835;
hspi1.Init.CRCLength = SPI_CRC_LENGTH_16BIT;
hspi1.Init.NSSPMode = SPI_NSS_PULSE_DISABLE;
if (HAL_SPI_Init(&hspi1) != HAL_OK)
{
Error_Handler();
}

}

 

And here is master config:

 

/* SPI4 init function */
static void MX_SPI4_Init(void)
{

hspi4.Instance = SPI4;
hspi4.Init.Mode = SPI_MODE_MASTER;
hspi4.Init.Direction = SPI_DIRECTION_2LINES;
hspi4.Init.DataSize = SPI_DATASIZE_16BIT;
hspi4.Init.CLKPolarity = SPI_POLARITY_LOW;
hspi4.Init.CLKPhase = SPI_PHASE_1EDGE;
hspi4.Init.NSS = SPI_NSS_SOFT;
hspi4.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_32;
hspi4.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi4.Init.TIMode = SPI_TIMODE_DISABLE;
hspi4.Init.CRCCalculation = SPI_CRCCALCULATION_ENABLE;
hspi4.Init.CRCPolynomial = 50835;
if (HAL_SPI_Init(&hspi4) != HAL_OK)
{
Error_Handler();
}

}

 

I use Hal lib to send data :

HAL_SPI_Transmit_DMA(&hspi4,ptr,1);

and call this function in receive side ;

HAL_SPI_Receive_DMA(&hspi1,ptr,1);

 

data is received as  i expected 

but i have changed CRC POLYNOMIAL in master side  for test crc error in slave side .

but I havn't got any error .

 

I have checked data transmission by oscilloscope CRC is attached at the end of the data .

when i set breakpoint in DMA receive complete the "SPI Rx CRC register" was 0 !

and the CRC ERROR bit in status was 0!

i guess the problem is in slave side but i can't find the problem .

 

 

 

 I would appreciate all help.

Outcomes