int main(void)
{
  BSP_Init();
  P2DIR |= 0x04;
  MRFI_Init();
  //mrfiSpiWriteReg(PATABLE,0x50);// -30dBm Tx power
  //mrfiSpiWriteReg(PATABLE,0x84);// -24dBm Tx power
  //mrfiSpiWriteReg(PATABLE,0x46);// -20dBm Tx power
  //mrfiSpiWriteReg(PATABLE,0x55);// -16dBm Tx power
  //mrfiSpiWriteReg(PATABLE,0x8D);// -14dBm Tx power
  //mrfiSpiWriteReg(PATABLE,0xC6);// -12dBm Tx power
  //mrfiSpiWriteReg(PATABLE,0x97);// -10dBm Tx power
  //mrfiSpiWriteReg(PATABLE,0x6E);// -8 dBm Tx power
  //mrfiSpiWriteReg(PATABLE,0x7F);// -6 dBm Tx power
  //mrfiSpiWriteReg(PATABLE,0xA9);// -4 dBm Tx power
  //mrfiSpiWriteReg(PATABLE,0xBB);// -2 dBm Tx power
  mrfiSpiWriteReg(PATABLE,0xFE);// 0dBm Tx power
  mrfiSpiWriteReg(MDMCFG1,0x23);
  mrfiSpiWriteReg(MDMCFG0,0xF8);// 400kHz channel spacing
  mrfiSpiWriteReg(FREQ2,0x5C);
  mrfiSpiWriteReg(FREQ1,0x80);
  mrfiSpiWriteReg(FREQ0,0x00);  // 2.405GHz base frequency
  mrfiSpiWriteReg(CHANNR,0xBC); // channel 26
  MRFI_WakeUp();
  MRFI_RxOn();
  __bis_SR_register(GIE+LPM3_bits);
}
Example #2
0
interrupt(PORT1_VECTOR) Buttopn(void)
{
	P1IFG &= ~0x04;
	P1OUT ^=  0x03;
	//after press the button , we can send and recieve message 
	BSP_Init();
	MRFI_Init();
	MRFI_SetLogicalChannel(1);
	MRFI_SetRFPwr(0);

	Uart_Init();

	MRFI_WakeUp();
	MRFI_RxOn(); 

	Scan_Init(&etat);			//open timer B for scan
	Start_Timer_Surveille();		//open timer for surveille

	print("\n\r");
	print("command: \n\r");
	print("o  : who is on line \n\r");
	print("v  : voisin \n\r");
	print("r  : router table \n\r");
	print("i  : sysinfo \n\r");
	print("ESC: help \n\r");
}
int main(void)
{
  BSP_Init();
  MRFI_Init(/*0x9D, 0x58, 0x5C*/);
  P3SEL    |= 0x30;
  UCA0CTL1  = UCSSEL_2;
  UCA0BR0   = 0x41;
  UCA0BR1   = 0x3;
  UCA0MCTL  = UCBRS_2;
  UCA0CTL1 &= ~UCSWRST;
  MRFI_WakeUp();
  __bis_SR_register(GIE);
  
  while(1) {
    
      //NEED TO SET !!!
    uint8_t SubChannelsAmount = 13;
      //
    for(uint8_t SubChannelsCounter = 1; SubChannelsCounter <= SubChannelsAmount; SubChannelsCounter++)
    {
        SetBaseFrequencyRegisters(SubChannelsCounter);
        ReadChannelsAndSendRSSI();
    }
    
    TXString("\n",1);
  }
}
/***********************************************************************************
 * @fn          SMPL_Init
 *
 * @brief       Initialize the SimpliciTI stack.
 *
 * input parameters
 * @param   f  - Pointer to call back function. Function called by NWK when
 *               user application frame received. The callback is done in the
 *               ISR thread. Argument is Link ID associated with frame. Function
 *               returns 0 if frame is to be kept by NWK, otherwise 1. Frame
 *               should be kept if application will do a SMPL_Receive() in the
 *               user thread (recommended). Pointer may be NULL.
 *
 * output parameters
 *
 * @return   Status of operation:
 *             SMPL_SUCCESS
 *             SMPL_NO_JOIN     No Join reply. AP possibly not yet up.
 *             SMPL_NO_CHANNEL  Only if Frequency Agility enabled. Channel scan
 *                              failed. AP possibly not yet up.
 */
