示例#1
0
/*

  Write a Command to the RFM Module using SPI
  
  Requires: 16bit valid command
  Returns:  16bit result from transaction
  
  This is a bi-directional transfer.  
  A command is clocked out to the RFM a bit at a time.  
  At the same time a result is clocked back in a bit at a time.
   
*/
uint WriteCMD(uint CMD)
{
	
	uint RESULT = 0;							// Holds the received SDI
	uchar n=16;									// number of bits in SPI Command we need to send
	LOW_SCK();									// SCK LOW
	LOW_SEL();									// CS LOW
	while(n--)									// Send All 16 Bits MSB First
	{
		if (CMD&0x8000)
		{
			Write1();							// Write 1 via SDI		
		}
		else
		{
			Write0();							// Write 0 via SPI
		}
		
		RESULT<<=1;								// Shift left for next bit to receive
		if(SDI)									// Check if we received a high on SDI
			RESULT |= 0x0001;					// RESULT LSB = 1		
		CMD<<=1;								// Shift left for next bit to send
	}
	LOW_SCK();									// SCK LOW
	HI_SEL();									// CS HIGH - Finished Sending Command
	return RESULT;
}
示例#2
0
void WriteCMD(int16 CMD)
{
	int8 n = 16;

	output_low(_SCK);
	RF_EN	= false;

	while (n--){
		if (CMD&0x8000)
			Write1();
		else
			Write0();
		CMD<<=1;
	}
	SCK		= false;
	RF_EN	= true;
}
示例#3
0
/* 
  Waits for RFM 12 to become ready by checking first bit of status register
  Before we can Tx or Rx data the RFM12 needs to be ready, 
  i.e. not in the middle of transmitting a previous byte
  
  This function is blocking and will only return when it is ready to Tx or Rx
*/
void WaitReady(void)
{	
//#ifdef DEBUG							// always return for simulator
//		return;
//#endif
	unsigned long timeout = 0;
	bit READY = 0;
	while(READY == 0)						
	{
		LOW_SCK();						// SCK LOW
		LOW_SEL();						// CS LOW
		Write0();
		if(SDI==1)						// check RGIT bit of status (first bit)
		{ 								// If HIGH then Tx/RX is ready to accept the next byte
			READY = 1;
		}	
		LOW_SCK();						// SCK LOW
		LOW_SDO();
		HI_SEL();						// CS HIGH - Finished Sending Command
	}
}