SPI¶
4G LTE Module SPI Port Mapping¶
SPI Port 0¶
SPI Pin |
EC600U |
EC200U* |
N58 |
N716 |
L610 |
|---|---|---|---|---|---|
MISO |
Pin 1 |
Pin 40 |
Pin 84 |
Pin 6 |
Pin 40 |
MOSI |
Pin 4 |
Pin 37 |
Pin 87 |
Pin 7 |
Pin 37 |
CLK |
Pin 3 |
Pin 38 |
Pin 86 |
Pin 5 |
Pin 38 |
CS |
Pin 2 |
Pin 39 |
Pin 85 |
Pin 4 |
Pin 39 |
Note
SPI Port 0 is not available on EC200U with integrated GNSS
SPI Port 1¶
SPI Pin |
EC600U |
EC200U |
N58 |
N716 |
L610 |
|---|---|---|---|---|---|
MISO |
Pin 60 |
Pin 25 |
Pin 78 |
Pin 102 |
Pin 25 |
MOSI |
Pin 59 |
Pin 24 |
Pin 80 |
Pin 101 |
Pin 24 |
CLK |
Pin 61 |
Pin 27 |
Pin 50 |
Pin 99 |
Pin 27 |
CS |
Pin 58 |
Pin 26 |
Pin 90 |
Pin 100 |
Pin 26 |
GSM/NB-IoT Module SPI Port Mapping¶
GSM (MT2503, MT6261) and NB-IoT (MT2625) chipset supported modules expose only one I2C port. Following is the pin mapping for SPI Port 0.
SPI Pin |
MC20U Pin
|
M56 Pin |
MC60 Pin
|
M66 Pin |
BC20 Pin |
SIM868 Pin |
|---|---|---|---|---|---|---|
MISO |
Pin 61 |
Pin 15 |
Pin 61 |
Pin 31 |
Pin 61 |
Pin 41 |
MOSI |
Pin 60 |
Pin 16 |
Pin 60 |
Pin 33 |
Pin 60 |
Pin 42 |
CLK |
Pin 62 |
Pin 18 |
Pin 62 |
Pin 32 |
Pin 62 |
Pin 7 |
CS |
Pin 59 |
Pin 4 |
Pin 59 |
Pin 30 |
Pin 59 |
Pin 5 |
API Reference¶
Header File¶
Functions¶
-
int
spi_hw_init(int port, int hardware_cs, int clock, int mode, int cs_pol)¶ Initialize SPI Hardware and setup pinmux
- Return
0 on success, negative on error
- Parameters
port: [in] SPI Port Number (spiport_e)hardware_cs: [in] Set it TRUE, if application hardware chip select is used and hardware controls chip select status, FALSE otherwiseclock: [in] SPI Clock speed in Hzmode: [in] SPI Mode (spi_mode_e)cs_pol: [in] Chip select Polarity (spi_cspol_e)
-
int
spi_hw_setclock(int port, unsigned long clock_hz)¶ Set/Change SPI clock speed. Default speed is 10MHz
- Return
0 on success, negative value on error
- Parameters
port: [in] SPI Port Number (spiport_e)clock_hz: [in] Clock speed in Hz
-
int
spi_hw_setmode(int port, int mode)¶ Configure SPI clock mode
- Return
0 on success, negative value on error
- Parameters
port: [in] SPI Port Number (spiport_e)mode: [in] SPI mode, see spi_mode_e
-
int
spi_hw_setbitorder(int port, int bit_order)¶ Configure SPI bit shift order
- Return
0 on success, negative value on error
- Parameters
port: [in] SPI Port Number (spiport_e)bit_order: [in] SPI bit shit order, see spi_bitorder_e
-
int
spi_hw_setcsmode(int port, int cs_pol)¶ Configure chip-select line. Only needed when hardware_cs is used
- Return
0 on success, negative value on error
- Parameters
port: [in] SPI Port Number (spiport_e)cs_pol: [in] Chip select polarity, see spi_cspol_e
-
int
spi_hw_transfer(int port, const unsigned char *wrbuf, unsigned char *rdbuf, int length)¶ Perform SPI transaction
- Return
Length of data read/write on success, negative on error
- Parameters
port: [in] SPI Port Number (spiport_e)wrbuf: [in] Pointer to data buffer to write, can be NULL if only read operation to be performedrdbuf: [out] Pointer to buffer to store data, can be NULL if only write operation to be performedlength: [in] Length of data to read/write
-
int
spi_hw_free(int port)¶ Release SPI hardware
- Return
0 on success, negative on error
- Parameters
port: [in] SPI Port Number (spiport_e)
-
int
spi_hw_cscontrol(int port, int level)¶ Control SPI HW CS line.
This function can be used to control chip select line of SPI controller (which is not mapped as GPIO) when HW SPI is used.
- Note
This function is only available on platforms with RDA8910 SoC.
- Return
0 on success, negative on error
- Parameters
port: [in] SPI Port Number (spiport_e)level: [in] chip select level (0 - low, 1 - high)
Enumerations¶
-
enum
spi_mode_e¶ SPI Modes to configure clock polarity and clock phase.
For more information see https://en.wikipedia.org/wiki/Serial_Peripheral_Interface#Clock_polarity_and_phase
Values:
-
enumerator
SPI_MODE0¶ Mode 0 (default): CPOL = 0, CPHA = 0
-
enumerator
SPI_MODE1¶ Mode 1: CPOL = 0, CPHA = 1
-
enumerator
SPI_MODE2¶ Mode 2: CPOL = 1, CPHA = 0
-
enumerator
SPI_MODE3¶ Mode 3: CPOL = 1, CPHA = 1
-
enumerator