smplStatus_t SMPL_Init(uint8_t (*f)(linkID_t))
{
  smplStatus_t rc;

  if (!sInit_done)
  {
    /* set up radio. */
    MRFI_Init();

    /* initialize network */
    if ((rc=nwk_nwkInit(f)) != SMPL_SUCCESS)
    {
      return rc;
    }

    MRFI_WakeUp();
#if defined( FREQUENCY_AGILITY )
    {
      freqEntry_t chan;

      chan.logicalChan = 0;
      /* ok to set default channel explicitly now that MRFI initialized. */
      nwk_setChannel(&chan);
    }
#endif
    /* don't turn Rx on if we're an end device that isn't always on. */
    /* but do turn the radio on for PLL operations */
#if !defined( END_DEVICE ) || defined( NWK_PLL )
    MRFI_RxOn();
#endif

#if defined( END_DEVICE )
    /* All except End Devices are in promiscuous mode */
    MRFI_SetRxAddrFilter((uint8_t *)nwk_getMyAddress());
    MRFI_EnableRxAddrFilter();
#endif
  }
  sInit_done = 1;

#ifdef NWK_PLL
  /* If the PLL is enabled then it must get running before the join
   * request or the system may lock up in the join request becuase
   * PLL is not locked in.
   */
  // turn on the PLL
  SMPL_Ioctl(IOCTL_OBJ_PLL, IOCTL_ACT_ON, NULL);
  // reference clocks are by definition always locked.
  #ifndef NWK_PLL_REFERENCE_CLOCK
    // wait for a 5ms failure rate to be achieved
    while( nwk_pllIsLocked( 0 ) == false )
      nwk_pllBackgrounder( false );
  #endif
#endif

  /* Join. if no AP or Join fails that status is returned. */
  rc = nwk_join();

  return rc;
}
int main(void)
{
  WDTCTL = WDTPW + WDTHOLD;            // stop watchdog timer
  BSP_Init();
  MRFI_Init();
  MCU_Init(30000);                     //30000 is dummy large number
  MRFI_WakeUp();                       //start radio in idle state
  MRFI_RxOn();                         //put radio in Rx
  __bis_SR_register(LPM3_bits + GIE);
}
int main(void)
{
  BSP_Init();
  P1REN |= 0x04;
  P1IE |= 0x04;
  MRFI_Init();
  P3SEL    |= 0x30;     // P3.4,5 = USCI_A0 TXD/RXD
  UCA0CTL1  = UCSSEL_2; // SMCLK
  UCA0BR0   = 0x41;     // 9600 from 8Mhz
  UCA0BR1   = 0x3;
  UCA0MCTL  = UCBRS_2;                     
  UCA0CTL1 &= ~UCSWRST; // Initialize USCI state machine
  IE2      |= UCA0RXIE; // Enable USCI_A0 RX interrupt
  BCSCTL3 |= LFXT1S_2; TACTL=MC_0; TACCTL0=0; TACCR0=1060;  //slow timeout
  TBCTL=MC_0; TBCCTL0=0; TBCCR0=31781;                      //fast timeout
  start_slow_timeout();
  __bis_SR_register(GIE+LPM3_bits);
}
int main(void)
{
  //int8_t rssi;
  //uint8_t channel;
  BSP_Init();
  MRFI_Init(/*0x9D, 0x58, 0x5C*/);
  P3SEL    |= 0x30;
  UCA0CTL1  = UCSSEL_2;
  UCA0BR0   = 0x41;
  UCA0BR1   = 0x3;
  UCA0MCTL  = UCBRS_2;
  UCA0CTL1 &= ~UCSWRST;
  MRFI_WakeUp();
  __bis_SR_register(GIE);
  while(1) {
    
    //change to 1th range of base frq
    SetBaseFrequencyRegisters(1);
    ReadChannelsAndSendRSSI();
    
    SetBaseFrequencyRegisters(2);
    ReadChannelsAndSendRSSI();
    
    SetBaseFrequencyRegisters(3);
    ReadChannelsAndSendRSSI();
    
    SetBaseFrequencyRegisters(4);
    ReadChannelsAndSendRSSI();
    
    SetBaseFrequencyRegisters(5);
    ReadChannelsAndSendRSSI();
    
    SetBaseFrequencyRegisters(6);
    ReadChannelsAndSendRSSI();
    
    SetBaseFrequencyRegisters(7);
    ReadChannelsAndSendRSSI();
    
    SetBaseFrequencyRegisters(8);
    ReadChannelsAndSendRSSI();
    
    TXString("\n",1);
  }
}
Example #8
0
/***********************************************************************************
 * @fn          SMPL_Init
 *
 * @brief       Initialize the SimpliciTI stack.
 *
 * input parameters
 * @param   f  - Pointer to call back function. Function called by NWK when
 *               user application frame received. The callback is done in the
 *               ISR thread. Argument is Link ID associated with frame. Function
 *               returns 0 if frame is to be kept by NWK, otherwise 1. Frame
 *               should be kept if application will do a SMPL_Receive() in the
 *               user thread (recommended). Pointer may be NULL.
 *
 * output parameters
 *
 * @return   Status of operation:
 *             SMPL_SUCCESS
 *             SMPL_NO_JOIN     No Join reply. AP possibly not yet up.
 *             SMPL_NO_CHANNEL  Only if Frequency Agility enabled. Channel scan
 *                              failed. AP possibly not yet up.
 */
