2016-03-09 05:21 AM
Hi,
I am examiningHAL_SPI_Receive()
. At some point it callsreturn
HAL_SPI_TransmitReceive(hspi, pData, pData, Size, Timeout);
where
pData
is the pointer to the rx buffer andSize
is its size passed toHAL_SPI_Receive()
. So,pData
is used as tx buffer and rx buffer inHAL_SPI_TransmitReceive()
. So, do I have to be sure the rx buffer is empty before the reception?2016-03-11 06:10 AM
So, what's happening here is:
1) Data register is loaded with first byte from pData.2) Data register copied into transmit shift.3) Bits are clocked, with Rx shifted in.4) Rx shift copied to data register.5) First byte of pData is is set to the value in the data register.That means that each byte from pData is sent, then replaced by the received byte.You don't need to ''clear'' anything for simplex communication. If you want to send all 0's, you probably want to set the buffer beforehand.2016-03-11 07:28 AM
Thank you for the reply. I changed the topic because I noticed it was wrong (I am asking an explanation for HAL_Receive() actually).
In my case I think I have to clear the rxbuffer in advance because the device I am communicating with supports full-duplex.Regards.2016-03-11 10:39 AM
Yes, if the device you are connecting to expects 0x00 or 0xFF bytes, then you'll have reset the buffer each time for correct MOSI behaviour. The library assumes that a receive sends ''don't care'' bytes or is simplex and irrelevant. You could have a constant buffer of 0x00 or 0xFF bytes and just use the TransmitReceive instead of Receive, so it doesn't have to be ''reset'', at the cost of some memory. But, hey, everything is a trade-off, right?
2016-03-15 03:07 AM
;) Yes everything is a tradeoff. However, I would have expected that ST had mentioned this in some user/programmer manual.
Regards.