Example #1
0
int main(void) 
{
  int i;

  WDTCTL = WDTPW + WDTHOLD;

  P1IE   = 0x00;        // Interrupt enable
  P2IE   = 0x00;        // 0:disable 1:enable

  LEDS_INIT();
  LEDS_ON();
  delay(DELAY);
  LEDS_OFF();

  led_state = 0;

  while (1) 
    {                         
      for (i=0; i<99; i++)
	{
	  led_change();
	  delay(DELAY >> 2);
	}
    }
}
Example #2
0
int main(void) 
{
    int i;

    set_mcu_speed_xt2_mclk_8MHz_smclk_1MHz();

    uart0_init(UART0_CONFIG_1MHZ_115200);

    LEDS_INIT();
    LEDS_ON();
    delay(DELAY);
    LEDS_OFF();

    led_state = 0;

    while (1) 
    {
        for (i=0; i<99; i++)
        {
            printf("Salam Aleikoum\n");
            uart0_getchar_polling();
            led_change();
        }
    }
}
Example #3
0
int main(void) 
{

  WDTCTL = WDTPW + WDTHOLD;
  
  P1IE   = 0x00;        // Interrupt enable
  P2IE   = 0x00;        // 0:disable 1:enable

  LEDS_INIT();
  LEDS_ON();
  delay(DELAY >> 4);
  LEDS_OFF();

  set_mcu_speed_xt2_mclk_8MHz_smclk_1MHz();
  LED_BLUE_ON;
  delay(DELAY >> 4);
  LED_BLUE_OFF;

  uart1_init();
  LED_RED_ON;
  delay(DELAY >> 4);
  LED_RED_OFF;

  printf("wsn430-timer test ready\n");
  printf("timerA3 register 0 = red / ACLK @ 32KHz\n");
  printf("timerB5 register 0 = blue / SMCLK @ 1MHz\n");

  timerA3_register_callback(red_led);
  timerB7_register_callback(blue_led);

  eint();
  timerB7_SMCLK_start_Hz(5);

  while (1) 
    {       
      timerA3_ACLK_start_Hz(5);
      delay(DELAY);

      timerA3_ACLK_start_Hz(10);
      delay(DELAY);

      timerA3_ACLK_start_Hz(2);
      delay(DELAY);

      timerB7_SMCLK_start_Hz(5);
      delay(DELAY);

      timerB7_SMCLK_start_Hz(20);
      delay(DELAY);

      timerB7_SMCLK_start_Hz(2);
      delay(DELAY);
    }
}
Example #4
0
int main(void) 
{
	// Set the MCU clock to 8MHz
	set_mcu_speed_xt2_mclk_8MHz_smclk_1MHz();

	// Enable interrupts
	eint();

	// Swtich of LEDs
	LEDS_INIT();
	LEDS_OFF();

	/** Initialization of timer A
	 *  This has to be done before using any of the timer A manipulation routine
	 */
	timerA_init();

	/** Callbacks registration
	 *  Two callbacks are registered, one for alarm 0 and another one for alarm 1.
	 *  Alarm 2 and overflow are not used. Therefore a NULL callback is registers.
	 *  This disables the two interrupts
	 */
	timerA_register_cb(TIMERA_ALARM_CCR0, callback0);
	timerA_register_cb(TIMERA_ALARM_CCR1, callback1);
	timerA_register_cb(TIMERA_ALARM_CCR2, 0);
	timerA_register_cb(TIMERA_ALARM_OVER, 0);

	/** Alarm periods definition
	 *  Alarm 0 is triggered every 32768 ticks (i.e. every 1s as ACLK is 32768Hz
	 *  on WSN430). Its first call will happen 1 tick after the routine call.
	 *  Alarm 1 is triggered every 16384 ticks (i.e. every 500ms). Its first call
	 *  will happen 10 ticks after the routine call.
	 */
	timerA_set_alarm_from_now(TIMERA_ALARM_CCR0, 1, 32768); 
	timerA_set_alarm_from_now(TIMERA_ALARM_CCR1, 10, 16384); 

	/** Timer start
	 *  Starts the timer with a frequency of ACK/TIMERA_DIV_1, i.e. 32768Hz
	 */
	timerA_start_ACLK_div(TIMERA_DIV_1);

	// Main loop
	while (1) 
	{
		// Put the processor in low power mode (only ACLK is active)
		LPM3;
		// Toggles the blue LED and go back to LPM
		toggle_led(2);
	}

	return 0;
}
Example #5
0
/**
 * Initialize the main hardware parameters.
 */
