|
© MCS Electronics, 1995-2007 |
|
|
|
INTERRUPT |
Specify ON or OFF. ON will enable the SPI interrupts to occur. While |
|
|
OFF disables SPI interrupts. ENABLE SPI and DISABLE SPI will |
|
|
accomplish the same. |
|
The default setting for hardware SPI when set from the Compiler, Options, SPI menu is MSB first, POLARITY = HIGH, MASTER = YES, PHASE = 0, CLOCKRATE = 4
When you use CONFIG SPI = HARD alone without the other parameters, the SPI will only be enabled. It will work in slave mode then with CPOL =0 and CPH=0.
In hardware mode the SPIINIT statement will set the SPI pins to : sbi DDRB,7 ; SCK output
cbi DDRB,6 ; MISO input sbi DDRB,5 ; MOSI output
In softmode the SPIINIT statement will set the SPI pins for example to : sbi PORTB,5 ;set latch bit hi (inactive)SS
sbi DDRB,5 ;make it an output SS cbi PORTB,4 ;set clk line lo
sbi DDRB,4 ;make it an output cbi PORTB,6 ;set data-out lo MOSI
sbi DDRB,6 ;make it an output MOSI cbi DDRB,7 ;MISO input
Ret
When you want to address multiple slaves with the software SPI you need multiple pins to select/activate the slave chip. Specify NONE for SS in that case. This also means that before every SPI command you need to set the logic level to 0 to address the chip and after the SPI command you need to set it back to a logic high level.
The hardware SPI also has this option. The NOSS parameter with a value of 1, wil not set the SS line to logic 0 when the SPI operation begins. You need to set SS or any other pin of your choice to a logic 0 yourself. After the SPI command(s) are used you need to set it back to a logic 1 to deselect the slave chip.
All SPI routines are SPI-master routines. Example 2 below demonstrates how to create a soft SPI slave. In the samples directory you will also find a SPI hardware master and SPI hardware slave sample.
See also
SPIIN , SPIOUT , SPIINIT , SPI , SPIMOVE
Example
Config SPI = SOFT, DIN = PINB.0 , DOUT = PORTB.1, SS = PORTB.2, CLOCK = PORTB.3
Dim var As Byte
SPIINIT 'Init SPI state and pins. SPIOUT var , 1 'send 1 byte
CONFIG SERVOS