cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_SPI_Transmit uint16_t size limit

SSmit.0
Associate II

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

13 REPLIES 13
SSmit.0
Associate II

Someone?

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

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

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

SSmit.0
Associate II
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