2017-07-25 03:25 AM
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.
2017-07-25 05:19 AM
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.
2017-07-31 10:33 PM
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.
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.