2024-02-17 01:25 AM - edited 2024-02-17 01:28 AM
Hi, I am wondering if anyone has any experience with HAL SPI as when I try in 16-bit mode to make a single packet of data manually and use (sizeof xxx) it sends 2x data packets to the oscilloscope and when I specify the packet size as "1" I get the correct waveform? I show it below the code and attach the scope readings:-
uint16_t packet;
packet = 0b0111 1111 1000 0000; // send 8 MSB bits in 16 bit mode
HAL_SPI_Transmit (&hspi1, &packet, sizeof(packet), HAL_MAX_DELAY); // sends 2 packets?
HAL_SPI_Transmit (&hspi1, &packet, 1, HAL_MAX_DELAY); // sends correct 1 packet.
2024-02-17 02:58 AM - edited 2024-02-17 02:58 AM
sizeof(xxx) returns number of bytes xxx occupies, i.e. in case of uint16_t it's 2.
That's why
> it sends 2x data packets
JW
2024-02-17 04:40 AM
Documentation should be clearer:
Always give units !
Note also that units are needed for the Timeout parameter.
2024-02-18 01:24 AM - edited 2024-02-18 01:25 AM
Hello,
@Andrew Neil , thank you for your feedback and for helping us improve the ST documentations!
Your request has been escalated via internal ticket number 173729.
(PS: internal ticket number 173729 is only for reference, not available outside of ST).
2024-02-18 01:39 AM
Yes, but what are units in this particular case?
Pieces. It even has an abbreviation (pcs). Not an SI unit, though.
Would you be satisfied with this "unit"?
JW
2024-02-18 06:02 AM
@waclawek.jan wrote:Yes, but what are units in this particular case?
They are multiples of the "data size" set by SPI_InitTypeDef::DataSize
That also needs to be better documented:
Is that bits or bytes?
(the values of SPI_Data_Size do suggest that it's bits)
2024-02-21 12:01 PM
Hi, thanks for the information it seems this "sizeof" is an internal HAL based integer which tells the size of a data packet or array so the correct amount of packets can be sent and is 2^16 (65,535).
This means potentially you can have a pointer or array that can be up too 65,535 in length.