Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Interfacing 18F4420 with AD7303 using SPI.

Status
Not open for further replies.

Cheng

New Member
Hi all, I'm trying to program PIC18F4420 using the SPI module to output an 8-bit information to AD7303, where it'll convert the binary data to relevant voltage. However, I just can't seem to get it to work with the code below. Any help would be most appreciated? =)

Code:
#include <p18f4420.h>
#include <delays.h>

unsigned char A;

void SPI(unsigned char);
unsigned char Variable;

void main(void)
{
	//SSP configuration
	TRISCbits.TRISC5=0;
	TRISCbits.TRISC3=0;
	TRISCbits.TRISC6=0;
	
	PORTCbits.RC5=0;
	PORTCbits.RC3=0;
	PORTCbits.RC6=1;

	SSPSTATbits.CKE = 1;
	SSPCON1 = 0x22;
	
	PORTCbits.RC4=0;

	SPI(0x00);

	
for(;;)	
{
	PORTCbits.RC6 = 0; //set at logic '0'
	SPI(0b00000001);
	SPI(0xAD);
	PORTCbits.RC6 = 1;
	PORTCbits.RC6 = 0; //set at logic '0'
	SPI(0b00110001);
	SPI(0xAD);
	PORTCbits.RC6 = 1;
}

		
}

void SPI(unsigned char Data)
{
	SSPBUF = Data;
	while(SSPSTATbits.BF==0);
	Data=SSPBUF;
	
}
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top