cancel
Showing results for 
Search instead for 
Did you mean: 

My SPI analyzer is different from what I send.

NSemrHomeInit
Senior

Dear ST Hello,

I am coming back to you because the my spi frame I am sending is not the same I am watching on the oscilloscope,

My spi configuration is:

  /* USER CODE BEGIN SPI3_Init 0 */
 
  /* USER CODE END SPI3_Init 0 */
 
  /* USER CODE BEGIN SPI3_Init 1 */
 
  /* USER CODE END SPI3_Init 1 */
  /* SPI3 parameter configuration*/
  hspi3.Instance = SPI3;
  hspi3.Init.Mode = SPI_MODE_MASTER;
  hspi3.Init.Direction = SPI_DIRECTION_2LINES;
  hspi3.Init.DataSize = SPI_DATASIZE_8BIT;
  hspi3.Init.CLKPolarity = SPI_POLARITY_LOW;
  hspi3.Init.CLKPhase = SPI_PHASE_1EDGE;
  hspi3.Init.NSS = SPI_NSS_SOFT;
  hspi3.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_32;
  hspi3.Init.FirstBit = SPI_FIRSTBIT_MSB;
  hspi3.Init.TIMode = SPI_TIMODE_DISABLE;
  hspi3.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
  hspi3.Init.CRCPolynomial = 10;
  if (HAL_SPI_Init(&hspi3) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN SPI3_Init 2 */

I am sending this trame of CAFE :p

/* Buffer used for transmission */
uint8_t aTxBuffer[] = {	0xCA,0xFE,0xCA,0xFE,0xCA,0xFE,0xCA,0xFE,
						0xCA,0xFE,0xCA,0xFE,0xCA,0xFE,0xCA,0xFE};

In my analyzer I receive this:

0693W000004KDFjQAO.pngThis is the code for sending and receiving,

    HAL_GPIO_WritePin(SPI3_CS_GPIO_Port, SPI3_CS_Pin, GPIO_PIN_RESET);
	status = HAL_SPI_TransmitReceive(&hspi3, (uint8_t*)aTxBuffer, (uint8_t *)aRxBuffer, 16, 5000);
	HAL_GPIO_WritePin(SPI3_CS_GPIO_Port, SPI3_CS_Pin, GPIO_PIN_SET);

Could you please tell me we why I read 95 FD *16 instead of CA FA *16,

Thank you in advance,

S.Tarik,

1 ACCEPTED SOLUTION

Accepted Solutions

I don't know what the Cube configurations mean, but from the picture it's clear that you have set CPOL=0 and CPHA=0, i.e. SPI Mode 0.

Similarly, I have no idea what the settings on your analyzer mean - you should consult the analyzer's manual - but from what it indicates it appears that it samples on the second, downgoing edge, i.e. CPOL=0 but CPHA=1.

JW

View solution in original post

5 REPLIES 5

Your analyzer is probably set to different SPI mode (CPOL, CPHA) than the SPI in STM32.

JW

If you take a look to scopy picture, you could see clock polarity LOW, and clock phase = 1,

in the SPI configuration:

  hspi3.Init.CLKPolarity = SPI_POLARITY_LOW;
  hspi3.Init.CLKPhase = SPI_PHASE_1EDGE;

Tarik

I don't know what the Cube configurations mean, but from the picture it's clear that you have set CPOL=0 and CPHA=0, i.e. SPI Mode 0.

Similarly, I have no idea what the settings on your analyzer mean - you should consult the analyzer's manual - but from what it indicates it appears that it samples on the second, downgoing edge, i.e. CPOL=0 but CPHA=1.

JW

0693W000004KFHrQAO.pngYour absolutely right,

I don't know what is the problem with CubeMx,

Any idea about this issue?

Why would there be any problem?

It's just question of definition. Instead of standard CPOL/CPHA notation, Cube authors decided for:

/** @defgroup SPI_Clock_Phase SPI Clock Phase
  * @{
  */
#define SPI_PHASE_1EDGE                 0x00000000U
#define SPI_PHASE_2EDGE                 SPI_CR1_CPHA

If you use Cube, you have to learn both Cube's definitions and their meaning in RM.

JW