2018-10-30 11:41 AM
Hello,
I would like to send a uint32_t size array via HAL_SPI_Transmit / HAL_SPI_Transmit_DMA but both are limited to 16 bit size.
I have tried casting as
HAL_SPI_Transmit(&hspi1,Array,(uint16_t)65537),10000)
but this doesn't work.
I have also tried editing the SPI driver and changing TxXferSize and TxXferCount to uint32_t but this only seems to get rid of the compiler warning and still overflows somewhere, i.e only 1 byte from the array is sent.
Please could anyone advise what else I need to change?
Thanks
2018-11-03 07:13 AM
Someone?
2018-11-03 07:40 AM
You'd need to break the transfer in to multiple pieces, advancing the Array pointer to account for the data already committed.
I think HAL_SPI_Transmit() will block until complete. The STM32 is capable of interrupting on the DMA TC event.
Is SPI in 8-bit or 16-bit mode, the size is in units not bytes
If 16-bit SPI
HAL_SPI_Transmit(&hspi1,(uint16_t*)&Array[0], 38400,10000);
HAL_SPI_Transmit(&hspi1,(uint16_t*)&Array[38400], 38400 ,10000);
one could do it as an iterative loop
If 8-bit SPI, from a 16-bit array
int i;
for(i=0; i<4; i++)
HAL_SPI_Transmit(&hspi1,(uint16_t*)&Array[i * (38400/2)], 38400,10000); // 38400 bytes, 19200 words
2018-11-03 03:43 PM
If DMA transfers 16-bit halfwords and SPI is set to 16-bit too, then
uin16_t Array[76800]
HAL_SPI_Transmit(&hspi1,(uint16_t)Array, 65535 ,10000);
HAL_SPI_Transmit(&hspi1,(uint16_t)&Array[65535], 76800-65535 ,10000);
JW
2018-11-08 03:23 AM
If 16-bit SPI
HAL_SPI_Transmit(&hspi1,(uint16_t*)&Array[0], 38400,10000);
HAL_SPI_Transmit(&hspi1,(uint16_t*)&Array[38400], 38400 ,10000);
This did the trick, many thanks. I didn't realise the array position could act as an offset, I thought those lines would just send element [0] and [38400], 38400 times.
Thanks