smplStatus_t SMPL_Init(uint8_t (*f)(linkID_t))
{
  smplStatus_t rc;

  if (!sInit_done)
  {
    /* set up radio. */
    MRFI_Init();

    /* initialize network */
    if ((rc=nwk_nwkInit(f)) != SMPL_SUCCESS)
    {
      return rc;
    }

    MRFI_WakeUp();
#if defined( FREQUENCY_AGILITY )
    {
      freqEntry_t chan;

      chan.logicalChan = 0;
      /* ok to set default channel explicitly now that MRFI initialized. */
      nwk_setChannel(&chan);
    }
#endif
    /* don't turn Rx on if we're an end device that isn't always on. */
#if !defined( END_DEVICE )
    MRFI_RxOn();
#endif

#if defined( END_DEVICE )
    /* All except End Devices are in promiscuous mode */
    MRFI_SetRxAddrFilter((uint8_t *)nwk_getMyAddress());
    MRFI_EnableRxAddrFilter();
#endif
  }
  sInit_done = 1;

  /* Join. if no AP or Join fails that status is returned. */
  rc = nwk_join();

  return rc;
}
Example #9
0
/**
 * swInit
 *
 * Initialize SWAP comms
 */
void swInit(void)
{
  // Setup radio
  MRFI_Init();

  // Set default configuration parameters?
  if (loadDefaultParams)
  {
    swSetDefaultConfigParams();
    loadDefaultParams = false;
  }
  // Or the current ones?
  else
    swSetCurrentConfigParams();

  // Initialize global variables
  memset(glblDataArray, 0, sizeof(glblDataArray));
  glblSwapData.data = glblDataArray;
  glblSwapData.length = 0;
  
  // Start comms
  swStart();
}
Example #10
0
/******************************************************************************
* @fn         mrfiLinkInit
*
* @brief      Initialise the MRFI layer. Selects RF channel and addresses.
*
* @param      src - source address (16 bit)
*
* @param      dst - destination address (16 bit)
*
* @return     void
*
*/
void mrfiLinkInit(uint16 src, uint16 dst, uint8 mrfiChannel)
{
#ifdef USB_SUSPEND_HOOKS
    // Register USB hooks if necessary
    pFnSuspendEnterHook= MRFI_Sleep;
    pFnSuspendExitHook= linkRestore;
#endif

    // Make sure the timer is initialised
    BSP_INIT_BOARD();

    // Initialise the addresses
    src_addr[0]=  LO_UINT16(MRFI_LINK_PAN_ID);
    src_addr[1]=  HI_UINT16(MRFI_LINK_PAN_ID);
    src_addr[2]=  LO_UINT16(src);
    src_addr[3]=  HI_UINT16(src);

    dest_addr[0]= LO_UINT16(MRFI_LINK_PAN_ID);
    dest_addr[1]= HI_UINT16(MRFI_LINK_PAN_ID);
    dest_addr[2]= LO_UINT16(dst);
    dest_addr[3]= HI_UINT16(dst);

    // Initialise MRFI link housekeeping data
    mrfiPktRdy= FALSE;
    fAckRdy= FALSE;
    seqSend= 0;
    seqRecv= 0;

    // Initialise MRFI
    MRFI_Init();
    MRFI_WakeUp();
    MRFI_SetLogicalChannel(mrfiChannel);
    MRFI_RxOn();
    MRFI_SetRxAddrFilter(src_addr);
    MRFI_EnableRxAddrFilter();

}
Example #11
0
/*------------------------------------------------------------------------------
 * Main
 *----------------------------------------------------------------------------*/
