Arduino Core for STM32  1.0
SPI transaction initializers

Optimized methods for performance for data transaction. More...

Functions

uint16_t HardwareSPI_O::transfer (uint16_t data, bool lastByte=false) override
 SPI transfer is based on a simultaneous send and receive data. More...
 
uint16_t HardwareSPI_O::transfer16 (uint16_t data, bool lastByte=false) override
 SPI transfer is based on a simultaneous send and receive data. More...
 
uint32_t HardwareSPI_O::transfer32 (uint32_t data, bool lastByte=false) override
 SPI transfer is based on a simultaneous send and receive data. More...
 
bool HardwareSPI_O::write (uint16_t data, bool lastByte=false) override
 Sends data using SPI periphery. More...
 
bool HardwareSPI_O::write16 (uint16_t data, bool lastByte=false) override
 Sends data using SPI periphery. More...
 
bool HardwareSPI_O::write32 (uint32_t data, bool lastByte=false) override
 Sends data using SPI periphery. More...
 
uint16_t HardwareSPI_O::receive (bool lastByte=false) override
 Receives data from SPI periphery. More...
 
uint16_t HardwareSPI_O::receive16 (bool lastByte=false) override
 Receives data from SPI periphery. More...
 
uint32_t HardwareSPI_O::receive32 (bool lastByte=false) override
 Receives data from SPI periphery. More...
 
bool HardwareSPI_O::transferBytes (const uint8_t *out, uint8_t *in, uint32_t size, bool lastByte=false) override
 Transfers data using SPI periphery in blocking mode, it is sending and receiving data simultaneously. More...
 
bool HardwareSPI_O::writeBytes (const uint8_t *data, uint32_t size, bool lastByte=false) override
 Sends data using SPI periphery in blocking mode. More...
 
bool HardwareSPI_O::receiveBytes (uint8_t *data, uint32_t size, bool lastByte=false) override
 Receives data from SPI periphery in blocking mode. More...
 
bool HardwareSPI_O::transfer (void *buf, uint16_t count, bool lastByte=false) override
 SPI transfer is based on a simultaneous send and receive data. More...
 

Detailed Description

Optimized methods for performance for data transaction.

Three types of transaction methods

Note
In class HardwareSPI_O, methods beginTransaction() and endTransaction() have to be called before using Optimized transaction methods, else they will be disabled. There is also an exception, array optimized transaction methods can be called without calling beginTransaction() or endTransaction().
See also
Base transaction methods

Function Documentation

◆ transfer() [1/2]

uint16_t HardwareSPI_O::transfer ( uint16_t  data,
bool  lastByte = false 
)
overridevirtual

SPI transfer is based on a simultaneous send and receive data.

Parameters
data8-bit data to send. When data size (using setDataBits()) is set to 16 bits, 16-bit data are sent.
lastByteSet to true, if this will be last transfered byte before calling endTransaction(). It is important to set this parameter when CRC is enabled, because CRC calculation hardware have to be noticed, that it have to check or send CRC.
Note
beginTransaction() have to be called before using this method one or multiple time, then endTransaction has to be called to disable SPI.
When you have changed bit order to MSBFIRST, not only bits, but also bytes will be swapped.
Returns
Returns received 8-bit (or when data size is set to 16, then 16-bit) data.

Reimplemented from HardwareSPI.

◆ transfer16()

uint16_t HardwareSPI_O::transfer16 ( uint16_t  data,
bool  lastByte = false 
)
overridevirtual

SPI transfer is based on a simultaneous send and receive data.

Parameters
data16-bit data to send.
lastByteSet to true, if this will be last transfered byte before calling endTransaction(). It is important to set this parameter when CRC is enabled, because CRC calculation hardware have to be noticed, that it have to check or send CRC.
Note
beginTransaction() have to be called before using this method one or multiple time, then endTransaction has to be called to disable SPI.
When you have changed bit order to MSBFIRST, not only bits, but also bytes will be swapped.
Returns
Returns received 16-bit data.

Reimplemented from HardwareSPI.

◆ transfer32()

uint32_t HardwareSPI_O::transfer32 ( uint32_t  data,
bool  lastByte = false 
)
overridevirtual

SPI transfer is based on a simultaneous send and receive data.

Parameters
data32-bit data to send.
lastByteSet to true, if this will be last transfered byte before calling endTransaction(). It is important to set this parameter when CRC is enabled, because CRC calculation hardware have to be noticed, that it have to check or send CRC.
Note
beginTransaction() have to be called before using this method one or multiple time, then endTransaction has to be called to disable SPI.
When you have changed bit order to MSBFIRST, not only bits, but also bytes will be swapped.
Returns
Returns received 32-bit data.

