Пример #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;
}
int main()
{
	uint8_t addr[5];
	uint8_t buf[32];

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

	// Red, Green LED used for status
	P1DIR |= 0x41;
	P1OUT &= ~0x41;

	user = 0xFE;

	/* Initial values for nRF24L01+ library config variables */
	rf_crc = RF24_EN_CRC; // CRC enabled, 16-bit
	rf_addr_width      = 5;
	rf_speed_power     = RF24_SPEED_MIN | RF24_POWER_MIN;
	rf_channel         = 120;
	msprf24_init();  // All RX pipes closed by default
	msprf24_set_pipe_packetsize(0, 32);
	msprf24_open_pipe(0, 1);  // Open pipe#0 with Enhanced ShockBurst enabled for receiving Auto-ACKs
	// Note: Pipe#0 is hardcoded in the transceiver hardware as the designated "pipe" for a TX node to receive
	// auto-ACKs.  This does not have to match the pipe# used on the RX side.

	// Transmit to 'rad01' (0x72 0x61 0x64 0x30 0x31)
	msprf24_standby();
	user = msprf24_current_state();
	//addr[0] = 'r'; addr[1] = 'a'; addr[2] = 'd'; addr[3] = '0'; addr[4] = '1';
    memcpy(addr, "\xDE\xAD\xBE\xEF\x01", 5);
	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.
	buf[0] = '1';
	buf[1] = '\0';
	w_tx_payload(32, buf);
	msprf24_activate_tx();
	LPM4;

	if (rf_irq & RF24_IRQ_FLAGGED) {
		msprf24_get_irq_reason();
		if (rf_irq & RF24_IRQ_TX)
			P1OUT |= 0x40;  // Green LED
		if (rf_irq & RF24_IRQ_TXFAILED)
			P1OUT |= 0x01;  // Red LED

		msprf24_irq_clear(rf_irq);
		user = msprf24_get_last_retransmits();
	}
	return 0;
}
Пример #3
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;
	}
}
Пример #4
0
void main()
{
        char addr[5];
        char buf[32];
        char status;

        WDTCTL = WDTHOLD | WDTPW;
        DCOCTL = CALDCO_1MHZ;
        BCSCTL1 = CALBC1_1MHZ;
        BCSCTL2 = DIVS_0;  // SMCLK = DCOCLK/1
        // SPI (USI) uses SMCLK, prefer SMCLK=DCO (no clock division)

        /* Initial values for nRF24L01+ library config variables */
        rf_crc = RF24_EN_CRC | RF24_CRCO; // CRC enabled, 16-bit
        rf_addr_width      = 5;
        rf_speed_power     = RF24_SPEED_MIN | RF24_POWER_MAX;
        rf_channel         = 0x4c;
        msprf24_init();  // All RX pipes closed by default
        msprf24_open_pipe(0, 1);  // Open pipe#0 with Enhanced ShockBurst enabled for receiving Auto-ACKs
        msprf24_set_pipe_packetsize(0, 0);  // Dynamic payload length enabled (size=0)

        // Transmit to 'rad01' (0x72 0x61 0x64 0x30 0x31)
        msprf24_standby();
        addr[0] = 'r'; addr[1] = 'a'; addr[2] = 'd'; addr[3] = '0'; addr[4] = '1';
        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.
        buf[0] = '1';
        buf[1] = '2';
        buf[2] = '3';
        buf[3] = '\0';
        w_tx_payload(4, buf);
        msprf24_activate_tx();
        LPM4;

        if (rf_irq & RF24_IRQ_FLAGGED) {
                msprf24_get_irq_reason();  // this updates rf_irq
                if (rf_irq & RF24_IRQ_TX)
                        status = 1;
                if (rf_irq & RF24_IRQ_TXFAILED)
                        status = 0;
                msprf24_irq_clear(RF24_IRQ_MASK);  // Clear any/all of them
        }

        status += 1;
        // Do something cool with the 'status' variable
        // ???
        // Profit!
        // Go to sleep forever:
        _DINT();
        LPM4;
}
Пример #5
0
void radio_setup() {
  uint8_t addr[] = {0xDE, 0xAD, 0x00, 0xBE, 0xEF};
  rf_crc = RF24_EN_CRC | RF24_CRCO;
  rf_addr_width = 5;
  rf_speed_power = RF24_SPEED_250KBPS | RF24_POWER_0DBM;
  rf_channel = 120;
  // Initialize and such
  msprf24_init();
  msprf24_set_pipe_packetsize(0, 0);
  msprf24_open_pipe(0, 1);
  // Wake up from deep sleep (if...)
  msprf24_standby();
  // Set TX and RX addresses (AutoACKs are sent to the TX address)
  w_tx_addr(addr);
  w_rx_addr(0, addr);
}
Пример #6
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;
}
Пример #7
0
void main()
{
	char addr[4];
	char buf[32];

	WDTCTL = WDTHOLD | WDTPW;
	DCOCTL = CALDCO_1MHZ;
	BCSCTL1 = CALBC1_1MHZ;
	BCSCTL2 = DIVS_0;  // SMCLK = DCOCLK/1
	// SPI (USI) uses SMCLK, prefer SMCLK=DCO (no clock division)
	user = 0xFE;

	/* Initial values for nRF24L01+ library config variables */
	rf_crc = RF24_EN_CRC | RF24_CRCO; // CRC enabled, 16-bit
	rf_addr_width      = 4;
	rf_speed_power     = RF24_SPEED_MIN | RF24_POWER_MIN;
	rf_channel         = 119;
	msprf24_init();
	msprf24_set_pipe_packetsize(0, 15);
	msprf24_open_pipe(0, 1);  // Open pipe#0 with Enhanced ShockBurst for receiving Auto-ACKs

	// Transmit to 0xBEEFBEEF
	msprf24_standby();
	user = msprf24_current_state();
	addr[0] = 0xBE; addr[1] = 0xEF; addr[2] = 0xBE; addr[3] = 0xEF;
	w_tx_addr(addr);
	w_rx_addr(0, addr);  // Pipe#0 receives auto-ack's
	buf[0] = '0';
	buf[1] = '\0';
	w_tx_payload(15, buf);
	msprf24_activate_tx();
	LPM4;

	if (rf_irq & RF24_IRQ_FLAGGED) {
		user = ~(msprf24_get_irq_reason());
	}
}
Пример #8
0
void main()
{
	uint8_t addr[5];
	uint8_t buf[32];

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

	// Red, Green LED used for status
	P1DIR |= 0x41;
	P1OUT &= ~0x41;

	user = 0xFE;

	/* Initial values for nRF24L01+ library config variables */
	rf_crc = RF24_EN_CRC | RF24_CRCO; // CRC enabled, 16-bit
	rf_addr_width      = 5;
	rf_speed_power     = RF24_SPEED_1MBPS | RF24_POWER_0DBM;
	rf_channel         = 120;

	msprf24_init();  // All RX pipes closed by default
	msprf24_set_pipe_packetsize(0, 32);
	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();
	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.

	while(1){
		__delay_cycles(800000);
		if(buf[0]=='0'){buf[0] = '1';buf[1] = '0';}
		else {buf[0] = '0';buf[1] = '1';}
		w_tx_payload(32, buf);
		msprf24_activate_tx();
		LPM4;

		if (rf_irq & RF24_IRQ_FLAGGED) {
			rf_irq &= ~RF24_IRQ_FLAGGED;

			msprf24_get_irq_reason();
			if (rf_irq & RF24_IRQ_TX){
				P1OUT &= ~BIT0; // Red LED off
				P1OUT |= 0x40;  // Green LED on
			}
			if (rf_irq & RF24_IRQ_TXFAILED){
				P1OUT &= ~BIT6; // Green LED off
				P1OUT |= BIT0;  // Red LED on
			}

			msprf24_irq_clear(rf_irq);
			user = msprf24_get_last_retransmits();
		}
	}
}
Пример #9
0
int main()
{
    uint8_t addr[5];
    uint8_t buf[32];

    WDTCTL = WDTHOLD | WDTPW;
    //DCOCTL = CALDCO_16MHZ;
    //BCSCTL1 = CALBC1_16MHZ;
    DCOCTL = CALDCO_1MHZ;
    BCSCTL1 = CALBC1_1MHZ;
    BCSCTL2 = DIVS_0;  // SMCLK = DCOCLK/1
        BCSCTL3 = LFXT1S_2;  // ACLK = VLOCLK/1
        BCSCTL3 &= ~(XT2OF|LFXT1OF);


    //init the ADC
    //ADC_init();
    Temp_ADC_init();
    freq_timerA_init();//init freq timer stuff

//stuff for cal
const unsigned * const info_seg_a = (unsigned *)0x10C0;     // Address of info segement A
//const unsigned * const info_seg_a = (unsigned *)0x10DA;     // Address of info segement A
    const unsigned * const info_seg_a_end = info_seg_a + 32;    // 32 words in each segment
    

const TCAL * const cal = (TCAL *)(verify_info_chk(info_seg_a, info_seg_a_end) \
         ? 0 \
         : find_tag(info_seg_a, info_seg_a_end, 0x08));
    const long cc_scale  = cal ? 3604480L / (cal->t8515 - cal->t3015) : 0;
    const long cf_scale  = cal ? 6488064L / (cal->t8515 - cal->t3015) : 0;
    const long cc_offset = cal ? 1998848L - (cal->t3015 * cc_scale) : 0;
    const long cf_offset = cal ? 5668864L - (cal->t3015 * cf_scale) : 0;
    const long ck_offset = cc_offset + 17901158L;


    wdtsleep = 0;

    // SPI (USI) uses SMCLK, prefer SMCLK=DCO (no clock division)
    user = 0xFE;

    /* Initial values for nRF24L01+ library config variables */
    rf_crc = RF24_EN_CRC; // CRC enabled, 8-bit
    //| RF24_CRCO;
    rf_addr_width      = 5;
    //rf_speed_power     = RF24_SPEED_1MBPS | RF24_POWER_MAX;
    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, 0);
    msprf24_open_pipe(0, 1);  // Open pipe#0 with Enhanced ShockBurst enabled for receiving Auto-ACKs
    // Note: Pipe#0 is hardcoded in the transceiver hardware as the designated "pipe" for a TX node to receive
    // auto-ACKs.  This does not have to match the pipe# used on the RX side.

    // Transmit to 0xDEADBEEF00
    msprf24_standby();
    user = msprf24_current_state();
    //addr[0] = 'r'; addr[1] = 'a'; addr[2] = 'd'; addr[3] = '0'; addr[4] = '1';
    memcpy(addr, "\xDE\xAD\xBE\xEF\x00", 5);
    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.
    buf[0] = '0';
    //buf[1]='\0';
    buf[2] = '\0';
    buf[4] = '\0';
    while(1) {
        if (rf_irq & RF24_IRQ_FLAGGED) {  // Just acknowledging previous packet here
            msprf24_get_irq_reason();
            msprf24_irq_clear(RF24_IRQ_MASK);
            user = msprf24_get_last_retransmits();
        } else {  // WDT sleep completed, send a new packet
            //if (buf[0] == '1')
            //	buf[0] = '0';
            //else
            //	buf[0] = '1';

            //buf[] = snprintf(buf,32,"%d",ADC_read());
            adc_val = ADC_read();
            
            //adc_val = 1023;
            //buf[0] = (uint8_t)(adc_val>>8);//get high byte
            //buf[1] = (uint8_t)(adc_val);//low byte
            //buf[0]=(uint8_t)(adc_val>>2);//8 bits?
            
            //F
            //buf[1]= ((48724L * adc_val) -  30634388L) >> 16;
            buf[0]=((cf_scale * adc_val) + cf_offset) >> 16; //calibrated
            
            //celsius
            //buf[1]=((27069L * adc_val) -  18169625L) >> 16; 
                //calibrated
                buf[1]= ((cc_scale * adc_val) + cc_offset) >> 16;
            
            //uint16_t tempfreq;
            uint32_t tempfreq;
            //tempfreq = (uint16_t)read_frequency();
            tempfreq = read_frequency();
            //tempfreq = (uint16_t)read_avg_freq(6);
            //tempfreq = (uint16_t)read_avg_freq(6);
            buf[2]= (uint8_t)tempfreq; //get low byte
            buf[3]= (uint8_t)(tempfreq>>8);//get high byte
            tempfreq = read_avg_freq(6);
            buf[4]= (uint8_t)tempfreq; //get low byte
            buf[5]= (uint8_t)(tempfreq>>8);//get high byte
            
            w_tx_payload(32, buf);
            msprf24_activate_tx();
        }

        wdt_sleep(10);  //
    }
    return 0;
}
int main()
{
	uint8_t addr[5];
	uint8_t buf[32];

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

	// Red, Green LED used for status
	//P1DIR |= 0x41;
	//P1OUT &= ~0x41;

        BCSCTL3 = LFXT1S_2;  // ACLK = VLOCLK/1
        BCSCTL3 &= ~(XT2OF|LFXT1OF);

	wdtsleep = 0;
    
    setup_button();
    
	user = 0xFE;

	/* 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();  // All RX pipes closed by default
	msprf24_set_pipe_packetsize(0, 0);//dynamic packet size
	msprf24_open_pipe(0, 1);  // Open pipe#0 with Enhanced ShockBurst enabled for receiving Auto-ACKs
	// Note: Pipe#0 is hardcoded in the transceiver hardware as the designated "pipe" for a TX node to receive
	// auto-ACKs.  This does not have to match the pipe# used on the RX side.

	// Transmit to 'rad01' (0x72 0x61 0x64 0x30 0x31)
	msprf24_standby();
	user = msprf24_current_state();
	//addr[0] = 'r'; addr[1] = 'a'; addr[2] = 'd'; addr[3] = '0'; addr[4] = '1';
    memcpy(addr, "\xDE\xAD\xBE\xEF\x00", 5);
	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.
	buf[0] = '1';
	buf[1] = '\0';
	w_tx_payload(32, buf);
	msprf24_activate_tx();
	//LPM4;
    //LPM3;
    while(1) {
		if (rf_irq & RF24_IRQ_FLAGGED) {  // Just acknowledging previous packet here
			msprf24_get_irq_reason();
			msprf24_irq_clear(RF24_IRQ_MASK);
			user = msprf24_get_last_retransmits();
		} else {  // WDT sleep completed, send a new packet
			/*if (buf[0] == '1')
				buf[0] = '0';
			else
				buf[0] = '1';*/
                
            if((P1IN & BIT3)==0){
                buf[0] = '1';
            }else{
                buf[0] = '0';
            }
			w_tx_payload(2, buf);
			msprf24_activate_tx();
		}

		wdt_sleep(1);  //sleep a bit
	}
    
