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.
I've configured the SPI settings using CubeMX.
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.
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.