
/////////////////////////////////////////////////////////////////////////////////////////////////////////
LIBRARY
/////////////////////////////////////////////////////////////////////////////////////////////////////////
#include "rfm12.h"
#include "delay4MHZ.h"
#include "general.h"
#include "serial.h"
Tubuf buffer;
void ini_RFM12(void)
{
SDI_hope_io=0; // SDI Port RFM12 (Serial Data input)
SDI_hope=0; // Output
SCK_hope_io=0; // SCK Port RFM12 (Serial Data Clock)
SCK_hope=0; // Output ( Default 0)
nSEL_hope_io=0; // nSEL Port RFM12 (Chip Select -active low-)
nSEL_hope=1; // Output (Default 1)
SDO_hope_io=1; // SDO Port RFM12 (Serial Data output) Input
delay_ms(2000); // Waiting Two seconds!!!!! while the module starts
WriteCMD(0x80D7); // EL,EF,433band,12.0pF
#ifdef RFMTX
WriteCMD(0x8239); // !er,!ebb,ET,ES,EX,!eb,!ew,DC ...TX
#endif
#ifdef RFMRX
WriteCMD(0x82D9); // er,ebb,!ET,ES,EX,!eb,!ew,DC ...RX
#endif
WriteCMD(0xA640); // 434MHz
WriteCMD(0xC647); // 4.8kbps
WriteCMD(0x94A0); // VDI,FAST,134kHz,0dBm,-103dBm
WriteCMD(0xC2AC); // AL,!ml,DIG,DQD4
WriteCMD(0xCA81); // FIFO8,SYNC,!ff,DR
WriteCMD(0xCED4); // SYNC=2DD4;
WriteCMD(0xC483); // @PWR,NO RSTRIC,!st,!fi,OE,EN
WriteCMD(0x9850); // !mp,90kHz,MAX OUT
WriteCMD(0xCC77); // OB1,OB0, LPX,!ddy,DDIT,BW0
WriteCMD(0xE000); // NOT USE
WriteCMD(0xC800); // NOT USE
WriteCMD(0xC040); // 1.66MHz,2.2V
delay_ms(2000); // Waiting Two seconds!!!!! while the module starts
}
*******************************************************************************//
unsigned int WriteCMD(unsigned int CMD)
{
unsigned int RESULT=0; // Save the received data SPI
unsigned char n=16; // Bits Number to send
nSEL_hope=0; // nSEL (CS) LOW
while(n--) // Sends 16 bits (MSB first)
{
if (CMD&0x8000) // Check MSB
SDI_hope=1; // Writes 1
else
SDI_hope=0; // Writes 0
SCK_hope=1; // Clock bit
RESULTADO<<=1; // Shift left for next bit
if(SDO_hope==1) // Check if receive 1
RESULT |= 0x0001; // RESULT LSB = 1
CMD<<=1; // Shift left for next bit
SCK_hope=0; // clock
}
nSEL_hope=1; // nSEL (CS) LOW -finished command-
delay_ms(100);
return RESULT;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
MAIN
/////////////////////////////////////////////////////////////////////////////////////////////////////////
void main(void)
{
CONF_PORTS(); // Ports Conf
CONF_OSC(); // Osc Conf
CONF_T0(); // Timer Conf
conf_serial(25);
GIE=1; // Global Interrupt Activation
ini_RFM12();
while(1)
{
#ifdef RFMTX
WriteCMD(0x0000);
WriteCMD(0xB8AA);
WriteCMD(0xB8AA);
WriteCMD(0xB8AA);
WriteCMD(0xB82D);
WriteCMD(0xB8D4);
WriteCMD(0xB832);
WriteCMD(0xB878);
#endif
#ifdef RFMRX
WriteCMD(0x0000);
WriteCMD(0xB000);
WriteCMD(0xCA81);
WriteCMD(0xCA83);
#endif
delay_ms(200);
RB5=!RB5;
}
}
I really appreciate your help... I've have working without success like 4 days!!!!
Regards, Albert