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;
}
Пример #2
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();
		}
	}
}
Пример #3
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;
}
Пример #5
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;
}
Пример #6
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();
        }
    }
}