Skip to content

Patch of the STM32 library to implement SPI.transfer16() as a true 16 bit transfer

Notifications You must be signed in to change notification settings

drmcnelson/STM32_SPI_with_16bit_transfers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SPI

Patch to the STM32 SPI library to implement true 16 bit transfers.

Original readme follows:

STM32 SPI library has been modified with the possibility to manage hardware CS pin linked to the SPI peripheral. We do not describe here the SPI Arduino API but the functionalities added.

User have 2 possibilities about the management of the CS pin:

  • the CS pin is managed directly by the user code before to transfer the data (like the Arduino SPI library)
  • the user uses a hardware CS pin linked to the SPI peripheral

New API functions

Alternative class constructor

  • SPIClass::SPIClass(uint8_t mosi, uint8_t miso, uint8_t sclk, uint8_t ssel)

Param SPI mosi pin

Param SPI miso pin

Param SPI sclk pin

Params (optional) SPI ssel pin. This pin must be an hardware CS pin. If you configure this pin, the chip select will be managed by the SPI peripheral.

Example

This is an example of the use of the hardware CS pin linked to the SPI peripheral:

#include <SPI.h>
//            MOSI  MISO  SCLK   SSEL
SPIClass SPI_3(PC12, PC11, PC10, PC9);

void setup() {
  SPI_3.begin(); // Enable the SPI_3 instance with default SPISsettings
  SPI_3.beginTransaction(settings); // Configure the SPI_3 instance with other settings
  SPI_3.transfer(0x52); // Transfers data to the first device
  SPI_3.end() //SPI_3 instance is disabled
}

Transfer with Tx/Rx buffer

  • void transfer(const void *tx_buf, void *rx_buf, size_t count) :Transfer several bytes. One constant buffer used to send and one to receive data.

    Param tx_buf: constant array of Tx bytes that is filled by the user before starting the SPI transfer. If NULL, default dummy 0xFF bytes will be clocked out.

    Param rx_buf: array of Rx bytes that will be filled by the slave during the SPI transfer. If NULL, the received data will be discarded.

    Param count: number of bytes to send/receive.

Change default SPI instance pins

It is also possible to change the default pins used by the SPI instance using above API:

Warning

Have to be called before begin().

  • void setMISO(uint32_t miso)
  • void setMOSI(uint32_t mosi)
  • void setSCLK(uint32_t sclk)
  • void setSSEL(uint32_t ssel)
  • void setMISO(PinName miso)
  • void setMOSI(PinName mosi)
  • void setSCLK(PinName sclk)
  • void setSSEL(PinName ssel)

Note

Using setSSEL() allows to enable hardware CS pin management linked to the SPI peripheral.

Example:
    SPI.setMISO(PC_4); // using pin name PY_n
    SPI.setMOSI(PC2); // using pin number PYn
    SPI.begin(2);
  • SPI_HandleTypeDef *getHandle(void): Could be used to mix Arduino API and STM32Cube HAL API (ex: DMA). Use at your own risk.

Extended API

  • All defaustatndard transfer() API's have a new bool argument skipReceive. It allows to skip receive data after transmitting. Value can be SPI_TRANSMITRECEIVE or SPI_TRANSMITONLY. Default SPI_TRANSMITRECEIVE.

About

Patch of the STM32 library to implement SPI.transfer16() as a true 16 bit transfer

Resources

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published