Reimplemented from HardwareSPI.

◆ write()

bool HardwareSPI_O::write ( uint16_t  data,
bool  lastByte = false 
)
overridevirtual

Sends data using SPI periphery.

If any data was received, they will be discarded. This method is faster than transfer method.

Parameters
data8-bit data to send. When data size (using setDataBits()) is set to 16 bits, 16-bit data are sent.
lastByteSet to true, if this will be last transfered byte before calling endTransaction(). It is important to set this parameter when CRC is enabled, because CRC calculation hardware have to be noticed, that it have to check or send CRC.
Note
beginTransaction() have to be called before using this method one or multiple time, then endTransaction has to be called to disable SPI.
When you have changed bit order to MSBFIRST, not only bits, but also bytes will be swapped.
Returns
Returns true when data has been written.

Reimplemented from HardwareSPI.

◆ write16()

bool HardwareSPI_O::write16 ( uint16_t  data,
bool  lastByte = false 
)
overridevirtual

Sends data using SPI periphery.

If any data was received, they will be discarded. This method is faster than transfer method. data 16-bit data to send.

Parameters
lastByteSet to true, if this will be last transfered byte before calling endTransaction(). It is important to set this parameter when CRC is enabled, because CRC calculation hardware have to be noticed, that it have to check or send CRC.
Note
beginTransaction() have to be called before using this method one or multiple time, then endTransaction has to be called to disable SPI.
When you have changed bit order to MSBFIRST, not only bits, but also bytes will be swapped.
Returns
Returns true when data has been written.

Reimplemented from HardwareSPI.

◆ write32()

bool HardwareSPI_O::write32 ( uint32_t  data,
bool  lastByte = false 
)
overridevirtual

Sends data using SPI periphery.

If any data was received, they will be discarded. This method is faster than transfer method. data 32-bit data to send.

Parameters
lastByteSet to true, if this will be last transfered byte before calling endTransaction(). It is important to set this parameter when CRC is enabled, because CRC calculation hardware have to be noticed, that it have to check or send CRC.
Note
beginTransaction() have to be called before using this method one or multiple time, then endTransaction has to be called to disable SPI.
When you have changed bit order to MSBFIRST, not only bits, but also bytes will be swapped.
Returns
Returns true when data has been written.

Reimplemented from HardwareSPI.

◆ receive()

uint16_t HardwareSPI_O::receive ( bool  lastByte = false)
overridevirtual

Receives data from SPI periphery.

During receiving zeros will be sent when mode is set to Master. It is recommended to use available() method to check, if any data are available in FIFO buffer, else this method will wait until timeout or until receiving data. To check, if timeout elapsed, use lastTransactionStatus() method.

Parameters
lastByteSet to true, if this will be last transfered byte before calling endTransaction(). It is important to set this parameter when CRC is enabled, because CRC calculation hardware have to be noticed, that it have to check or send CRC.
Note
beginTransaction() have to be called before using this method one or multiple time, then endTransaction has to be called to disable SPI.
When you have changed bit order to MSBFIRST, not only bits, but also bytes will be swapped.
Returns
Returns received 8-bit (or when data size is set to 16, then 16-bit) data.

Reimplemented from HardwareSPI.

◆ receive16()

uint16_t HardwareSPI_O::receive16 ( bool  lastByte = false)
overridevirtual

Receives data from SPI periphery.

During receiving zeros will be sent when mode is set to Master. It is recommended to use available() method to check, if any data are available in FIFO buffer, else this method will wait until timeout or until receiving data. To check, if timeout elapsed, use lastTransactionStatus() method.

Parameters
lastByteSet to true, if this will be last transfered byte before calling endTransaction(). It is important to set this parameter when CRC is enabled, because CRC calculation hardware have to be noticed, that it have to check or send CRC.
Note
beginTransaction() have to be called before using this method one or multiple time, then endTransaction has to be called to disable SPI.
When you have changed bit order to MSBFIRST, not only bits, but also bytes will be swapped.
Returns
Returns received 16-bit data.

Reimplemented from HardwareSPI.

◆ receive32()

uint32_t HardwareSPI_O::receive32 ( bool  lastByte = false)
overridevirtual

Receives data from SPI periphery.

During receiving zeros will be sent when mode is set to Master. It is recommended to use available() method to check, if any data are available in FIFO buffer, else this method will wait until timeout or until receiving data. To check, if timeout elapsed, use lastTransactionStatus() method.

