pic 16f690 spi haberleşme sorunu

Başlatan atillaa, 11 Aralık 2013, 21:21:59

atillaa

merhaba arkadaşlar, uygulamamda pic 16f690 ile spi haberleşmesi gerçekleştirmek istiyorum. Ayarları yaptım ancak simülasyonda giden veri sürekli 0 gözüküyor. Nerede hata yaptım acaba yardım edebilir misiniz .
spi.h
#define SCK      RB6
#define SDI      RB4
#define SDO      RC7
#define nSEL   RC6
//////////////////
extern void SPICmd8bit(unsigned char WrPara);
extern void SPIWrite(unsigned int WrPara);


spi.c
#include "RFM69H.h"
#include <pic.h>

/**********************************************************
**Name:     SPICmd8bit
**Function: SPI Write one byte
**Input:    WrPara
**Output:   none
**note:     use for burst mode
**********************************************************/
void SPICmd8bit(unsigned char WrPara)
{
 unsigned char bitcnt;	
 nSEL = 0;
 SCK  = 0;

 for(bitcnt=8; bitcnt!=0; bitcnt--)
 	{
 	SCK = 0;
 	if(WrPara&0x80)
 		SDI = 1;
 	else
 		SDI = 0;
 	SCK = 1;
 	WrPara <<= 1;
 	}
 SCK = 0;
 SDI = 1;
}
/**********************************************************
**Name:     SPIWrite
**Function: SPI Write CMD
**Input:    WrPara -> address & data
**Output:   None
**********************************************************/
void SPIWrite(unsigned int WrPara)								
{                                                       
 unsigned char bitcnt;    
 
 SCK  = 0;				
 nSEL = 0;
 
 WrPara |= 0x8000;                                        //MSB must be "1" for write 
 
 for(bitcnt=16; bitcnt!=0; bitcnt--)
 	{
 	SCK = 0;
 	if(WrPara&0x8000)
 		SDI = 1; 
 	else
 		SDI = 0;
	SCK = 1;
 	WrPara <<= 1;
 	}
 SCK = 0;
 SDI = 1; 
 nSEL= 1;
}         


main
void main()
{
led=0;
//unsigned char kontrol;
init();
for(SysTime=0;SysTime<16;);   //delay for stabilize
//RFM69H_Config(2);   // FREQ_SEL: 0-----315MHz   FREQ_SEL: 1-----434MHz    FREQ_SEL: 2-----868MHz  FREQ_SEL: 3-----915MHz
Tx_Drm=0;
Rx_Drm=0;
SPICmd8bit(0xf2);
SPICmd8bit(0xf2);
SPICmd8bit(0xf2);
//BurstWrite(0x00,RxData, 21);
	while(1);


init
void init(void)
{
ANSEL=0x00;
ANSELH=0x00;

/////////////spi ayarları//////////
SSPM3=0;  // Fosc/64
SSPM2=0;
SSPM1=0;
SSPM0=0;
SSPEN=1;
WCOL=0;
SSPOV=0;
////////////port ayarları ////////////

TRISA=0x00;
TRISB=0xB0;
TRISC=0x20;
///////////interrupt ayarları ////////

GIE     = 1;         //Enable GIE
PEIE    = 1;        //Enable PEIE
T0IE	= 1;        //Enable TMR0
RCIE	= 1;
RABIE=1;
RABIF=0;
IOCB=0b10100000;

//////timer0 ayarları////////////
T0CS=0;
PSA=0;
PS2=1;
PS1=1;
PS0=1;
TMR0=130;
////////////////////diğer ayarlar////////////
WDTCON=0;
OSCCON=0x70;  // krsital 8Mhz seçiliyor
ADCON0=0;
ADCON1=0;
}