Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] SPI CLOCK not working

Status
Not open for further replies.

embeded

Newbie level 3
Joined
Jun 14, 2015
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
20
Hello,
I am a newbie in PIC18 series
I am trying to set up basic SPI on PIC18F4550.
following is the code,
I am not getting SPI clock. Please help
Code:
#include <p18f4550.h>
#include <stdio.h>
#include <stdlib.h>
#pragma config FOSC = INTOSCIO_EC

void initialise_SPI(void);
void spi_w(unsigned char data);  
void init_io(void)
{
TRISD = 0x00;   
TRISB=0b00000001;   //sck RB1 and DI RB0 for 4550
TRISCbits.RC7 = 0;      //DO for 4550
}

//SPI write command function
void spi_w(unsigned char data)
{  
unsigned char x; 
PORTCbits.RC6=0; 
while (!SSPIF);  //wait for transmission complete  
x=SSPBUF;  	//dummy read  
SSPBUF=data;  
while (!SSPIF);  //wait for transmission complete  
x=SSPBUF;  
PORTCbits.RC6=1;
}

void initialise_SPI(void)
{  SSPEN = 0;
SSPSTAT=0b01000000; 
SSPCON1=0b00100000; 
SSPEN = 1;
}    

void main()
{	
unsigned char data= 0x05;
init_io();
initialise_SPI();
	while(1)
	{	
	spi_w(data);
	PORTD=data;
	}	  
}
 

How do you know the SPI clock isn't working?
Did you measure it with an Oscilloscope? Did you measure the MOSI?
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top