Software SPI Library
The mikroBasic PRO for FT90x provides routines for implementing Software SPI communication. These routines are hardware independent and can be used with any MCU. The Software SPI Library provides easy communication with other devices via SPI: A/D converters, D/A converters, MAX7219, LTC1290, etc.
- SPI to Master mode
- Clock value = 20 kHz.
- Data sampled at the middle of interval.
- Clock idle state low.
- Data sampled at the middle of interval.
- Data transmitted at low to high edge.
The library configures SPI to the master mode, clock = 20kHz, data sampled at the middle of interval, clock idle state low and data transmitted at low to high edge.

External dependencies of Software SPI Library
The following variables must be defined in all projects using Software SPI Library: | Description : | Example : |
---|---|---|
dim SoftSpi_SDI as sbit sfr external |
Data In line. | dim SoftSpi_SDI as sbit at GPIO_PIN30_Bit |
dim SoftSpi_SDO as sbit sfr external |
Data Out line. | dim SoftSpi_SDO as sbit at GPIO_PIN29_bit |
dim SoftSpi_CLK as sbit sfr external |
Clock line. | dim SoftSpi_CLK as sbit at GPIO_PIN27_bit |
Library Routines
Soft_SPI_Init
Prototype |
sub procedure Soft_SPI_Init() |
---|---|
Description |
Routine initializes the software SPI module. |
Parameters |
None. |
Returns |
Nothing. |
Requires |
External dependencies of the library from the top of the page must be defined before using this function. |
Example |
' Software SPI module connections dim SoftSpi_CLK as sbit at GPIO_PIN27_bit dim SoftSpi_SDI as sbit at GPIO_PIN30_Bit dim SoftSpi_SDO as sbit at GPIO_PIN29_bit ' End Software SPI module connections ... Soft_SPI_Init() ' Initialize Soft_SPI |
Notes |
None. |
Soft_SPI_Read
Prototype |
sub function Soft_SPI_Read(dim data_ as byte) as byte |
---|---|
Description |
This routine performs 3 operations simultaneously. It provides clock for the Software SPI bus, reads a byte and sends a byte. |
Parameters |
|
Returns |
Byte received via the SPI bus. |
Requires |
Soft SPI must be initialized before using this function. See Soft_SPI_Init routine. |
Example |
dim data_read, data_send as byte ... ' Read a byte and assign it to data_read variable ' (data_send byte will be sent via SPI during the Read operation) data_read = Soft_SPI_Read(data_send) |
Notes |
None. |
Soft_SPI_Write
Prototype |
sub procedure Soft_SPI_Write(dim data_ as byte) |
---|---|
Description |
This routine sends one byte via the Software SPI bus. |
Parameters |
|
Returns |
Nothing. |
Requires |
Soft SPI must be initialized before using this function. See Soft_SPI_Init. |
Example |
' Write a byte to the Soft SPI bus Soft_SPI_Write($AA) |
Notes |
None. |
What do you think about this topic ? Send us feedback!