2023-05-23 03:32 PM - edited 2023-11-20 04:45 AM
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.
Solved! Go to Solution.
2023-05-24 11:57 AM
This was a hardware issue.
2023-05-24 03:34 AM
Are you sure you want SPI_CR1.BIDIMODE be set?
JW
2023-05-24 05:38 AM
I tried it again with that cleared, updated the image and still the same results.
2023-05-24 06:33 AM
OK so set SCK to GPIO Output and try to wiggle it "manually" and observe.
JW
2023-05-24 06:57 AM
I can't wiggle the old CLK and SDI. I can wiggle SDO.
2023-05-24 08:34 AM
What external device is connected to the SPI signals? Is whatever used to be the master still connected? If so, it is probably driving those signals.
2023-05-24 11:57 AM
This was a hardware issue.