static void prvSetupHardware(void) {
	/* Stop the watchdog timer. */
	WDTCTL = WDTPW + WDTHOLD;

	/* Setup MCLK 8MHz and SMCLK 1MHz */
	set_mcu_speed_xt2_mclk_8MHz_smclk_1MHz();

	LEDS_INIT();
	LEDS_OFF();

	uart0_init(UART0_CONFIG_1MHZ_115200);
	uart0_register_callback(char_rx);

	/* Enable Interrupts */
	eint();
}
Example #6
0
/**
 * Initialize the main hardware parameters.
 */
static void prvSetupHardware(void) {
	/* Stop the watchdog timer. */
	WDTCTL = WDTPW + WDTHOLD;

	/* Setup MCLK 8MHz and SMCLK 1MHz */
	set_mcu_speed_xt2_mclk_8MHz_smclk_1MHz();

	LEDS_INIT();
	LEDS_OFF();

	uart0_init(UART0_CONFIG_1MHZ_115200);

	printf("FreeRTOS SENSOR TDMA coordinator\r\n");

	/* Enable Interrupts */
	eint();
}
Example #7
0
int main(void) {
    BOARD_Init();

    // Configure Timer 1 using PBCLK as input. This default period will make the LEDs blink at a
    // pretty reasonable rate to start.
    OpenTimer1(T1_ON | T1_SOURCE_INT | T1_PS_1_8, 0xFFFF);

    // Set up the timer interrupt with a priority of 4.
    INTClearFlag(INT_T1);
    INTSetVectorPriority(INT_TIMER_1_VECTOR, INT_PRIORITY_LEVEL_4);
    INTSetVectorSubPriority(INT_TIMER_1_VECTOR, INT_SUB_PRIORITY_LEVEL_0);
    INTEnable(INT_T1, INT_ENABLED);

    /***************************************************************************************************
     * Your code goes in between this comment and the following one with asterisks.
     **************************************************************************************************/
    int x = 0x01;
    LEDS_INIT();
    //give the initial value
    checkItem.event = 0;
    checkItem.value = 0;
    int direction = RIGHT;
    while (1) {
        //set the value
        LEDS_SET(x);
        if (checkItem.event == 1) {
            checkItem.event = 0;
            //two directions
            if(direction == RIGHT){
                x = x << 1;
            }else{
                 x = x >> 1;
            }
        }
        //edge case of 0x100
        if((x == 0x100) && (direction == RIGHT)){
            x = 0x40;
            direction = LEFT;
        }
        //edge case of 0x00
        if((x == 0) && (direction == LEFT)){
            x = 0x02;
            direction = RIGHT;
        }
    }
Example #8
0
void hardware_setup(void)
{
/**
*
* Hardware init
*
*/
#ifdef HAVE_WDT
	// watchdog timer init
 	wdt_init_and_start();
#else
	//stop wdg
 	wdt_hold();
#endif



	// clocks, wdt, power, uart, spi
	set_clocks_speed(MCLK_4MHZ_SMCLK_4MHZ);

	driver_power_init();
	//#if ! defined HAVE_CODE_COMPRESSION & ! defined HAVE_DEBUG
	uartSetup(UART0_CONFIG_32KHZ_9600);
	//#endif
	spi_init();
	timer_init();

	// LEDs
	LEDS_INIT();
	LEDS_OFF_CHECK_MODE(led_mode);

	// Temperature
#ifndef	HAVE_CODE_COMPRESSION
	update_temperature(); // for some unclear reason the very first temp measure is incorrect
	update_temperature(); // hence taking an extra-measure for security
#endif

// powersave
#ifdef HAVE_POWERSAVE
	power_init();
#endif /* HAVE_POWERSAVE */


}
Example #9
0
int main (void)
{
    WDTCTL = WDTPW+WDTHOLD;                   // Stop watchdog timer

    set_mcu_speed_xt2_mclk_8MHz_smclk_1MHz();
    set_aclk_div(1);

    LEDS_INIT();
    LEDS_OFF();

    uart0_init(UART0_CONFIG_1MHZ_115200);
    printf("\n-----------------------------------\n");
    printf("TDMA_NODE test\r\n");
    eint();

    mac_init(0);
    mac_set_access_allowed_cb(mac_ready);

    printf("*** I'm %u ***\n", node_addr);

    uint8_t dodo = 'a';
    while(1) {
        if (mac_is_access_allowed()) {
            mac_payload[0] = dodo;
            mac_send();

            dodo++;
            if (dodo>'z')dodo='a';

            LED_RED_TOGGLE();
        }
        LPM3;
    }

    return 0;
}
Example #10
0
File: mac.c Project: EDAyele/wsn430
static void vInitMac(void)
{
    /* Leds */
    LEDS_INIT();
    LEDS_OFF();

    /* Initialize the radio driver */
    cc1101_init();
    cc1101_cmd_idle();

    cc1101_cfg_append_status(CC1101_APPEND_STATUS_ENABLE);
    cc1101_cfg_crc_autoflush(CC1101_CRC_AUTOFLUSH_DISABLE);
    cc1101_cfg_white_data(CC1101_DATA_WHITENING_ENABLE);
    cc1101_cfg_crc_en(CC1101_CRC_CALCULATION_ENABLE);
    cc1101_cfg_freq_if(0x0C);
    cc1101_cfg_fs_autocal(CC1101_AUTOCAL_NEVER);

    cc1101_cfg_mod_format(CC1101_MODULATION_MSK);

    cc1101_cfg_sync_mode(CC1101_SYNCMODE_30_32);

    cc1101_cfg_manchester_en(CC1101_MANCHESTER_DISABLE);

    // set channel bandwidth (560 kHz)
    cc1101_cfg_chanbw_e(0);
    cc1101_cfg_chanbw_m(2);

    // set data rate (0xD/0x2F is 250kbps)
    cc1101_cfg_drate_e(0x0D);
    cc1101_cfg_drate_m(0x2F);

    uint8_t table[] = {CC1101_868MHz_TX_12dBm};
    cc1101_cfg_patable(table, 1);
    cc1101_cfg_pa_power(0);

}
Example #11
0
int main()
{
    // Configure the device for maximum performance but do not change the PBDIV
    // Given the options, this function will change the flash wait states, RAM
    // wait state and enable prefetch cache but will not change the PBDIV.
    // The PBDIV value is already set via the pragma FPBDIV option above..
    SYSTEMConfig(F_SYS, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);

    // Auto-configure the PIC32 for optimum performance at the specified operating frequency.
    SYSTEMConfigPerformance(F_SYS);

    // osc source, PLL multipler value, PLL postscaler , RC divisor
    OSCConfig(OSC_POSC_PLL, OSC_PLL_MULT_20, OSC_PLL_POST_1, OSC_FRC_POST_1);

    // Configure the PB bus to run at 1/4th the CPU frequency, so 20MHz.
    OSCSetPBDIV(OSC_PB_DIV_4);

    // Enable multi-vector interrupts
    INTEnableSystemMultiVectoredInt();
    INTEnableInterrupts();

    // Configure Timer 2 using PBCLK as input. We configure it using a 1:16 prescalar, so each timer
    // tick is actually at F_PB / 16 Hz, so setting PR2 to F_PB / 16 / 100 yields a .01s timer.
    OpenTimer2(T2_ON | T2_SOURCE_INT | T2_PS_1_16, F_PB / 16 / 100);

    // Set up the timer interrupt with a medium priority of 4.
    INTClearFlag(INT_T2);
    INTSetVectorPriority(INT_TIMER_2_VECTOR, INT_PRIORITY_LEVEL_4);
    INTSetVectorSubPriority(INT_TIMER_2_VECTOR, INT_SUB_PRIORITY_LEVEL_0);
    INTEnable(INT_T2, INT_ENABLED);

/******************************** Your custom code goes below here ********************************/
    int check;
    OledInit();
    AdcInit();
    LEDS_INIT();
    check = GameInit();

    if(check == STANDARD_ERROR) {
        FATAL_ERROR();
    }
    float currPage;
    float binSize;
    float titleSize;
    float descSize;
    float numPages;
    uint8_t roomExit;
    uint16_t adcValue = 0;

    while(1) {
        roomExit = GameGetCurrentRoomExits();
        LEDS_SET(roomExit);
        while(buttonEvents == 0) {
            descSize = GameGetCurrentRoomDescription(roomData.description);
            titleSize = GameGetCurrentRoomTitle(roomData.title);

            numPages = ((titleSize + descSize) / MAX_OLED_PIXELS);
            binSize = (ADC_MAX_VALUE / numPages);

            if(AdcChanged()) {
                adcValue = AdcRead();
            }

            currPage = (adcValue / binSize);
            if(currPage < 1) {
                char titleArray[TITLE_OLED_SPACE] = {0};
                char descriptionBuffer[FIRST_PG_DESCRIPTION_OLED_SPACE] = {0};

                strncpy(descriptionBuffer, roomData.description, DESCRIPTION_COPY);
                sprintf(titleArray, "%s\n%s", roomData.title, descriptionBuffer);

                OledClear(OLED_COLOR_BLACK);
                OledDrawString(titleArray);
            } else {
                char buffer[MAX_OLED_PIXELS] = {0};
                int buffIndex;
                buffIndex = (int)currPage * MAX_OLED_PIXELS;
                strncpy(buffer, (roomData.description + buffIndex - OFFSET), MAX_OLED_PIXELS);

                OledClear(OLED_COLOR_BLACK);
                OledDrawString(buffer);
            }
            OledUpdate();
        }

        if((buttonEvents & BUTTON_EVENT_4UP) && (roomExit & GAME_ROOM_EXIT_NORTH_EXISTS)) {
            GameGoNorth();
        } else if((buttonEvents & BUTTON_EVENT_3UP) && (roomExit & GAME_ROOM_EXIT_EAST_EXISTS)) {
            GameGoEast();
        } else if((buttonEvents & BUTTON_EVENT_2UP) && (roomExit & GAME_ROOM_EXIT_SOUTH_EXISTS)) {
            GameGoSouth();
        } else if((buttonEvents & BUTTON_EVENT_1UP) && (roomExit & GAME_ROOM_EXIT_WEST_EXISTS)) {
            GameGoWest();
        }
        buttonEvents = BUTTON_EVENT_NONE;
    }



/**************************************************************************************************/
    while (1);
}
Example #12
0
/**
 * The main function.
 */
int main( void )
{
	/* Stop the watchdog timer. */
	WDTCTL = WDTPW + WDTHOLD;
	
	/* Setup MCLK 8MHz and SMCLK 1MHz */
	set_mcu_speed_xt2_mclk_8MHz_smclk_1MHz();
	
	/* Enable Interrupts */
	eint();
	
	uart0_init(UART0_CONFIG_1MHZ_115200);
	uart0_register_callback(char_cb);
	printf("CC1100 RXTX test program\r\n");
	
	LEDS_INIT();
	LEDS_OFF();
	
	cc1100_init();
	
	cc1100_cfg_append_status(CC1100_APPEND_STATUS_ENABLE);
	cc1100_cfg_crc_autoflush(CC1100_CRC_AUTOFLUSH_DISABLE);
	cc1100_cfg_white_data(CC1100_DATA_WHITENING_ENABLE);
	cc1100_cfg_crc_en(CC1100_CRC_CALCULATION_ENABLE);
	cc1100_cfg_freq_if(0x0C);
	cc1100_cfg_fs_autocal(CC1100_AUTOCAL_NEVER);
	
	cc1100_cfg_mod_format(CC1100_MODULATION_MSK);
	
	cc1100_cfg_sync_mode(CC1100_SYNCMODE_30_32);
	
	cc1100_cfg_manchester_en(CC1100_MANCHESTER_DISABLE);
	
	printf("CC1100 initialized\r\nType 's' to send a message\r\n");
	
	while(1)
	{
		// Enter RX
		LED_RED_ON();
		cc1100_cmd_idle();
		cc1100_cmd_flush_rx();
		cc1100_cmd_calibrate();
		cc1100_cmd_rx();
		
		cc1100_cfg_gdo0(CC1100_GDOx_SYNC_WORD);
		cc1100_gdo0_int_set_falling_edge();
		cc1100_gdo0_int_clear();
		cc1100_gdo0_int_enable();
		cc1100_gdo0_register_callback(rx_ok);
		
		// Low Power Mode
		LPM0;
		
		// Check for send flag
		if (send == 1) {
			send = 0;
			LED_RED_OFF();
			cc1100_cmd_idle();
			cc1100_cmd_flush_tx();
			cc1100_cmd_calibrate();
			cc1100_gdo0_int_disable();
			
			frameseq ++;
			
			length = sprintf((char *)frame, "Hello World #%i", frameseq);
			
			printf("Sent : %s \r\n", frame);
			
			cc1100_fifo_put(&length, 1);
			cc1100_fifo_put(frame, length);
			
			cc1100_cmd_tx();
			
			// Wait for SYNC word sent
			while (cc1100_gdo0_read() == 0);
			
			// Wait for end of packet
			while (cc1100_gdo0_read() != 0);
		}
		
		// Check for receive flag
		if (receive == 1) {
			receive = 0;
			uint8_t i;

			// verify CRC result
			if ( !(cc1100_status_crc_lqi() & 0x80) ) {
				continue;
			}

			cc1100_fifo_get(&length, 1);
			
			if (length > 60) {
				continue;
			}
			
			cc1100_fifo_get(frame, length+2);

			uint16_t rssi = (uint16_t)frame[length];
			int16_t rssi_d;

			if (rssi >= 128)
				rssi_d = (rssi-256)-140;
			else
				rssi_d = rssi-140;

			printf("Frame received with RSSI=%d.%d dBm: ", rssi_d, 5*(rssi_d&0x1));
			for (i=0; i<length; i++) {
				printf("%c",frame[i]);
			}
			printf("\r\n");

			LED_GREEN_TOGGLE();
		}
	}
	
	return 0;
}
Example #13
0
int main(void)
{
    WDTCTL = WDTPW+WDTHOLD;

    set_mcu_speed_xt2_mclk_8MHz_smclk_1MHz();
    set_aclk_div(1);

    LEDS_INIT();
    LEDS_OFF();


    ds2411_init();
    nodeaddr = (((uint16_t)ds2411_id.serial1)<<8) + (ds2411_id.serial0);

    uart0_init(UART0_CONFIG_1MHZ_115200);
    uart0_register_callback(char_rx);
    eint();

    printf("[APP];BOOTING;%.4x\n",nodeaddr);


    //check if this node is the sink
    if (nodeaddr == sink_nodes)
    {
        type = SINK;
        level = DEFAULT_LEVEL;
    }
    else
    {
        //retrieve father
        for (idx=0; idx<NUMBER_NODES; idx++)
        {
            if (list_nodes[idx] == nodeaddr)
            {
                if(father_nodes1[idx] != 0x0000)
                {
                    parent_id = father_nodes1[idx];
                    level = 12;
                    break;
                }
            }
        }
    }
    
    //hack for mobile
    /*if(nodeaddr == 0x1f5d)
    {
        parent_id = 0x0000;
        mac_set_mobile(1);
        level = 12;
    }*/

    mac_init(10);
    mac_set_rx_cb(packet_received);
    mac_set_error_cb(packet_error);
    mac_set_sent_cb(packet_sent);

    timerB_set_alarm_from_now(TIMERB_ALARM_CCR6, 32768, 32768);
    timerB_register_cb(TIMERB_ALARM_CCR6, inc_clock);

    while (1)
    {
        LPM1;

        if (state == SM_TX)
        {
            if (level != UNDEF_LEVEL && type != SINK)
            {
                seq_max = NUM_SEQ_MAX;
                delay = rand();
                delay &= 0xCFFF;
                delay += 12000; //(369ms < delay < 1991ms)
                timerB_set_alarm_from_now(TIMERB_ALARM_CCR5, delay, 0);
                timerB_register_cb(TIMERB_ALARM_CCR5, next_send);
            }
            else
            {
                printf("[APP];NOROUTE\n");
            }

            state = SM_IDLE;
        }
        else if (state == SM_LOOP_TX)
        {
            if (level != UNDEF_LEVEL)
            {
                sprintf(sourceaddr,"%.4x",nodeaddr);
                data_txframe[0] = DATA;
                data_txframe[1] = level-1;
                data_txframe[2] = sourceaddr[0];
                data_txframe[3] = sourceaddr[1];
                data_txframe[4] = sourceaddr[2];
                data_txframe[5] = sourceaddr[3];
                data_txframe[6] = seq;	//sequence
                data_txframe[7] = 1;    //hops
                txlength = 8;

                stat_add(STAT_APP_TX);
                printf("[APP];NODE_TX;%.4x;%.4x;%u;%u-%u\n", nodeaddr, parent_id, seq, global_clock, timerB_time()/32);

                seq++;

                mac_send(data_txframe, txlength, parent_id);

                if (DEBUG_LEDS == 1)
                {
                    LED_GREEN_ON();
                }

                if (seq < seq_max)
                {
                    timerB_set_alarm_from_now(TIMERB_ALARM_CCR5, SEND_DATA_PERIOD, 0);
                    timerB_register_cb(TIMERB_ALARM_CCR5, next_send);
                }
            }
            state = SM_IDLE;
        }
     
    }

    return 0;
}
Example #14
0
/**
 * The main function.
 */
int main( void )
{

    /* Stop the watchdog timer. */
    WDTCTL = WDTPW + WDTHOLD;

    /* Setup MCLK 8MHz and SMCLK 1MHz */
    set_mcu_speed_xt2_mclk_8MHz_smclk_1MHz();

    /* Enable Interrupts */
    eint();

    LEDS_INIT();
    LEDS_ON();

    uart0_init(UART0_CONFIG_1MHZ_115200);
    printf("CC2420 TX test program with address recognition and acknowledge frames\r\n");

    cc2420_init();
    cc2420_io_sfd_register_cb(sfd_cb);
    cc2420_io_sfd_int_set_falling();
    cc2420_io_sfd_int_clear();
    cc2420_io_sfd_int_enable();
    cc2420_set_txpower(CC2420_2_45GHz_TX_0dBm);

    uint8_t fcf[2] = {0x21, 0x88};  /* -> 00100001 10001000 -> reverse of bits for each byte -> 10000100 00010001 -> ack bit = 1 (6th bit), Frame type = 001 (don't forget to read from right to left) */
    uint8_t seq_numb = 0x01;
    uint8_t dest_pan_id[2] = {0x22, 0x00};
    uint8_t dest_addr[2] = {0x11, 0x11};

    uint8_t src_pan_id[2] = {0x22, 0x01};
    uint8_t src_addr[2] = {0x11, 0x12};

    while ( (cc2420_get_status() & 0x40) == 0 ); // waiting for xosc being stable

    cc2420_set_panid(src_pan_id); // save pan id in ram
    cc2420_set_shortadr(src_addr); // save short address in ram

    printf("CC2420 initialized\r\n");

    LEDS_OFF();

    while (1)
    {
        cc2420_cmd_idle();
        cc2420_cmd_flushtx();

        txlength = sprintf((char *)txframe, "Hello World #%i", seq_numb);

        printf("Sent : %s of length %d\r\n", txframe,txlength);

        txlength += 13;

        cc2420_fifo_put(&txlength, 1);
        cc2420_fifo_put(fcf, 2);
        cc2420_fifo_put(&seq_numb, 1);
        cc2420_fifo_put(dest_pan_id, 2);
        cc2420_fifo_put(dest_addr, 2);
        cc2420_fifo_put(src_pan_id, 2);
        cc2420_fifo_put(src_addr, 2);
        cc2420_fifo_put(txframe, txlength-13);

	LED_BLUE_TOGGLE();

        cc2420_cmd_tx();

        micro_delay(0xFFFF);
	while (cc2420_io_sfd_read());

	printf("Waiting for acknowledge frame...\n");

	if (rx_ack())
	{
            seq_numb ++;
	}
	else
	{
	    printf("No Acknowledge frame received for frame number #%i - Retrying...\r\n\n", seq_numb);
	    LED_RED_TOGGLE();
	}
        micro_delay(0xFFFF);
        micro_delay(0xFFFF);
        micro_delay(0xFFFF);
        micro_delay(0xFFFF);
        micro_delay(0xFFFF);
        micro_delay(0xFFFF);
        micro_delay(0xFFFF);
        micro_delay(0xFFFF);
        micro_delay(0xFFFF);
        micro_delay(0xFFFF);
    }


    return 0;
}
Example #15
0
/**
 * The main function.
 */
int main( void )
{
    /* Stop the watchdog timer */
    WDTCTL = WDTPW + WDTHOLD;

    /* Setup the MSP430 micro-controller clock frequency: MCLK, SMCLK and ACLK */

    /* Set MCLK at 8MHz and SMCLK at 1MHz */
    set_mcu_speed_xt2_mclk_8MHz_smclk_1MHz();

	/* Set ACKL at 4096Hz (32 768Hz / 8) */
    set_aclk_div(8);

    /* Initialize the LEDs */
    LEDS_INIT();
    LEDS_OFF();

    /* Initialize the temperature sensor */
    ds1722_init();
    ds1722_set_res(12);
    ds1722_sample_cont();

    /* Initialize the Luminosity sensor */
    tsl2550_init();
    tsl2550_powerup();
    tsl2550_set_standard();
    tsl2550_read_adc0();

    /* Initialize the UART0 */

	/* We want 115kbaud, and SMCLK is running at 1MHz */
    uart0_init(UART0_CONFIG_1MHZ_115200);

	/* Set the UART callback function it will be called every time a character is received. */
    uart0_register_callback(char_rx);

    /* Print first message */
    printf("\n\nSenslab Simple Demo program\n");

    /* Enable Interrupts */
    eint();

    /* Print information */
    printf("Type command\n");
    printf("\tt:\ttemperature measure\n");
    printf("\tl:\tluminosity measure\n");

    /* Initialize the timer for the LEDs */
    timerA_init();

	/*  TimerA clock is at 512Hz (4096Hz / 8) */
    timerA_start_ACLK_div(TIMERA_DIV_8);

    /* Configure the first timerA period to 1s (periodic) */
    timerA_set_alarm_from_now(TIMERA_ALARM_CCR0, 512, 512);

	/* Set the first timerA callback */
    timerA_register_cb(TIMERA_ALARM_CCR0, alarm);

    // Declare 2 variables for storing the different values
    int16_t value_0=0, value_1=1;
    while (1) {
        printf("cmd > ");
        cmd = 0;

        while (cmd==0) {
            LPM0; // Low Power Mode 1: SMCLK remains active for UART
        }

        switch (cmd) {
        case 't':
            value_0 = ds1722_read_MSB();
            value_1 = ds1722_read_LSB();
            value_1 >>= 5;
            value_1 *= 125;
            printf("Temperature measure: %i.%i\n", value_0, value_1);
            break;
        case 'l':
            tsl2550_init();
            value_0 = tsl2550_read_adc0();
            value_1 = tsl2550_read_adc1();
            uart0_init(UART0_CONFIG_1MHZ_115200);
            uart0_register_callback(char_rx);
            printf("Luminosity measure: %i:%i\n", value_0, value_1);
            break;
        default:
            break;
        }
    }

    return 0;
}
Example #16
0
/**
 * The main function.
 */
int main( void )
{
    uint8_t i;
    uint8_t length;

    /* Stop the watchdog timer. */
    WDTCTL = WDTPW + WDTHOLD;

    /* Setup MCLK 8MHz and SMCLK 1MHz */
    set_mcu_speed_xt2_mclk_8MHz_smclk_1MHz();

    /* Enable Interrupts */
    eint();

    LEDS_INIT();
    LEDS_ON();

    uart0_init(UART0_CONFIG_1MHZ_115200);
    printf("CC2420 RX test program with address recognition and acknowledge frames\r\n");

    cc2420_init();
    cc2420_io_sfd_register_cb(sfd_cb);
    cc2420_io_sfd_int_set_falling();
    cc2420_io_sfd_int_clear();
    cc2420_io_sfd_int_enable();

    uint8_t src_pan_id[2] = {0x22,0x00};
    uint8_t src_addr[2] = {0x11,0x11};

    while ( (cc2420_get_status() & 0x40) == 0 ); // waiting for xosc being stable

    cc2420_set_panid(src_pan_id); // save pan id in ram
    cc2420_set_shortadr(src_addr); // save short address in ram

    printf("CC2420 initialized\r\n");

    LEDS_OFF();

    while(1)
    {
        cc2420_cmd_idle();
        cc2420_cmd_flushrx();
        cc2420_cmd_rx();

        while (flag == 0) ;
        micro_delay(0xFFFF);
        flag = 0;
	LED_GREEN_TOGGLE();
        cc2420_fifo_get(&length, 1);
        if ( length < 128 )
        {
            cc2420_fifo_get(rxframe, length);
            // check CRC
            if ( (rxframe[length-1] & 0x80) != 0 )
            {
                printf("Frame received with rssi=%ddBm:\r\n", ((signed int)((signed char)(rxframe[length-2])))-45);
                LED_BLUE_TOGGLE();
		// ignore 11 first bytes (fcf,seq,addr) and the 2 last ones (crc)
                for (i=11; i<length-2; i++)
                {
                    printf("%c",rxframe[i]);
                }
                printf("\r\n\n");
            }
	    else {
		printf("CRC non OK, erreur de transmission?\n");
                printf("\r\n");
                LED_RED_TOGGLE();
	    }
        }
    }

    return 0;
}
Example #17
0
/**
 * The main function.
 */
int main( void )
{
    // Stop the watchdog timer.
    WDTCTL = WDTPW + WDTHOLD;

    // Setup MCLK 8MHz and SMCLK 1MHz
    set_mcu_speed_xt2_mclk_8MHz_smclk_1MHz();
    set_aclk_div(8); // ACKL is at 4096Hz

    // Initialize the LEDs
    LEDS_INIT();
    LEDS_OFF();

    // Initialize the temperature sensor
    ds1722_init();
    ds1722_set_res(12);
    ds1722_sample_cont();

    // Initialier the Luminosity sensor
    tsl2550_init();
    tsl2550_powerup();
    tsl2550_set_standard();
    tsl2550_read_adc0();

    // Initialize the UART0
    uart0_init(UART0_CONFIG_1MHZ_115200); // We want 115kbaud,
                                          // and SMCLK is running at 1MHz
    uart0_register_callback(char_rx);   // Set the UART callback function
                                        // it will be called every time a
                                        // character is received.

    // Print first message
    printf("Senslab TP Ex2: UART\n");

    // Enable Interrupts
    eint();

    // Print information
    printf("Type command\n");
    printf("\tt:\ttemperature measure\n");
    printf("\tl:\tluminosity measure\n");

    // Declare 2 variables for storing the different values
    int16_t value_0, value_1;
    while (1) {
        printf("cmd > ");
        cmd = 0;

        while (cmd==0) {
            LPM1; // Low Power Mode 1: SMCLK remains active for UART
        }

        switch (cmd) {
        case 't':
            value_0 = ds1722_read_MSB();
            value_1 = ds1722_read_LSB();
            value_1 >>= 5;
            value_1 *= 125;
            printf("Temperature measure: %i.%i\n", value_0, value_1);
            break;
        case 'l':
            tsl2550_init();
            value_0 = tsl2550_read_adc0();
            value_1 = tsl2550_read_adc1();
            uart0_init(UART0_CONFIG_1MHZ_115200);
            uart0_register_callback(char_rx);
            printf("Luminosity measure: %i:%i\n", value_0, value_1);
            break;
        default:
            break;
        }
    }

    return 0;
}