mikroC

making it simple...

Spi_Init_Advanced

mikroC - C Compiler for Microchip PIC microcontrollers

Prototype

void Spi_Init_Advanced(char master,

char data_sample, char

 

clock_idle, char transmit_edge);

 

 

 

 

Description

Configures and initializes SPI. Spi_Init_Advanced or SPI_Init needs to be called

 

before using other functions of SPI Library.

 

 

 

Parameter mast_slav determines the work mode for SPI; can have the values:

 

MASTER_OSC_DIV4

// Master clock=Fosc/4

 

 

MASTER_OSC_DIV16

// Master clock=Fosc/16

 

 

MASTER_OSC_DIV64

// Master clock=Fosc/64

 

 

MASTER_TMR2

// Master clock

source

TMR2

 

SLAVE_SS_ENABLE

// Master Slave

select

enabled

 

SLAVE_SS_DIS

// Master Slave

select

disabled

The data_sample determines when data is sampled; can have the values:

DATA_SAMPLE_MIDDLE // Input data sampled in middle of interval

DATA_SAMPLE_END // Input data sampled at the end of interval

Parameter clock_idle determines idle state for clock; can have the following values:

CLK_IDLE_HIGH

//

Clock

idle

HIGH

CLK_IDLE_LOW

//

Clock

idle

LOW

Parameter transmit_edge can have the following values:

LOW_2_HIGH // Data transmit on low to high edge

HIGH_2_LOW // Data transmit on high to low edge

Requires You need PIC MCU with hardware integrated SPI.

Example This will set SPI to master mode, clock = Fosc/4, data sampled at the middle of interval, clock idle state low and data transmitted at low to high edge:

Spi_Init_Advanced(MASTER_OSC_DIV4, DATA_SAMPLE_MIDDLE,

CLK_IDLE_LOW, LOW_2_HIGH)

 

 

page

 

MikroElektronika: Development tools - Books - Compilers

267