2021-06-16 07:33 AM
Hello! I need to send/receive a 16 bits data to an external ADC, but I realized that SPI HAL functions just support 8 bits buffers. How can I send more than 8 bits? Even DMA function all work with 8 bits. In CubeMX I set the word length as 16.
Solved! Go to Solution.
2021-06-16 02:29 PM
All of the HAL_SPI_* functions can transfer multiple bytes at once. Perhaps you are not using them correctly. Should be something like this if word size is configured to 8 bits:
uint8_t data[2] = {0x00, 0x01};
HAL_SPI_Transmit(&hspi, data, 2, HAL_MAX_DELAY);
2021-06-16 07:37 AM
Which STM32?
A pair of 8-bit bytes have 16 clocks, does this somehow differ from sending one 16-bit word?
The SPI DR typically is sensitive to the width of the write operation, some models may also use a FIFO
2021-06-16 08:19 AM
stm32f205
2021-06-16 08:21 AM
do you mean sendig a 2 bytes array ?
2021-06-16 02:29 PM
All of the HAL_SPI_* functions can transfer multiple bytes at once. Perhaps you are not using them correctly. Should be something like this if word size is configured to 8 bits:
uint8_t data[2] = {0x00, 0x01};
HAL_SPI_Transmit(&hspi, data, 2, HAL_MAX_DELAY);
2021-06-17 12:29 AM
@TDK does SPI_Transmit send first data[0] as LSB?
what about the reception, will data[0] also be LSB?
2021-06-17 06:25 AM
> does SPI_Transmit send first data[0] as LSB?
LSB refers to order of bits, not bytes.
data[0] will be sent/received as the first byte.