reddster
Newbie level 3

spi protocol basics+pic16f877
Hi to all!
I am a student undergoing a project which involves the interfacing
of the PIC16F877 to a Phase locked loop device(ADF4360-8) using the SPI.
Basically, I need to send out, via SDO, 3 batches of 24 bits to
the device to initialise it. I am worried that i might miss a few lines
of code because i could not detect the SCK signal from the SCK pin (RC3).
Also, am I doing it correctly for the initialisation of the SSPSTAT, SSPCON
and the sending part?
I fully appreciate your help!!
This is my code in C Language:
#include <pic1687x.h>
#include "delay.c"
void main () {
PORTA = 0x00;
PORTB = 0x00;
PORTC = 0x00;
PORTD = 0x00;
PORTE = 0x00;
TRISC = 0b00010000; //RC4=SPI Data In
TRISD = 0x00;
TRISB = 0b00000001; //RB0=input
TRISA = 0x00;
TRISE = 0x00;
//initialise PLL
//R counter = 0011 0000 0000 0000 0111 1001
//Control latch = 0000 1111 1111 0001 0000 0100
//N counter = 0000 0000 1011 0100 0000 0010
SSPSTAT = 0b01000000;
SSPCON = 0b00100010;
SSPBUF = 0b00110000; //R counter
SSPBUF = 0b00000000;
SSPBUF = 0b01111001;
RA5 = 1; //LE high to transfer data from shift register to latch
RA5 = 0;
SSPBUF = 0b00001111; //Control
SSPBUF = 0b11110001;
SSPBUF = 0b00000100;
RA5 = 1; //LE high to transfer data from shift register to latch
RA5 = 0;
DelayMs(20); //Delay between Control and N Counter
SSPBUF = 0b00000000; //N Counter
SSPBUF = 0b10110100;
SSPBUF = 0b00000010;
RA5 = 1; //LE high to transfer data from shift register to latch
RA5 = 0;
while(1){
if(RB0==1)//When RB0 is high, pull CE pin high to turn on PLL
RC1 = 1;
if(RB0==0)//When RB0 is low, pull CE pin low to turn off PLL
RC1 = 0;
}
} //end of main
Thanks again!!
Hi to all!
I am a student undergoing a project which involves the interfacing
of the PIC16F877 to a Phase locked loop device(ADF4360-8) using the SPI.
Basically, I need to send out, via SDO, 3 batches of 24 bits to
the device to initialise it. I am worried that i might miss a few lines
of code because i could not detect the SCK signal from the SCK pin (RC3).
Also, am I doing it correctly for the initialisation of the SSPSTAT, SSPCON
and the sending part?
I fully appreciate your help!!
This is my code in C Language:
#include <pic1687x.h>
#include "delay.c"
void main () {
PORTA = 0x00;
PORTB = 0x00;
PORTC = 0x00;
PORTD = 0x00;
PORTE = 0x00;
TRISC = 0b00010000; //RC4=SPI Data In
TRISD = 0x00;
TRISB = 0b00000001; //RB0=input
TRISA = 0x00;
TRISE = 0x00;
//initialise PLL
//R counter = 0011 0000 0000 0000 0111 1001
//Control latch = 0000 1111 1111 0001 0000 0100
//N counter = 0000 0000 1011 0100 0000 0010
SSPSTAT = 0b01000000;
SSPCON = 0b00100010;
SSPBUF = 0b00110000; //R counter
SSPBUF = 0b00000000;
SSPBUF = 0b01111001;
RA5 = 1; //LE high to transfer data from shift register to latch
RA5 = 0;
SSPBUF = 0b00001111; //Control
SSPBUF = 0b11110001;
SSPBUF = 0b00000100;
RA5 = 1; //LE high to transfer data from shift register to latch
RA5 = 0;
DelayMs(20); //Delay between Control and N Counter
SSPBUF = 0b00000000; //N Counter
SSPBUF = 0b10110100;
SSPBUF = 0b00000010;
RA5 = 1; //LE high to transfer data from shift register to latch
RA5 = 0;
while(1){
if(RB0==1)//When RB0 is high, pull CE pin high to turn on PLL
RC1 = 1;
if(RB0==0)//When RB0 is low, pull CE pin low to turn off PLL
RC1 = 0;
}
} //end of main
Thanks again!!