Mikroelektronika MIKROE-350 Datenbogen
![Mikroelektronika](https://files.manualsbrain.com/attachments/e0529b3b58069a916ad7bb89f7e9f5f0eda73421/common/fit/150/50/1b07b99aa3112e022a916b06db07f1f4f211e91d41878452d87c7638b1bf/brand_logo.gif)
SPI1_Init_Advanced
363
MIKROELEKTRONIKA
- SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Libraries
mikroBasic PRO for AVR
CHAPTER 6
Prototype
sub procedure SPI1_Init_Advanced(dim mode, fcy_div,
clock_and_edge as byte)
clock_and_edge as byte)
Returns
Nothing.
Description
Configures and initializes SPI. SPI1_Init_Advanced or SPI1_Init needs to be
called before using other functions of SPI Library.
called before using other functions of SPI Library.
Parameters mode, fcy_div and clock_and_edge determine the work mode for
SPI, and can have the following values:
Note: Some SPI clock speeds are not supported by all AVR MCUs and these
are:
are:
Fosc/2, Fosc/8, Fosc/32
. Please consult appropriate datasheet.
Requires
MCU must have SPI module.
Example
' Set SPI to the Master Mode, clock = Fosc/32 , clock idle level
is high, data sampled on falling edge:
SPI1_Init_Advanced(_SPI_MASTER, _SPI_FCY_DIV32,
_SPI_CLK_HI_TRAILING);
is high, data sampled on falling edge:
SPI1_Init_Advanced(_SPI_MASTER, _SPI_FCY_DIV32,
_SPI_CLK_HI_TRAILING);
Mask
Description
Predefined library
const
SPI mode constants:
0x10
Master mode
_SPI_MASTER
0x00
Slave mode
_SPI_SLAVE
Clock rate select constants:
0x00
Sck = Fosc/4, Master mode
_SPI_FCY_DIV4
0x01
Sck = Fosc/16, Master mode
_SPI_FCY_DIV16
0x02
Sck = Fosc/64, Master mode
_SPI_FCY_DIV64
0x03
Sck = Fosc/128, Master mode
_SPI_FCY_DIV128
0x04
Sck = Fosc/2, Master mode
_SPI_FCY_DIV2
0x05
Sck = Fosc/8, Master mode
_SPI_FCY_DIV8
0x06
Sck = Fosc/32, Master mode
_SPI_FCY_DIV32
SPI clock polarity and phase constants:
0x00
Clock idle level is low, sample
on rising edge
_SPI_CLK_LO_LEADING
0x04
Clock idle level is low, sample
on falling edge
_SPI_CLK_LO_TRAILING
0x08
Clock idle level is high, sample
on rising edge
_SPI_CLK_HI_LEADING
0x0C
Clock idle level is high, sample
on falling edge
_SPI_CLK_HI_TRAILING