cancel
Showing results for 
Search instead for 
Did you mean: 

SPI2 Problem STM32F303CC

PP1
Associate

Hello everbody,

Im using a STM32F303 and want to communicate with a MAX31855.

Im using the STM in full duplex master mode, under 1MBit/s data rate and standard settings.

CS ist working fine, SCK is working fine (want to read 4 times 8 bit, 32 pulses), but the connection between MISO at the STM and Data Out (DO) from MAX stays low with 32 little peaks in phase with the clock frequency (see picture: verbundene Leitung).

If I disconnect the STM from the MAX31855, I can see the right data on the Oscilloscope (see picture: offene Leitung). No shorts between the pins on the STM, no shorts to vcc or ground.

I have no idea what is going wrong. All SPI Settings are generated with the CUBE IDE.

CODE:

Generated spi.c

void MX_SPI2_Init(void)
{
 
  hspi2.Instance = SPI2;
  hspi2.Init.Mode = SPI_MODE_MASTER;
  hspi2.Init.Direction = SPI_DIRECTION_2LINES;
  hspi2.Init.DataSize = SPI_DATASIZE_8BIT;
  hspi2.Init.CLKPolarity = SPI_POLARITY_LOW;
  hspi2.Init.CLKPhase = SPI_PHASE_1EDGE;
  hspi2.Init.NSS = SPI_NSS_SOFT;
  hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_128;
  hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;
  hspi2.Init.TIMode = SPI_TIMODE_DISABLE;
  hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
  hspi2.Init.CRCPolynomial = 7;
  hspi2.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
  hspi2.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
  if (HAL_SPI_Init(&hspi2) != HAL_OK)
  {
    Error_Handler();
  }
 
}
 
void HAL_SPI_MspInit(SPI_HandleTypeDef* spiHandle)
{
 
  GPIO_InitTypeDef GPIO_InitStruct = {0};
  if(spiHandle->Instance==SPI2)
  {
  /* USER CODE BEGIN SPI2_MspInit 0 */
 
  /* USER CODE END SPI2_MspInit 0 */
    /* SPI2 clock enable */
    __HAL_RCC_SPI2_CLK_ENABLE();
 
    __HAL_RCC_GPIOB_CLK_ENABLE();
    /**SPI2 GPIO Configuration
    PB13     ------> SPI2_SCK
    PB14     ------> SPI2_MISO
    PB15     ------> SPI2_MOSI
    */
    GPIO_InitStruct.Pin = GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
    GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
 
    /* SPI2 interrupt Init */
    HAL_NVIC_SetPriority(SPI2_IRQn, 0, 0);
    HAL_NVIC_EnableIRQ(SPI2_IRQn);
  /* USER CODE BEGIN SPI2_MspInit 1 */
 
  /* USER CODE END SPI2_MspInit 1 */
  }
}

main.c

    HAL_Delay(50);
    uint8_t buffer_max[4];
    HAL_GPIO_WritePin(SPI2_CS_GPIO_Port,SPI2_CS_Pin, GPIO_PIN_RESET);       
    HAL_SPI_Receive(&hspi2,buffer_max,4,100);              
    HAL_GPIO_WritePin(SPI2_CS_GPIO_Port,SPI2_CS_Pin, GPIO_PIN_SET);          
    HAL_Delay(50);

2 REPLIES 2
TDK
Guru

I don't see a problem. What are you expecting instead? MISO is an input to the STM32 if the SPI is in master mode. If it's not being driven externally (i.e. if the MAX chip isn't there), it's subject to noise and crosstalk. Spikes on clock transitions are how this typically shows up.

If you feel a post has answered your question, please click "Accept as Solution".
AScha.3
Chief III

no, if i understand it : open line show signal...so exchange miso/mosi , you connect now output to output ! (is almost ..Kurzschluss ! )

If you feel a post has answered your question, please click "Accept as Solution".