2021-08-19 03:59 PM
Hardware/Firmware Setup
In MX_SPI1_Init() in main.c
for 8-bit mode use the default of:
hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
for 16-bit mode use:
hspi1.Init.DataSize = SPI_DATASIZE_16BIT;
The issue is
Notes
Seems like I'm just missing some obscure configuration in order to make 16-bit mode to work. Perhaps someone has already resolved this issue ?
2021-08-23 12:47 AM
You're changing DMA transfer size from byte to half-word as well, correct?
If so, and if you wanted to debug further, you could put a breakpoint in the DMA stream interrupt and see why it never gets around to calling HAL_SPI_TxRxCpltCallback. You could also verify that the DMA stream NDTR register reaches 0. Sounds like a HAL issue based on your description, but hard to know.
2021-08-23 04:02 PM
I'm not dynamically switching from 8-bit to 16-bit (half-word). Just configuring the app to run either 8-bit or 16-bit transfers.
I will try your suggestion to set a breakpoint in the DMA Stream interrupt and verify that the NDTR register reaches 0.
2021-08-24 05:01 PM
Thanks for the hint. Changed the callback to the 'half word' callback and now I'm getting a successful 16-bit transfer with TRANSFER_COMPLETE. Now I just need to figure out why the second byte of the 16-bit received word is 0x00 instead of the desired value (the first byte is correct) ... even though the desired both byte values are correctly captured and decoded on the Logic Analyzer/Decoder.
I am manually driving the CSn active low and then high after the SPI transaction.
Additionally, the second time around that I try to do the same SPI transaction I get a HAL_BUSY from the HAL_SPI_TransmitReceive_DMA(). My first problem in the chain is not getting the second byte of the 16-bit received word.
Following is my SPI Configuration:
// SPI1 parameter configuration
hspi1.Instance = SPI1;
hspi1.Init.Mode = SPI_MODE_MASTER;
hspi1.Init.Direction = SPI_DIRECTION_2LINES;
hspi1.Init.DataSize = SPI_DATASIZE_16BIT;
hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
hspi1.Init.CLKPhase = SPI_PHASE_2EDGE;
hspi1.Init.NSS = SPI_NSS_SOFT;
hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_32;
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;