示例#1
0
int main()
{
	uint8_t addr[5];
	uint8_t buf[32];

	WDTCTL = WDTHOLD | WDTPW;
	DCOCTL = CALDCO_16MHZ;
	BCSCTL1 = CALBC1_16MHZ;
	BCSCTL2 = DIVS_2;  // SMCLK = DCOCLK/4
	// SPI (USCI) uses SMCLK, prefer SMCLK < 10MHz (SPI speed limit for nRF24 = 10MHz)
	user = 0xFE;

	// Red LED will be our output
	P1DIR |= BIT0;
	P1OUT &= ~BIT0;

	/* Initial values for nRF24L01+ library config variables */
	rf_crc = RF24_EN_CRC; // CRC enabled, 8-bit
	rf_addr_width      = 5;
	rf_speed_power     = RF24_SPEED_MIN | RF24_POWER_MAX;
	rf_channel         = 120;
	msprf24_init();
	msprf24_set_pipe_packetsize(0, 0);
	msprf24_open_pipe(0, 1);  // Open pipe#0 with Enhanced ShockBurst

	// Set our RX address
	memcpy(addr, "\xDE\xAD\xBE\xEF\x01", 5);
	w_rx_addr(0, addr);

	// Receive mode
	if (!(RF24_QUEUE_RXEMPTY & msprf24_queue_state())) {
		flush_rx();
	}
	msprf24_activate_rx();
	LPM4;

	while (1) {
		if (rf_irq & RF24_IRQ_FLAGGED) {
			msprf24_get_irq_reason();
		}
		if (rf_irq & RF24_IRQ_RX || msprf24_rx_pending()) {
			r_rx_payload(r_rx_peek_payload_size(), buf);
			msprf24_irq_clear(RF24_IRQ_RX);
			user = buf[0];

			if (buf[0] == '0')
				P1OUT &= ~BIT0;
			if (buf[0] == '1')
				P1OUT |= BIT0;

		} else {
			user = 0xFF;
		}
		LPM4;
	}
	return 0;
}
示例#2
0
int main()
{
	uint8_t pktlen, pipeid;
	uint8_t rfbuf[32];

	WDTCTL = WDTPW | WDTHOLD;
	DCOCTL = CALDCO_16MHZ;
	BCSCTL1 = CALBC1_16MHZ;
	BCSCTL2 = DIVS_2;  // SMCLK = 8MHz

	// Initialize red LED
	P1DIR |= BIT6;
	P1OUT &= ~BIT6;

	// Initialize nRF24L01+ RF transceiver
	rf_crc = RF24_EN_CRC;
	rf_addr_width = 5;
	rf_speed_power = RF24_SPEED_MIN | RF24_POWER_MAX;
	rf_channel = 8;
	msprf24_init();
	msprf24_open_pipe(1, 1);  // Receive pipe#1 (could use #0 too, as we don't do any TX...)
	msprf24_set_pipe_packetsize(1, 0);  // Dynamic payload support

	w_rx_addr(1, (uint8_t*)ouraddr);
	msprf24_activate_rx();  // Start listening
	// Main loop
	while (1) {
		// Handle incoming nRF24 IRQs
		if (rf_irq & RF24_IRQ_FLAGGED) {
			msprf24_get_irq_reason();

			if (rf_irq & RF24_IRQ_RX || msprf24_rx_pending()) {
				pktlen = r_rx_peek_payload_size();
				if (!pktlen || pktlen > 32) {  /* Erroneous >32byte packets need to be flushed right away
							        * I have actually seen these occur, even with CRC enabled, and it 
							        * logjams the FIFOs because r_rx_payload() can't read them...
							        */
					flush_rx();
					msprf24_irq_clear(RF24_IRQ_RX);
				} else {
					pipeid = r_rx_payload(pktlen, rfbuf);
					msprf24_irq_clear(RF24_IRQ_RX);
					if (pipeid == 1) {  // Only paying attention to pipe#1 (this should always eval true)
						if (!memcmp(rfbuf, rfpayload, 3))  // Valid pushbutton packet
							P1OUT ^= BIT6;             // Toggle red LED
					}
				}
			}
		}

		LPM4;
	}
}
示例#3
0
int main() {
  uint8_t buf[32];

  WDTCTL = WDTPW | WDTHOLD;
  DCOCTL = 0;
  BCSCTL1 = CALBC1_16MHZ;
  DCOCTL = CALDCO_16MHZ;
  BCSCTL3 |= LFXT1S_2;

  P1DIR |= BIT0;
  P1OUT &= ~BIT0;

  _BIS_SR(GIE);
#ifdef UART_DEBUG
  uart_setup();
#endif
  radio_setup();

  // flush RX just in case
  if (!(RF24_RX_EMPTY & msprf24_queue_state())) {
    flush_rx();
  }
  msprf24_activate_rx();
  LPM4;

  while (1) {
    if (rf_irq & RF24_IRQ_FLAGGED) {
      rf_irq &= ~RF24_IRQ_FLAGGED;
      msprf24_get_irq_reason();
    }
    if (rf_irq & RF24_IRQ_RX || msprf24_rx_pending()) {
      uint8_t nextPayloadSize = r_rx_peek_payload_size();
      r_rx_payload(nextPayloadSize, buf);
      msprf24_irq_clear(RF24_IRQ_MASK);
      memcpy(dht_data.bytes, buf, nextPayloadSize);
#ifdef UART_DEBUG
      int t = (((dht_data.val.th&0x7f)<<8) + dht_data.val.tl)*((dht_data.val.th&0x80)?-1:1);
      int h = (dht_data.val.hh<<8) + (dht_data.val.hl);
      uart_send(sprintf(txbuf, "%d.%1d;%d.%1d\r\n", t/10, t%10, h/10, h%10));
#endif
    }
    LPM4;
  }

  return 0;
}
示例#4
0
//-----------------------------------------------------------------------
int RF_Init(void)
{
	int err = 0;

	//Setting RGB LED as output
	MAP_GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2);
	MAP_GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0);
	GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2);
	GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0);

	//Set P6.1 to be the pin interupt
	MAP_GPIO_setAsInputPin(GPIO_PORT_P6, GPIO_PIN1);
	MAP_GPIO_clearInterruptFlag(GPIO_PORT_P6, GPIO_PIN1);
	MAP_GPIO_enableInterrupt(GPIO_PORT_P6, GPIO_PIN1);

	//Enable the gpio interupt
	MAP_Interrupt_enableInterrupt(INT_PORT6);
	MAP_Interrupt_enableMaster();

    /* Initial values for nRF24L01+ library config variables */
    rf_crc = RF24_EN_CRC | RF24_CRCO; // CRC enabled, 16-bit
    rf_addr_width      = (uint8_t)PACKET_SIZE;
    rf_speed_power     = RF24_SPEED_MIN | RF24_POWER_MAX;
    rf_channel     	   = 120;

    msprf24_init();  // All RX pipes closed by default
    msprf24_set_pipe_packetsize(0, (uint8_t)PACKET_SIZE);
    msprf24_open_pipe(0, 1);  // Open pipe#0 with Enhanced ShockBurst enabled for receiving Auto-ACKs

    // Transmit to 'rad01' (0x72 0x61 0x64 0x30 0x31)
    msprf24_standby();
    user = msprf24_current_state();
    memcpy(addr, "\xDE\xAD\xBE\xEF\x01", 5);
//    addr[0] = 0xDE; addr[1] = 0xAD; addr[2] = 0xBE; addr[3] = 0xEF; addr[4] = 0x00;
    w_tx_addr(addr);
    w_rx_addr(0, addr);  // Pipe 0 receives auto-ack's, autoacks are sent back to the TX addr so the PTX node
                     // needs to listen to the TX addr on pipe#0 to receive them.
    msprf24_activate_rx();

	return err;
}