SPI Library
The SPI Master module is available with all FT90x MCUs.
mikroBasic PRO for FT90x provides a library for comfortable work with the SPI Master module.
The FT90x can easily communicate with other devices via SPI:
A/D converters, D/A converters, MAX7219, LTC1290, etc.
Library Routines
- SPIM1_Init
- SPIM1_Init_Advanced
- SPIM1_Read
- SPIM1_Read_Bytes
- SPIM1_Write
- SPIM1_Write_Bytes
- SPIM1_Enable_SS
- SPIM1_Disable_SS
- SPIM_Set_Active
Generic Routines
SPIM1_Init
| Prototype |
sub procedure SPIM1_Init() |
|---|---|
| Description |
Configures and initializes the SPI module with default parameters :
|
| Parameters |
None. |
| Returns |
Nothing. |
| Requires |
Routine requires SPI module. |
| Example |
' Initialize the SPI module with default settings SPIM1_Init() |
| Notes |
|
SPIM1_Init_Advanced
| Prototype |
sub procedure SPIM1_Init_Advanced(dim masterClkRatio as byte, dim config as word, dim ssLine as word) |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Description |
Configures and initializes the SPI module with user defined settings. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Parameters |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Returns |
Nothing. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Requires |
Routine requires SPI module. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Example |
SPIM1_Init_Advanced(_SPI_MASTER_CLK_RATIO_64, _SPI_CFG_PHASE_CAPTURE_RISING or _SPI_CFG_POLARITY_IDLE_LOW or _SPI_CFG_SS_AUTO_DISABLE or _SPI_CFG_FIFO_DISABLE, _SPI_SS_LINE_NONE) |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Notes |
|
SPIM1_Read
| Prototype |
sub function SPIM1_Read(dim dummy as byte) as byte |
|---|---|
| Description |
Reads one byte from the SPI bus. |
| Parameters |
|
| Returns |
Received byte. |
| Requires |
Routine requires SPI module. Used SPI module must be initialized before using this function. See the SPIM1_Init and SPIM1_Init_Advanced routines. |
| Example |
' read a byte from the SPI bus dim take, buffer as byte ... take = SPIM1_Read(buffer) |
| Notes |
SPI library routines require you to specify the module you want to use. To select the desired SPI module, simply change the letter x in the routine prototype for a number from 0 to 3. Number of SPI modules per MCU differs from chip to chip. Please, read the appropriate datasheet before utilizing this library. |
SPIM1_Read_Bytes
| Prototype |
sub procedure SPIM1_Read_Bytes(dim bufferIn as ^byte, dim numBytesToRead as word) |
|---|---|
| Description |
Reads multiple bytes from the SPI bus. |
| Parameters |
|
| Returns |
Received bytes. |
| Requires |
Routine requires SPI module. Used SPI module must be initialized before using this function. See the SPIM1_Init and SPIM1_Init_Advanced routines. |
| Example |
' read 16 bytes from the SPI bus dim buffer as byte[16] ... SPIM1_Read_Bytes(@buffer, 16) |
| Notes |
SPI library routines require you to specify the module you want to use. To select the desired SPI module, simply change the letter x in the routine prototype for a number from 0 to 3. Number of SPI modules per MCU differs from chip to chip. Please, read the appropriate datasheet before utilizing this library. |
SPIM1_Write
| Prototype |
sub procedure SPIM1_Write(dim dataOut as byte) |
|---|---|
| Description |
Writes one byte to the SPI bus. |
| Parameters |
|
| Returns |
Nothing. |
| Requires |
Routine requires SPI module. Used SPI module must be initialized before using this function. See the SPIM1_Init and SPIM1_Init_Advanced routines. |
| Example |
' write a buffer to the SPI bus dim buffer as byte ... SPIM1_Write(buffer) |
| Notes |
SPI library routines require you to specify the module you want to use. To select the desired SPI module, simply change the letter x in the routine prototype for a number from 0 to 3. Number of SPI modules per MCU differs from chip to chip. Please, read the appropriate datasheet before utilizing this library. |
SPIM1_Write_Bytes
| Prototype |
sub procedure SPIM1_Write_Bytes(dim bufferOut as ^byte, dim numBytesToSend as word) |
|---|---|
| Description |
Writes bytes to the SPI bus. |
| Parameters |
|
| Returns |
Nothing. |
| Requires |
Routine requires SPI module. Used SPI module must be initialized before using this function. See the SPIM1_Init and SPIM1_Init_Advanced routines. |
| Example |
' write a buffer to the SPI bus SPIM1_Write_Bytes(@buffer, 16) |
| Notes |
SPI library routines require you to specify the module you want to use. To select the desired SPI module, simply change the letter x in the routine prototype for a number from 0 to 3. Number of SPI modules per MCU differs from chip to chip. Please, read the appropriate datasheet before utilizing this library. |
SPIM1_Enable_SS
| Prototype |
sub procedure SPIM1_Enable_SS(dim ssLine as byte) |
||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Description |
Enables desired Slave Select line. |
||||||||||||||||||||
| Parameters |
|
||||||||||||||||||||
| Returns |
Nothing. |
||||||||||||||||||||
| Requires |
Routine requires SPI module. Used SPI module must be initialized before using this function. See the SPIM1_Init and SPIM1_Init_Advanced routines. |
||||||||||||||||||||
| Example |
' enable SS line 0 SPIM1_Enable_SS(_SPI_SS_LINE_0) |
||||||||||||||||||||
| Notes |
SPI library routines require you to specify the module you want to use. To select the desired SPI module, simply change the letter x in the routine prototype for a number from 0 to 3. Number of SPI modules per MCU differs from chip to chip. Please, read the appropriate datasheet before utilizing this library. |
SPIM1_Disable_SS
| Prototype |
sub procedure SPIM1_Disable_SS(dim ssLine as word) |
||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Description |
Disables desired Slave Select line. |
||||||||||||||||||||
| Parameters |
|
||||||||||||||||||||
| Returns |
Nothing. |
||||||||||||||||||||
| Requires |
Routine requires SPI module. Used SPI module must be initialized before using this function. See the SPIM1_Init and SPIM1_Init_Advanced routines. |
||||||||||||||||||||
| Example |
' disable SS line 0 SPIM1_Disable_SS(_SPI_SS_LINE_0) |
||||||||||||||||||||
| Notes |
SPI library routines require you to specify the module you want to use. To select the desired SPI module, simply change the letter x in the routine prototype for a number from 0 to 3. Number of SPI modules per MCU differs from chip to chip. Please, read the appropriate datasheet before utilizing this library. |
SPIM_Set_Active
| Prototype |
sub procedure SPIM_Set_Active(
|
|---|---|
| Description |
Sets the active SPI module which will be used by the SPIM1_Read and SPIM1_Write routines. |
| Parameters |
Parameters :
|
| Returns |
Nothing. |
| Requires |
Routine is available only for MCUs with multiple SPI modules. Used SPI module must be initialized before using this function. See the SPIM1_Init and SPIM1_Init_Advanced routines. |
| Example |
SPIM_Set_Active(@SPIM1_Write_Bytes, @SPIM1_Write, @SPIM1_Read_Bytes, @SPIM1_Read, @SPIM1_Enable_SS, @SPIM1_Disable_SS) ' Sets the SPIM1 module active |
| Notes |
Number of SPI modules per MCU differs from chip to chip. Please, read the appropriate datasheet before utilizing this library. |
SPIM_Read
| Prototype |
sub function SPIM_Read(dim dummy as byte) as byte |
|---|---|
| Description |
Reads one byte from the SPI bus. This is a generic routine which uses the active SPI module previously activated by the SPIM_Set_Active routine. |
| Parameters |
|
| Returns |
Received byte. |
| Requires |
Routine requires SPI module. Used SPI module must be initialized before using this function. See the SPIM1_Init and SPIM1_Init_Advanced routines. |
| Example |
' read a word from the SPI bus dim take, buffer as byte ... take = SPIM_Read(buffer) |
| Notes |
None. |
SPIM_Read_Bytes
| Prototype |
sub procedure SPIM_Read_Bytes(dim bufferIn as ^byte, dim numBytesToRead as word) |
|---|---|
| Description |
Reads bytes from the SPI bus. This is a generic routine which uses the active SPI module previously activated by the SPIM_Set_Active routine. |
| Parameters |
|
| Returns |
Received bytes. |
| Requires |
Routine requires SPI module. Used SPI module must be initialized before using this function. See the SPIM1_Init and SPIM1_Init_Advanced routines. |
| Example |
' read 16 bytes from the SPI bus dim buffer as byte[16] ... SPIM_Read_Bytes(@buffer, 16) |
| Notes |
None. |
SPIM_Write
| Prototype |
sub procedure SPIM_Write(dimdataOut as byte) |
|---|---|
| Description |
Writes one byte to the SPI bus. This is a generic routine which uses the active SPI module previously activated by the SPIM_Set_Active routine. |
| Parameters |
|
| Returns |
Nothing. |
| Requires |
Routine requires SPI module. Used SPI module must be initialized before using this function. See the SPIM1_Init and SPIM1_Init_Advanced routines. |
| Example |
' write a byte to the SPI bus dim buffer as byte ... SPIM_Write(buffer) |
| Notes |
None. |
SPIM_Write_Bytes
| Prototype |
sub procedure SPIM_Write_Bytes(dim bufferOut as ^byte, dim numBytesToSend as word) |
|---|---|
| Description |
Writes bytes to the SPI bus. This is a generic routine which uses the active SPI module previously activated by the SPIM_Set_Active routine. |
| Parameters |
|
| Returns |
Nothing. |
| Requires |
Routine requires SPI module. Used SPI module must be initialized before using this function. See the SPIM1_Init and SPIM1_Init_Advanced routines. |
| Example |
' write a buffer to the SPI bus SPIM_Write_Bytes(@buffer, 16) |
| Notes |
None. |
SPIM_Enable_SS
| Prototype |
sub procedure SPIM_Enable_SS(dim ssLine as byte) |
||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Description |
Enables desired Slave Select line. This is a generic routine which uses the active SPI module previously activated by the SPIM_Set_Active routine. |
||||||||||||||||||||
| Parameters |
|
||||||||||||||||||||
| Returns |
Nothing. |
||||||||||||||||||||
| Requires |
Routine requires SPI module. Used SPI module must be initialized before using this function. See the SPIM1_Init and SPIM1_Init_Advanced routines. |
||||||||||||||||||||
| Example |
' enable SS line 0 SPIM_Enable_SS(_SPI_SS_LINE_0) |
||||||||||||||||||||
| Notes |
None. |
SPIM_Disable_SS
| Prototype |
sub procedure SPIM_Disable_SS(dim ssLine as byte) |
||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Description |
Disables desired Slave Select line. This is a generic routine which uses the active SPI module previously activated by the SPIM_Set_Active routine. |
||||||||||||||||||||
| Parameters |
|
||||||||||||||||||||
| Returns |
Nothing. |
||||||||||||||||||||
| Requires |
Routine requires SPI module. Used SPI module must be initialized before using this function. See the SPIM1_Init and SPIM1_Init_Advanced routines. |
||||||||||||||||||||
| Example |
' disable SS line 0 SPIM_Disable_SS(_SPI_SS_LINE_0) |
||||||||||||||||||||
| Notes |
None. |
What do you think about this topic ? Send us feedback!



