0
\$\begingroup\$

I recently purchased this STM32 Discovery Board in an attempt to start learning STM32 microcontrollers. Things have been going smoothly due to the CubeMX + HAL libraries. However, I'm absolutely struggling to get SPI working with this MAX31855 chip which I've previously had success with on different microcontrollers.

As a troubleshooting method, I've completely removed the MAX31855 from the equation and am trying to confirm that I'm getting correct constant data on the MISO pin. I've jumpered the MISO pin to GND and am trying to confirm I'm reading all zeros.

enter image description here

enter image description here

I've configured the SPI settings using CubeMX.

enter image description here

CubeMX then generates the following initialization code. Note that I've confirmed that the error handlers doesn't get called, so I assume it's not failing during initialization.

static void MX_SPI1_Init(void)
{

  /* USER CODE BEGIN SPI1_Init 0 */

  /* USER CODE END SPI1_Init 0 */

  /* USER CODE BEGIN SPI1_Init 1 */

  /* USER CODE END SPI1_Init 1 */
  /* SPI1 parameter configuration*/
  hspi1.Instance = SPI1;
  hspi1.Init.Mode = SPI_MODE_MASTER;
  hspi1.Init.Direction = SPI_DIRECTION_2LINES;
  hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
  hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
  hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
  hspi1.Init.NSS = SPI_NSS_SOFT;
  hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16;
  hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
  hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
  hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
  hspi1.Init.CRCPolynomial = 7;
  hspi1.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
  hspi1.Init.NSSPMode = SPI_NSS_PULSE_DISABLE;
  if (HAL_SPI_Init(&hspi1) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN SPI1_Init 2 */

  /* USER CODE END SPI1_Init 2 */

}

I'm now ready to confirm that I'm reading 'all zeros' in on the MISO pin.

In the main.c file, I've added a simple call to the HAL_SPI_TransmitReceive function. I'm really only interested in the receive data. However, when I run this, you can see from the watch window that the RXData gets read as all 1's.

enter image description here

Further, the status value returns "HAL_OK" which makes me assume no obvious error has occurred. I initially thought that the polarity was reversed, so I tied PA6 to VDD but still received all 1's. To me this indicates that the MISO pin is not reading inputs.

So I'm curious, what exactly is going on? This is an extremely barebone test and it is resulting in weird behavior. Is it possible that that the MISO pin has some other configuration getting applied to it by default? However, there's nothing in the autogenerated code that would indicate PA6 is getting configured elsewehere.

\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

The MCU pin PA6 is by default used for capacitive sensor so it is not connected to the pin header. Solder bridge SB29 must be shorted to connect it.

Same thing for SB30 if you want to have PA7 too.

These are explained in the board user manual and can be seen from the schematics too that there are solder bridges for configuration.

\$\endgroup\$
3
  • \$\begingroup\$ Well that would explain a lot then, thank you. A bonus question if you have a minute: I've also tried and failed to execute on SPI2 (imgur.com/a/zUJRcCU). Do you know if this MISO pin PC2 has any odd configurations on it? It looks like it might be tied to a gyroscope interrupt? \$\endgroup\$
    – Izzo
    Mar 13 at 14:05
  • \$\begingroup\$ Alright, lesson learned. I should not have purchased the Discovery Board since most of the pins are already connected to hardware. I just used the alternative SPI2 pins and everything is working now. \$\endgroup\$
    – Izzo
    Mar 13 at 14:57
  • 1
    \$\begingroup\$ @Izzo in a future buy Nucleo boards instead \$\endgroup\$ Mar 13 at 17:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.