cancel
Showing results for 
Search instead for 
Did you mean: 

SPI Data Size means?

Sandeep Dhokne
Associate II
Posted on July 25, 2017 at 12:25

Hi,

HAL_SPI_TransmitReceive(SPI_HandleTypeDef *hspi, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size, uint32_t Timeout)

In this API Size is in Byte or in Bits?

Thank you.

2 REPLIES 2
Tomas DRESLER
Senior II
Posted on July 25, 2017 at 14:19

No. of frames to transfer, depending on your initial SPI configuration. The frame size, if 4-8 bits, is transferred as byte, 9-16 bits as half-word, and 17+ bits as word.

Posted on August 01, 2017 at 07:33

Hi Sandeep,

According to the HAL manual, in this case for STM32F4 family the size refers to the amount of data to be sent and received, for some STM32 microcontrollers families the data can be only of 8bits or 16bits, so in this case as the buffer pointer is to a uint8_t it refers to the amount of bytes to be sent and received, if data is configured in 16bits the spi peripheral fix the frames to be sent 2 by 2 bytes each time.

0690X00000607mzQAA.png

So for example, if you have the uint8_t arrays :

uint8_t myarray[5] = {'a','b','c','d','e'};

uint8_t myarray2[5] = {0,0,0,0,0};

and data configured in 8bits, y

ou can use the function:

HAL_SPI_TransmitReceive(&hspi, myarray, myarray2

, 5

,10);

So, you will send the 5 chars of myarray and also receive 5 chars that have been stored in myarray2, but you can also send just some chars:

HAL_SPI_TransmitReceive(&hspi, myarray,

myarray2

, 2

,10);

So, you will send the 2 chars of myarray and also receive 2 chars that have been stored in myarray2.