cancel
Showing results for 
Search instead for 
Did you mean: 

SPI Send (sizeof) too big

PLee.3
Associate II

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.

 

6 REPLIES 6

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

Documentation should be clearer:

AndrewNeil_0-1708173492403.png

Always give units !

Note also that units are needed for the Timeout parameter.

@Imen.D 

Imen.D
ST Employee

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).

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen

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


@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:

 AndrewNeil_0-1708264841983.png 

Is that bits or bytes?

(the values of SPI_Data_Size do suggest that it's bits)

PLee.3
Associate II

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.