PIC18f4220

Status
Not open for further replies.

BUSHRATARIQ

New Member
hey i am a beginner in embedded programming. i am trying to make a master slave spi link between two pics, pic18f4220. but i am facing alot of problem.
i am configuring everything fine but there is nothing on my SCK pin of master pic. also there is nothing on my SDO of master pic. and another problem i am facing is that i have connected an led to port b configured as output port. to blink at the start and end of code. its blinking is not visible unless i put a probe on some other pin of port b.
i dont understand why.
Can anyone please help!
 
Hi,

You need to post your program code for both master and slave plus the circuit diagram, otherwise its difficult to see where you have gone wrong
 
hey
i am trying to configure only master pic first and separately. the code i am using is

#include<p18f4220.h>
#include<spi.h>
#pragma config WDT=OFF

void main()

{
unsigned char a,m;

TRISB=0;
PORTB=0;

TRISA=0;
PORTA=0x03;

m=0xFF;

PORTAbits.RA0=1;
SSPCON1bits.SSPEN=1;
SSPCON1bits.SSPM0=0;
SSPCON1bits.SSPM1=0;
SSPCON1bits.SSPM2=0;
SSPCON1bits.SSPM3=0;
SSPCON1bits.SSPOV=0;
SSPCON1bits.WCOL=0;

TRISC=0;
SSPCON1bits.CKP=0;
SSPSTATbits.CKE=0;
SSPSTATbits.SMP=0;

while(1)
{
PORTB=0xFF;
PORTAbits.RA0=0;
a=1000;
while(a--);
SSPBUF=m;
PORTAbits.RA0=1;
PORTB=0;

a=1000;
while(a--);

}

The problem with this code is that i dont get anything on the SDO pin and SCK.
 
According to the datasheet.. You have to set all the relevant SSP module settings BEFORE you enable.

Set your SSPCON bits and then enable SSPEN.

Wrong info deleted
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…