예제 #1
0
//------------------------------------------------------------------------------
//  void pktRxHandler(void)
//
//  DESCRIPTION:
//      This function is called every time a timer interrupt occurs. The 
//      function starts by retreiving the status byte. Every time the status 
//      byte indicates that there are available bytes in the RX FIFO, bytes are 
//      read from the RX FIFO and written to RxBuffer. This is done until the 
//      whole packet is received. If the status byte indicates that there has 
//      been an RX FIFO overflow the RX FIFO is flushed. Please see the 
//      EM430F5137RF900 RF Examples User Manual for a flow chart describing this 
//      function.
//------------------------------------------------------------------------------
void pktRxHandler(void) {
  unsigned char RxStatus;
  unsigned char bytesInFifo;
  
  // Which state?
  RxStatus = Strobe(RF_SNOP);
  
  switch(RxStatus & CC430_STATE_MASK)
  {
    case CC430_STATE_RX:
      // If there's anything in the RX FIFO....
      if (bytesInFifo = MIN(rxBytesLeft, RxStatus & CC430_FIFO_BYTES_AVAILABLE_MASK))
      {         
        if((rxBytesLeft == PACKET_LEN + 2) && !lengthByteRead)
        {
          rxBytesLeft = ReadSingleReg(RXFIFO) + 2;  // For appended bytes
          lengthByteRead = 1; 
        }
        // Update how many bytes are left to be received
        rxBytesLeft -= bytesInFifo;
  
        // Read from RX FIFO and store the data in rxBuffer
        while (bytesInFifo--) {
          RxBuffer[rxPosition] = ReadSingleReg(RXFIFO);
          rxPosition++; 
        }  
        if (!rxBytesLeft){           
            packetReceived = 1; 
            receiving = 0;
            lengthByteRead = 0; 
            ReceiveOff();
            
            P1OUT ^= BIT0;                    // Toggle LED1             
        }      
      } 
      break;
    default:
      if(!packetReceived)
      {
        packetReceived = 1; 
      }
      
      rxBytesLeft = 0;
      receiving = 0; 
      ReceiveOff();

      break;  
  }
} // pktRxHandler
예제 #2
0
void main( void )
{  
  // Stop watchdog timer to prevent time out reset 
  WDTCTL = WDTPW + WDTHOLD; 
  // Increase PMMCOREV level to 2 for proper radio operation
  SetVCore(2);                               
  
  ResetRadioCore();
  InitButtonLeds();
  InitTimer(); 
    
  // Clean out the RX Buffer 
  rxPosition = PACKET_LEN+2;
  while(rxPosition--)
  {
    RxBuffer[rxPosition] = 0; 
  }

  InitRadio();  
  ReceiveOn(); 
//Check RSSI here
  while (1)
  { 
    P1IE |= BIT7;                           // Enable button interrupt
    
    __bis_SR_register( LPM3_bits + GIE );   
    __no_operation(); 
    
    if (buttonPressed)                      // Process a button press->transmit
    {
      ReceiveOff();                         // Button means TX, stop RX
      receiving = 0;                         

      TransmitPacket();                 

      buttonPressed = 0;                    // Re-enable button press                           
    }
    if(receiving)
    {
      ReceivePacket(); 
      __no_operation(); 
      // Check CRC
      if(RxBuffer[CRC_LQI_IDX] & CRC_OK)
      //Got it!
      P1OUT ^= BIT0;                    // Toggle LED1 in celebration

    }
    if(!transmitting)
    {
      ReceiveOn(); 
    }
  }


}
예제 #3
0
void RF_Connection_Test(void)
{  
  Init_RF();
  timer1_A3_Up_Mode;
  
  while(1){
    
    if (buttonPressed)                      // Process a button pressed --> transmit 
    {
      //P3OUT |= BIT6;                        // Pulse LED during Transmit                          
      buttonPressed = 0; 
      P1IFG = 0; 
      
      ReceiveOff();
      Transmit( (unsigned char*)TxBuffer, sizeof TxBuffer);      
      
      //Wait for TX status to be reached before going back to low power mode
      while((Strobe(RF_SNOP) & 0x70) != 0x20);    
       
      P1IE |= BIT1;                         // Re-enable button press  
    }
    else if (packetTransmit)
    {
      RF1AIE &= ~BIT9;                      // Disable RFIFG9 TX end-of-packet interrupts
      //P3OUT &= ~BIT6;                       // Turn off LED after Transmit 
      
      ReceiveOn();
      
      //Wait for RX status to be reached
      while((Strobe(RF_SNOP) & 0x70) != 0x10); 
    
      packetTransmit = 0; 
    }
    else if(packetReceived)                 // Process a received packet 
    {
      char toggle = 1; 
      
      // Read the length byte from the FIFO       
      RxBufferLength = ReadSingleReg( RXBYTES );               
      ReadBurstReg(RF_RXFIFORD, RxBuffer, RxBufferLength); 
    
      // Check the packet contents and don't toggle LED if they are different 
      for(i = 0; i < RxBuffer[0]; i++)
      {
        if(RxBuffer[i] != TxBuffer[i]) toggle = 0; 
      }      
        
      if(toggle){
        LED_Togg;                  // Toggle LED
        packetReceived = 0; 
      }
      
    }
  }
}
void Send_Data(unsigned char ADDRESS, unsigned char* Data)
{
	unsigned char TxBuffer[PACKET_LEN];

	append(Data, ADDRESS, TxBuffer);

	ReceiveOff();
	receiving = 0;

	Transmit( (unsigned char*)TxBuffer, sizeof TxBuffer);
	transmitting = 1;
}
void main( void )
{  
  // Stop watchdog timer to prevent time out reset 
  WDTCTL = WDTPW + WDTHOLD; 
  TA1CCTL0 = CCIE;                          // CCR0 interrupt enabled
  TA1CCR0 = 50000;
  TA1CTL = TASSEL_2 + MC_1 + TACLR;         // SMCLK, upmode, clear TAR
   __bis_SR_register(GIE);
  //WDTCTL = WDT_ARST_250;
  //SFRIE1 |= WDTIE;                          // Enable WDT interrupt
  // Increase PMMCOREV level to 2 for proper radio operation
  SetVCore(2);                            
  
  ResetRadioCore();     
  InitRadio();
  InitButtonLeds();
  InitUart();
    
  ReceiveOn(); 
  receiving = 1; 
  _EINT();  
  while (1)
  { 
    //WDTCTL = WDT_ARST_250;
   // __bis_SR_register( LPM3_bits + GIE ); 
    __no_operation();
    
  if((!(BUTTON_IN & (1<<BUTTON_BIT))))
    {
      _NOP();
      delayms(30);
      if(!(BUTTON_IN & (1<<BUTTON_BIT)))
      {
        _NOP();
		buttonPressed = 1;		
        LEDR_ON();
        ReceiveOff();
        receiving = 0;
        Transmit( (unsigned char*)TxBuffer,sizeof TxBuffer);
        transmitting = 1;
		while(!(BUTTON_IN & (1<<BUTTON_BIT)));
      }
      
    }
    if(!transmitting)
    {
      ReceiveOn();
      receiving = 1;
    }
	if(buttonPressed && transmit == 1)
	{
		LEDR_ON();
        ReceiveOff();
        receiving = 0;
        Transmit( (unsigned char*)TxBuffer,sizeof TxBuffer);
        transmitting = 1;
		transmit = 0;
		receive = 1;
		delayms(500);
		buttonPressed = 0;	
	}
	if(count == 20 && buttonPressed == 0 && receive == 1)
	{
	buttonPressed = 1;	
	count = 0;
	transmit = 1;
	receive = 0;
	}
  }
}