User manual
mikroBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
471
Parameters
Returns Nothing.
Requires MCU must have the SPI module.
Example
‘ Set SPI1 to the Master Mode, data length is 16-bit, clock = Fcy (no clock
scaling), data sampled in the middle of interval, clock IDLE state high and
data transmitted at low to high clock edge:
SPI1_Init_Advanced(_SPI_MASTER, _SPI_16_BIT, _SPI_PRESCALE_SEC_1, _SPI_
PRESCALE_PRI_1, _SPI_SS_DISABLE, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_
HIGH, _SPI_ACTIVE_2_IDLE)
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 1 to 3.
Number of SPI modules per MCU differs from chip to chip. Please, read the appropriate datasheet
before utilizing this library.
Slave Select Enable/Disable
Description Predened library const
SS used for the Slave mode _SPI_SS_ENABLE
SS not used for the Slave mode _SPI_SS_DISABLE
Data Sampling Moment
Description Predened library const
Data sampled in the middle of data output time _SPI_DATA_SAMPLE_MIDDLE
Data sampled at end of data output time _SPI_DATA_SAMPLE_END
Clock Polarity
Description Predened library const
IDLE state is Lo, ACTIVE state is Hi _SPI_CLK_IDLE_LOW
IDLE state is Hi, ACTIVE state is Lo _SPI_CLK_IDLE_HIGH
Clock Edge
Description Predened library const
Data is valid on ACTIVE-to-IDLE transition _SPI_ACTIVE_2_IDLE
Data is valid on IDLE-to-ACTIVE transition _SPI_IDLE_2_ACTIVE
The parameter slave_select determines whether the Slave Select (SS) pin is used in communication.
Valid in the Slave Mode only.
The parameter data_sample determines the sample moment (phase) of input data.
The parameter clock_idle determines the behaviour of the SPI clock (CLK) line in IDLE phase.
The parameter edge determines on which clock edge data is considered to be valid.