SPI Library
The SPI Master module is available with all FT90x MCUs.
mikroC 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 |
void 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 |
void SPIM1_Init_Advanced(char masterClkRatio, unsigned int config, unsigned int ssLine); |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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 | _SPI_CFG_POLARITY_IDLE_LOW | _SPI_CFG_SS_AUTO_DISABLE | _SPI_CFG_FIFO_DISABLE, _SPI_SS_LINE_NONE); |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Notes |
|
SPIM1_Read
Prototype |
char SPIM1_Read(char dummy); |
---|---|
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 char take, buffer; ... 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 |
void SPIM1_Read_Bytes(char *bufferIn, unsigned int numBytesToRead); |
---|---|
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 char *buffer[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 |
void SPIM1_Write(char dataOut); |
---|---|
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 unsigned char buffer; ... 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 |
void SPIM1_Write_Bytes(char *bufferOut, unsigned int numBytesToSend); |
---|---|
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 |
void SPIM1_Enable_SS(char ssLine); |
||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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 |
void SPIM1_Disable_SS(char ssLine); |
||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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 |
void 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 |
char SPIM_Read(char dummy); |
---|---|
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 unsigned char take, buffer; ... take = SPIM_Read(buffer); |
Notes |
None. |
SPIM_Read_Bytes
Prototype |
void SPIM_Read_Bytes(char *bufferIn, unsigned int numBytesToRead); |
---|---|
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 char *buffer[16]; ... SPIM_Read_Bytes(&buffer, 16); |
Notes |
None. |
SPIM_Write
Prototype |
void SPIM_Write(char dataOut); |
---|---|
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 unsigned char buffer; ... SPIM_Write(buffer); |
Notes |
None. |
SPIM_Write_Bytes
Prototype |
void SPIM_Write_Bytes(char *bufferOut, unsigned int numBytesToSend); |
---|---|
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 |
void SPIM_Enable_SS(char ssLine); |
||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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 |
void SPIM_Disable_SS(char ssLine); |
||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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!