/*
	if (rf_irq & RF24_IRQ_FLAGGED) {
		msprf24_get_irq_reason();
		if (rf_irq & RF24_IRQ_TX)
			P1OUT |= 0x40;  // Green LED
		if (rf_irq & RF24_IRQ_TXFAILED)
			P1OUT |= 0x01;  // Red LED

		msprf24_irq_clear(rf_irq);
		user = msprf24_get_last_retransmits();
	}*/
    
	return 0;
}
Пример #11
0
int main(){
    uint8_t txretry_count=0, txretry_latch=0;

    WDTCTL = (WDTPW + WDTHOLD);
    DCOCTL = CALDCO_16MHZ;
    BCSCTL1 = CALBC1_16MHZ;
    BCSCTL2 = DIVS_1;  // SMCLK = 8MHz

    // Inicializacao do 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(0, 1);  // This is only for receiving auto-ACK packets.
    msprf24_set_pipe_packetsize(0, 0);  // Dynamic payload support
        // Note: Pipe#0 is hardcoded in the transceiver hardware as the designated "pipe" for a TX node to receive
        // auto-ACKs.  This does not have to match the pipe# used on the RX side.

    Serial_config();

    // Main loop
    while (1) {
        // Handle any nRF24 IRQs first
        if (rf_irq & RF24_IRQ_FLAGGED) {
            msprf24_get_irq_reason();

            if (rf_irq & RF24_IRQ_TX) {
                msprf24_irq_clear(RF24_IRQ_TX);
                flush_tx();
                w_rx_addr(0, (uint8_t*)masterAddr);
                msprf24_powerdown();
            }

            if (rf_irq & RF24_IRQ_TXFAILED) {
                msprf24_irq_clear(RF24_IRQ_TXFAILED);
                if (txretry_count) {
                    txretry_count--;
                    if (!txretry_latch) {
                        txretry_latch = 1;
                        tx_reuse_lastpayload();
                    }
                    pulse_ce();
                } else {
                    // Ran out of retries, give up
                    flush_tx();
                    w_rx_addr(0, (uint8_t*)masterAddr);
                    txretry_latch = 0;
                    msprf24_powerdown();
                }
            }
            // No need to handle RX packets since we never enter RX mode
        }

        if (handle_serial){
            if(serial_data_rcv == START_CHAR){
                pl_index == 0;
            }
            else if(serial_data_rcv == END_CHAR){
                send_pkg = true;
                pl_index == 0;
            }
            else if(pl_index < PL_SIZE){
                rfpayload[pl_index++] = serial_data_rcv;
            }
            else{
                pl_index = 0;
            }

            handle_serial = false;
        }

        if (msprf24_queue_state() & RF24_QUEUE_TXEMPTY && send_pkg) {

            Serial_escreve_texto("\nEnviando pacote: ");
            Serial_escreve_texto(rfpayload);

            msprf24_standby();
            w_tx_addr((uint8_t*)nodeAddr);
            w_rx_addr(0, (uint8_t*)nodeAddr);  // To catch the auto-ACK reply
            w_tx_payload(2, (uint8_t*)rfpayload);
            msprf24_activate_tx();
            txretry_count = 20;  // Try damned hard to send this, retrying up to 20 * ARC times (ARC=15 by default)

            send_pkg = false;
        }

    }
}
Пример #12
0
void main()
{
	int err = 0, count = 0, bytesWritten = 0;
	char addr[5], i = '0';
	char buf[32], data[64];
	uint8_t status;
	uint32_t ACLKfreq;
	BYTE temp[100];
	UINT bw = 0, btw;
	FRESULT iFResult;
	DWORD sizeBuf = 0;

//Initialization Functions
	err = InitFunction();
	err |= ADC_InitFunction();
	err |= I2C_InitFunc(calData);
	err |= InitOneWire();

//Initialize the SD card
	Use_SD_CARD = YES;
	if(SD_CardInit())
	{
		Use_SD_CARD = NO;
	}

	//Initialize the nRF wireless module
	ACLKfreq = MAP_CS_getACLK();  // get ACLK value to verify it was set correctly

	rf_crc = RF24_CRCO;
	rf_addr_width      = (uint8_t)ADDRESS_WIDTH;
	rf_speed_power     = RF24_SPEED_MIN | RF24_POWER_MAX;
	rf_channel         = 120;
	msprf24_init();  // All RX pipes closed by default
	msprf24_open_pipe(0, 1);  // Open pipe#0 with Enhanced ShockBurst enabled for receiving Auto-ACKs
	msprf24_set_pipe_packetsize(0, (uint8_t)ADDRESS_WIDTH);  // Dynamic payload length enabled (size=0)

	// Transmit to 'rad01' (0x72 0x61 0x64 0x30 0x31)
	msprf24_standby();
	memcpy(addr, "\xDE\xAD\xBE\xEF\x01", 5);
//	addr[0] = 'r'; addr[1] = 'a'; addr[2] = 'd'; addr[3] = '0'; addr[4] = '2';
	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.
	buf[0] = '1';
	buf[1] = '\0';
//	w_tx_payload(1, buf);
	w_tx_payload_noack(1, buf);
	msprf24_activate_tx();

	if (rf_irq & RF24_IRQ_FLAGGED)
	{
			msprf24_get_irq_reason();  // this updates rf_irq
			if (rf_irq & RF24_IRQ_TX)
					status = 1;
			if (rf_irq & RF24_IRQ_TXFAILED)
					status = 0;
			msprf24_irq_clear(RF24_IRQ_MASK);  // Clear any/all of them
	}
	memset(buf, 0, sizeof(buf));

	MAP_Interrupt_enableMaster();
//	MAP_Interrupt_setPriority(INT_TA0_0, 0x00);

	//Entering the main loop
	while(1)
	{
		while(Refresh == 0)
		{	//Keep the process locked here until 'Refresh' is set high.
		}
		MAP_ADC14_toggleConversionTrigger();
		Refresh = 0;

		//Get light value
	    GetLightValue(&lux, &lightIndex);

	    //Get temperature and pressure
	    GetBaroTemp(calData, &temperature, &pressure);

	    //Get temperature and humidity
	    __delay_cycles(100);
	    dht_start_read();
	    int t = dht_get_temp();
	    int h = dht_get_rh();
		__delay_cycles(100);

		//For debug purposes
		printf("Temperature: %d\n", temperature);
		printf("Pressure: %d\n", pressure);
		printf("Lux: %d\n", lux);
		printf("Humidity: %d\n", h);

		//Form the string to send to base station
		sprintf(buf, "<T%003dP%000006dH%003dL%00005d>", temperature, pressure, h, lux);

		//transmit data
		GPIO_setOutputHighOnPin(GPIO_PORT_P1, GPIO_PIN0);
		w_tx_payload((uint8_t)ADDRESS_WIDTH, buf);
		msprf24_activate_tx();
		GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0);

		//open SD card
		if(Use_SD_CARD == YES)
		{
			iFResult = f_open(&g_sFileObject, "data.txt", FA_OPEN_EXISTING | FA_WRITE);
			count = 0;
			//if the first open fails, unmount and try again for 5 times
			while ((iFResult != FR_OK) && (count < 5))
			{
				iFResult = f_mount(0, 0);
				count++;
				__delay_cycles(10000);
				iFResult = f_mount(0, &g_sFatFs);
				__delay_cycles(10000);
				iFResult |= f_open(&g_sFileObject, "data.txt", FA_WRITE | FA_CREATE_NEW);
			}
//			sizeBuf = strlen(temp) + 1;
			sizeBuf = sizeBuf + bw;

			sprintf(temp, "\n%d, %d, %d, %d ", temperature, pressure, lux, h);
			btw = strlen(temp);
			if(count < 5)
			{
				//Find the end of the file and write new data here
				iFResult = f_lseek(&g_sFileObject, sizeBuf);
				iFResult = f_write(&g_sFileObject, temp, btw, &bw);
				//close the file
				iFResult = f_close(&g_sFileObject);
			}
		}
	}
}
Пример #13
0
int main()
{
	uint8_t rfbuf[32], i, do_lpm, pktlen, pipeid;

	WDTCTL = WDTPW | WDTHOLD;


	// I/O ports used for status LED
	//P3DIR |= BIT6;
	P1DIR |= BIT0;
	//P1OUT &= ~BIT7;
	P1OUT &= ~BIT0;
	//P3OUT |= BIT6;  // Blue LED signifies clock startup

	/* MSP430 F5172 */
	//ucs_clockinit(16000000, 0, 0);
	/* MSP430 G-series */
	DCOCTL = CALDCO_16MHZ;
	BCSCTL1 = CALBC1_16MHZ;
	BCSCTL2 = DIVS_1;

	//P3OUT &= ~BIT6;



	// Configure Nordic nRF24L01+
	rf_crc = RF24_EN_CRC | RF24_CRCO; // CRC enabled, 16-bit
	rf_addr_width      = 5;
	rf_speed_power     = RF_SPEED | RF24_POWER_MAX;  // RF_SPEED from tcsender.h
	rf_channel         = RF_CHANNEL;  // This #define is located in tcsender.h
	msprf24_init();
	msprf24_open_pipe(0, 0);
	msprf24_set_pipe_packetsize(0, 0);

	packet_init_tasklist();
	dmx512_init();

	// Submit one color change.
	memcpy(dmx512_buffer, rgb_cust, 3);
	dmx512_output_channels(0x00, 1, dmx512_buffer, 3);

	while(1) {
		do_lpm = 1;

		// Handle RF acknowledgements
		if (rf_irq & RF24_IRQ_FLAGGED || msprf24_rx_pending()) {
			msprf24_get_irq_reason();

			// Handle TX acknowledgements
			if (rf_irq & RF24_IRQ_TX) {
				// Acknowledge
				msprf24_irq_clear(RF24_IRQ_TX);
				P1OUT &= ~BIT0;
			}

			if (rf_irq & RF24_IRQ_TXFAILED) {
				msprf24_irq_clear(RF24_IRQ_TXFAILED);
				flush_tx();
			}

			if (rf_irq & RF24_IRQ_RX || msprf24_rx_pending()) {
				pktlen = r_rx_peek_payload_size();
				if (pktlen > 0 && pktlen < 33) {
					pipeid = r_rx_payload(pktlen, (char*)rfbuf);
					if (pipeid == 1) {
						for (i=0; i < pktlen; i++) {
							if (rfbuf[i]) {
								/* Process this packet if it's valid (and payload length doesn't send us
								 *   past the end of the rfbuf buffer)
								 */
								if ( (i+rfbuf[i+1] + 1) < pktlen ) {
									packet_processor(rfbuf[i],
											 rfbuf[i+1],
											 &rfbuf[i+2]);
									i += rfbuf[i+1] + 1;
								} else {
									i = pktlen;  /* Otherwise, we're done, we assume the
										      *   the rest of the payload is corrupt.
										      */
								}
							} /* rfbuf[i] != 0x00 (i.e. valid program ID) */
						} /* for(0 .. pktlen) */
					} /* pipeid == 1 */
				} else {
					// False alarm; bad packet, nuke it.
					flush_rx();
				} /* pktlen is 1..32 */
				msprf24_irq_clear(RF24_IRQ_RX);
			} /* rf_irq & RF24_IRQ_RX */

			do_lpm = 0;
		}  /* rf_irq & RF24_IRQ_FLAGGED */

		if (packet_task_next() != NULL) {
			packet_process_txqueue();
		}

		if (do_lpm)
			LPM4;
	} /* while(1) */

	return 0;  // Should never reach here
}
Пример #14
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
        BCSCTL3 = LFXT1S_2;  // ACLK = VLOCLK/1
        BCSCTL3 &= ~(XT2OF|LFXT1OF);


    //init the ADC
    //ADC_init();
    Temp_ADC_init();

    wdtsleep = 0;

    // SPI (USI) uses SMCLK, prefer SMCLK=DCO (no clock division)
    user = 0xFE;

    /* Initial values for nRF24L01+ library config variables */
    rf_crc = RF24_EN_CRC; // CRC enabled, 8-bit
    //| RF24_CRCO;
    rf_addr_width      = 5;
    //rf_speed_power     = RF24_SPEED_1MBPS | RF24_POWER_MAX;
    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, 0);
    msprf24_open_pipe(0, 1);  // Open pipe#0 with Enhanced ShockBurst enabled for receiving Auto-ACKs
    // Note: Pipe#0 is hardcoded in the transceiver hardware as the designated "pipe" for a TX node to receive
    // auto-ACKs.  This does not have to match the pipe# used on the RX side.

    // Transmit to 0xDEADBEEF00
    msprf24_standby();
    user = msprf24_current_state();
    //addr[0] = 'r'; addr[1] = 'a'; addr[2] = 'd'; addr[3] = '0'; addr[4] = '1';
    memcpy(addr, "\xDE\xAD\xBE\xEF\x00", 5);
    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.
    buf[0] = '0';
    //buf[1]='\0';
    buf[2] = '\0';
    while(1) {
        if (rf_irq & RF24_IRQ_FLAGGED) {  // Just acknowledging previous packet here
            msprf24_get_irq_reason();
            msprf24_irq_clear(RF24_IRQ_MASK);
            user = msprf24_get_last_retransmits();
        } else {  // WDT sleep completed, send a new packet
            //if (buf[0] == '1')
            //	buf[0] = '0';
            //else
            //	buf[0] = '1';

            //buf[] = snprintf(buf,32,"%d",ADC_read());
            adc_val = ADC_read();
            
            //adc_val = 1023;
            //buf[0] = (uint8_t)(adc_val>>8);//get high byte
            //buf[1] = (uint8_t)(adc_val);//low byte
            //buf[0]=(uint8_t)(adc_val>>2);//8 bits?
            
            buf[1]= ((48724L * adc_val) -  30634388L) >> 16;
            
            //celsius
            //buf[1]=((27069L * adc_val) -  18169625L) >> 16; 
            
            w_tx_payload(32, buf);
            msprf24_activate_tx();
        }

        wdt_sleep(1);  //
    }
    return 0;
}
Пример #15
0
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void main()
{
	int err = NONE;
    char addr[5];
    char buf[32];

    err = InitFunction();

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

//    // Red, Green LED used for status
//    P1DIR |= 0x41;
//    P1OUT &= ~0x41;

    user = 0xFE;  // this is just used for testing, examined via debugger, it can be ignored

    /* Initial values for nRF24L01+ library config variables */
    rf_crc = RF24_EN_CRC | RF24_CRCO; // CRC enabled, 16-bit
    rf_addr_width      = 5;
    rf_speed_power     = RF24_SPEED_1MBPS | RF24_POWER_0DBM;
    rf_channel     	   = 120;

    msprf24_init();  // All RX pipes closed by default
    msprf24_set_pipe_packetsize(0, 32);
    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();
    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.

    while(1)
    {
        __delay_cycles(800000);
        if(buf[0]=='0')
        {
        	buf[0] = '1';
        	buf[1] = '0';
        }
        else
        {
        	buf[0] = '0';
        	buf[1] = '1';
        }
//        w_tx_payload(32, buf);
        msprf24_activate_tx();

        if (rf_irq & RF24_IRQ_FLAGGED)
        {
            msprf24_get_irq_reason();
            if (rf_irq & RF24_IRQ_TX)
            {
            	GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2);
            	GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN1);
            }
            if (rf_irq & RF24_IRQ_TXFAILED)
            {
            	GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2);
            	GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN0);
            }

            msprf24_irq_clear(rf_irq);
            user = msprf24_get_last_retransmits();
        }
    }
}