Parameters
lastByteSet to true, if this will be last transfered byte before calling endTransaction(). It is important to set this parameter when CRC is enabled, because CRC calculation hardware have to be noticed, that it have to check or send CRC.
Note
beginTransaction() have to be called before using this method one or multiple time, then endTransaction has to be called to disable SPI.
When you have changed bit order to MSBFIRST, not only bits, but also bytes will be swapped.
Returns
Returns received 32-bit data.

Reimplemented from HardwareSPI.

◆ transferBytes()

bool HardwareSPI_O::transferBytes ( const uint8_t *  out,
uint8_t *  in,
uint32_t  size,
bool  lastByte = false 
)
overridevirtual

Transfers data using SPI periphery in blocking mode, it is sending and receiving data simultaneously.

Parameters
outPointer to data, that have to be sent in blocking mode.
inPointer to array, where will be stored received data. It can also pointing same address as out parameter without any error.
sizeThe size of data in bytes (8-bits). Out and in parameter must have same size.
lastByteSet to true, if this is last transaction method before calling endTransaction(). It is important to set this parameter when CRC is enabled, because CRC calculation hardware have to be noticed, that it have to check or send CRC.
Note
beginTransaction() and endTransaction() don't have to be called before, HardwareSPI methods will be called instead, but if you call it before, modified code will be called.
When you have changed bit order to MSBFIRST, only bits will be swapped. Bytes will be sent from array begin also in MSBFIST mode.
When data size (using setDataBits()) is set to 16 and count value is odd, the real count will be then count+1 and the last byte will contain random value.
Returns
Returns true when data has been transfered.

Reimplemented from HardwareSPI.

◆ writeBytes()

bool HardwareSPI_O::writeBytes ( const uint8_t *  data,
uint32_t  size,
bool  lastByte = false 
)
overridevirtual

Sends data using SPI periphery in blocking mode.

If any data was received, they will be discarded. This method is faster than transfer method.

Parameters
dataPointer to data, that have to be sent in blocking mode.
sizeThe size of data in bytes (8-bits).
lastByteSet to true, if this is last transaction method before calling endTransaction(). It is important to set this parameter when CRC is enabled, because CRC calculation hardware have to be noticed, that it have to check or send CRC.
Note
beginTransaction() and endTransaction() don't have to be called before, HardwareSPI methods will be called instead, but if you call it before, modified code will be called.
When you have changed bit order to MSBFIRST, only bits will be swapped. Bytes will be sent from array begin also in MSBFIST mode.
When data size (using setDataBits()) is set to 16 and count value is odd, the real count will be then count+1 and the last byte will contain random value.
Returns
Returns true when data has been written.

Reimplemented from HardwareSPI.

◆ receiveBytes()

bool HardwareSPI_O::receiveBytes ( uint8_t *  data,
uint32_t  size,
bool  lastByte = false 
)
overridevirtual

Receives data from SPI periphery in blocking mode.

During receiving zeros will be sent when mode is set to Master. It is recommended to use available() method to check, if any data are available in FIFO buffer, else this method will wait until timeout or until receiving data. To check, if timeout elapsed, use lastTransactionStatus() method.

Parameters
dataPointer to array, where will be stored received data.
sizeThe size of data in bytes (8-bits).
lastByteSet to true, if this is last transaction method before calling endTransaction(). It is important to set this parameter when CRC is enabled, because CRC calculation hardware have to be noticed, that it have to check or send CRC.
Note
beginTransaction() and endTransaction() don't have to be called before, HardwareSPI methods will be called instead, but if you call it before, modified code will be called.
When you have changed bit order to MSBFIRST, only bits will be swapped. Bytes will be sent from array begin also in MSBFIST mode.
Returns
Returns true when data has been received.

Reimplemented from HardwareSPI.

◆ transfer() [2/2]

bool HardwareSPI_O::transfer ( void *  buf,
uint16_t  count,
bool  lastByte = false 
)
overridevirtual

SPI transfer is based on a simultaneous send and receive data.

Data are transfered in blocking mode.

Parameters
bufPointer to data, that have to be sent in blocking mode.
countThe size of data in bytes (8-bits). If you are sending whole array uint32_t[5], the count parameter have to be set to 4*5 = 20.
lastByteSet to true, if this is last transaction method before calling endTransaction(). It is important to set this parameter when CRC is enabled, because CRC calculation hardware have to be noticed, that it have to check or send CRC.
Note
beginTransaction() and endTransaction() don't have to be called before, HardwareSPI methods will be called instead, but if you call it before, modified code will be called.
When you have changed bit order to MSBFIRST, only bits will be swapped. Bytes will be sent from array begin also in MSBFIST mode.
When data size (using setDataBits()) is set to 16 and count value is odd, the real count will be then count+1 and the last byte will contain random value.
Returns
Returns received 32-bit data.

Reimplemented from HardwareSPI.