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()
{
        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;
}
示例#3
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());
	}
}
示例#4
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();
		}
	}
}
示例#5
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;
}
示例#7
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;
        }

    }
}
示例#8
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);
			}
		}
	}
}
示例#9
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;
}