I'm kind of new to this so am unsure of what to do. I'm using the MPLAB C18 compiler. I'm using the C18 programming library functions like ReadSPI and WriteSPI. This is the code I'm using. It isn't giving me the output I need and I can't spot what I might be doing wrong.
#include <p18cxxx.h>
#include <usart.h>
#include <delays.h>
#include <spi.h>
#include <stdio.h>
#include <string.h>
#pragma config WDT = OFF
#pragma config LVP = OFF
#define MSEL1 PORTDbits.RD0
#define MSEL2 PORTDbits.RD7
#pragma config OSC = INTIO67 //for internal clock 1Mhzs instruction cycle frequency
unsigned char cmd;
unsigned char dummy1;
unsigned char dummy2;
//value assignment within main loop;
void main()
{
cmd=0x20;
dummy1=0x00;
dummy2=0x00;
SSPBUF = cmd;
TRISDbits.TRISD0=0; //Set RD0 as output
TRISDbits.TRISD7=0; //Set RD7 as output
OpenSPI(SPI_FOSC_4,MODE_01,SMPEND);
Nop();
Nop();
MSEL2=0;
Nop();
Nop();
WriteSPI(SSPBUF); //configuring the gyro for rate sensing
MSEL2=1;
Nop();
while(1)
{
Nop();
Nop();
MSEL1=0;
Nop();
Nop();
dummy1 = ReadSPI(); //reading rate output from gyro
dummy2 = ReadSPI();
MSEL1=1;
Nop();
Nop();
// CloseSPI();
}
}