void main ( void ) {
  uint8_t tx_cmd;
  uint8_t tx_data;

  /* Initialize board devices */
  BSP_Init();
  MRFI_Init();

  /* Setup I/O */
  P1DIR |= (LED_RED+LED_GREEN);        // Enable LEDs  
  P1DIR &= ~PUSH_BUTTON;               // Enable push button  
  P1REN |= PUSH_BUTTON;                // Enable pull-up/down resistor
  P1IE |= PUSH_BUTTON;                 // Enable interrupt  
  P2DIR &= ~(TRIGGER_L2H+TRIGGER_H2L+MODE_SELECT); // Enable inputs
  P2IE |= (TRIGGER_L2H+TRIGGER_H2L);   // Enable interrupts
  P2IES &= ~TRIGGER_L2H;               // Set rising edge select
  P2IES |= TRIGGER_H2L;                // Set falling edge select

  /* Setup Timer A */
  BCSCTL3 |= LFXT1S_2;   // Source VLO @ 12kHz
  TACCTL0 = CCIE;        // Enable TimerA interrupt
  TACCR0 = 12000;        // ~1Hz
  TACTL = MC_1+TASSEL_1; // Count up + ACLK
  
  /* Initialize device settings */
  NODE1 |= LINK_MODE;

  /* Signal boot complete */  
  P1OUT |= (LED_RED+LED_GREEN);
  
  /* Enter main loop */
  while(1) {    
    __bis_SR_register(GIE+LPM3_bits);
    
    if (NODE1&MEASURE_VCC) {      
      volatile long temp;
      
      P1OUT |= LED_GREEN;
      
      ADC10CTL1 = INCH_11; 
      ADC10CTL0 = SREF_1 + ADC10SHT_2 + REFON + ADC10ON + ADC10IE + REF2_5V;
      __delay_cycles(240);
      ADC10CTL0 |= ENC + ADC10SC;
      __bis_SR_register(CPUOFF+GIE);
      temp = ADC10MEM;
      tx_cmd = NODE_ALIVE;
      tx_data = (temp*25)/512;
      ADC10CTL0 &= ~ENC;
      ADC10CTL0 &= ~(REFON + ADC10ON);     
      NODE1 &= ~MEASURE_VCC;
      NODE1 |= (WAKE_RADIO+BROADCAST);
      TACCTL0 |= CCIE;

      P1OUT &= ~LED_GREEN;
    }
    
    if (NODE1&LINK_MODE) {      
      P1OUT ^= (LED_RED+LED_GREEN);
      tx_cmd = NEW_NODE;
      NODE1 |= (WAKE_RADIO+BROADCAST);      
    } else {
      if (NODE1&STATE_CHANGED) {
        if (NODE1&ALARMED) {
          P1OUT |= LED_RED;
          tx_cmd = ALARMED_NODE;
        } else {
          P1OUT &= ~LED_RED;
          tx_cmd = RESET_NODE;
        }
        NODE1 |= (WAKE_RADIO+BROADCAST);
      } else {
        if (NODE1&ALARMED) {
          P1OUT ^= LED_RED;
        } else {
          P1OUT &= ~LED_RED;
        }
      }
    }
    
    if (NODE1&WAKE_RADIO) {
      MRFI_WakeUp();
      MRFI_RxOn();
    }

    if (NODE1&BROADCAST) {  
      mrfiPacket_t tx_packet;
      
      tx_packet.frame[0] = 8+20;
      tx_packet.frame[SRC_ADDR] = my_addr;
      tx_packet.frame[DST_ADDR] = 0x00;  
      tx_packet.frame[CMD] = tx_cmd;
      tx_packet.frame[DATA] = tx_data;
      MRFI_Transmit(&tx_packet, MRFI_TX_TYPE_FORCED);
      
      NODE1 &= ~BROADCAST;
    }
    
    if (!(NODE1&WAKE_RADIO)) {
      MRFI_Sleep();
    }  
  }
}
//Main Execution of the program
main()
{
	int temp;
	int DegK;
	int light;
	int humidity;
	char c[4];
	
	
	mrfiPacket_t 	packet;
	unsigned char msg[9];
	
	BSP_Init();
	
	MRFI_Init();
	MRFI_WakeUp();
	
	//Disable Watchdog Timer
	WDTCTL = WDTPW + WDTHOLD;
	
	//Red LED P1.1
	P1DIR |= 0x01;
	P1OUT |= 0x00;
	
	//Analog Input Setup
	//P1.1 = A10 = Internal	= Temperature Sensor
	//P2.2 = A2  = Pin 5 	= Light Sensor
	//P2.3 = A3  = Pin 6 	= Humidity Sensor
	P1DIR &= ~0x02;	//P1.1 is Input
	P2DIR &= ~0x0C; //P2.2 & P2.3 are Inputs
	
	//Global Interrupt Enable
	__bis_SR_register(GIE);
	
	//Read Analog Sensors Forever!
	while(1)
	{
		//Read Light Sensor
		light = analogRead(2);
		light = (int) (light/1023.0*100.0);
		sleep(60000);
		//Read Humidity Sensor
		humidity = analogRead(3);
		humidity = (int) (((((humidity/1023.0)*2.5)-.45)*100.0)/1.5); //Derived from Datasheet Info
		sleep(60000);
		//ReadTemperature
		temp = analogRead(10); 
	    DegK = (int) (((temp - 673.0) * 423.0) / 1023.0) + 273.0;
	
		//Make all values into 3 digit strings.
		itoa(light, c, 999);
		if (light < 10)
		{
			msg[0] = '0';
			msg[1] = '0';
			msg[2] = c[0];
		}
		else if (light < 100)
		{
			msg[0] = '0';
			msg[1] = c[0];
			msg[2] = c[1];
		}
		else
		{
			msg[0] = c[0];
			msg[1] = c[1];
			msg[2] = c[2];
		}
		
		itoa(humidity, c, 999);
		if (humidity < 10)
		{
			msg[3] = '0';
			msg[4] = '0';
			msg[5] = c[0];
		}
		else if (humidity < 100)
		{
			msg[3] = '0';
			msg[4] = c[0];
			msg[5] = c[1];
		}
		else
		{
			msg[3] = c[0];
			msg[4] = c[1];
			msg[5] = c[2];
		}
		
		itoa(DegK, c, 999);
		if (DegK < 10)
		{
			msg[6] = '0';
			msg[7] = '0';
			msg[8] = c[0];
		}
		else if (DegK < 100)
		{
			msg[6] = '0';
			msg[7] = c[0];
			msg[8] = c[1];
		}
		else
		{
			msg[6] = c[0];
			msg[7] = c[1];
			msg[8] = c[2];
		}
		
		//Copy message into the packet.
		strcpy( &packet.frame[9] , msg );
		
		/** Enter source and destination addresses  **/
		//Source address here is useless, as this is a send-only application.
		memset( &packet.frame[1], 0x20, 4);
		memset( &packet.frame[5], 0x10, 4);
		
		// Enter length of packet.
		packet.frame[0] = 8 + strlen(msg); // 8-byte header, 20-byte payload.
		
		//Transmit 
		MRFI_Transmit(&packet , MRFI_TX_TYPE_FORCED);
		
		//Toggle led.
		P1OUT ^= RED_SEND_LED;
		
		//sleep.
		sleep(60000);
		sleep(60000);
		sleep(60000);
		sleep(60000);
		sleep(60000);
	}
	
}