Currently we make use of three SPI busses on a STM32F405. SPI1 is a slave and SPI 2/3 are masters. I switch SPI1 to master mode and it just doesn't work. I suspect the APB2 bus but I think I have it set correctly.
Here's my code:
SPI_HandleTypeDef spi_handle =
{
.Instance = DEF_SPI_INS_SPI1,
.Init =
{
.Direction = SPI_DIRECTION_2LINES,
.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2,
.CLKPhase = SPI_PHASE_2EDGE,
.CLKPolarity = SPI_POLARITY_HIGH,
.CRCCalculation = SPI_CRCCALCULATION_DISABLE,
.CRCPolynomial = 0U, // unused
.DataSize = SPI_DATASIZE_8BIT,
.FirstBit = SPI_FIRSTBIT_MSB,
.NSS = SPI_NSS_SOFT,
.TIMode = SPI_TIMODE_DISABLE,
.Mode = SPI_MODE_MASTER
}
};
HAL_StatusTypeDef return_code;
return_code = HAL_SPI_Init(&spi_handle);
uint8_t data[] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
uint8_t rx_data[16];
HAL_SPI_Abort(&spi_handle);
__HAL_SPI_ENABLE(&spi_handle);
//return_code = HAL_SPI_Transmit(&spi_handle, data, 8, 5);
return_code = HAL_SPI_TransmitReceive(&spi_handle, data, rx_data, 8, 100);
while (HAL_SPI_GetState(&spi_handle) != HAL_SPI_STATE_READY);return_code from HAL_SPI_Init() == HAL_OK
return code from HAL_SPI_TransmitReceive() == HAL_OK
I get past the while{} loop.
SPI register settings:
PIOA settings (pins 5 = SCLK, 6 = MOSI, 7 = MISO):



RCC register settings:

I've played around with the prescaler CLK phase and polarity. One note, CLK never idles HIGH with CPOL = SPI_POLARITY_HIGH.
What am I missing?
This is all I get when I am in master mode:
Also note, I am not wiggling a CS right now - just trying to see a CLK and some data.
When I build it in slave mode and send data to the chip I see nice wiggles in all the right places and the micro reads the data correctly and sends back data to the remote SPI master. When I am doing this mcu SPI master testing, I have the remote master device disconnected and just have the logic analyzer connected.