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(); } } }
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); } }
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; }
/** * 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(); }
/** * 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(); }
int main(void) { int16_t i; WDTCTL = WDTPW | WDTHOLD; set_mcu_speed_xt2_mclk_8MHz_smclk_1MHz(); uart0_init(UART0_CONFIG_1MHZ_115200); printf("M25P80 external flash memory test program\r\n"); m25p80_init(); uint8_t sig; sig = m25p80_get_signature(); printf("signature is %x\r\n", sig); read_page(0); read_page(1); printf("Erasing sector #0\r\n"); m25p80_erase_sector(0); read_page(0); read_page(1); printf("Writing 0->255 in page #0-1\r\n"); for (i=0;i<256;i++) { page[i] = i; } m25p80_write(0x80, page, 256); for (i=0;i<256;i++) page[i] = 0xAA; read_page(0); read_page(1); while (1) {} }
int main(void) { WDTCTL = WDTPW | WDTHOLD; set_mcu_speed_xt2_mclk_8MHz_smclk_1MHz(); uart0_init(UART0_CONFIG_1MHZ_38400); printf("DS2411 unique serial number test program\r\n"); ds2411_init(); printf("Serial number is:\r\n"); int i; for (i=0;i<8;i++) { printf("%x:", ds2411_id.raw[i]); } printf("\r\n"); while (1) {} }
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; }
int main(void) { uint8_t temp1,temp2; // Stop the watchdog timer. WDTCTL = WDTPW | WDTHOLD; set_mcu_speed_xt2_mclk_8MHz_smclk_1MHz(); uart0_init(UART0_CONFIG_1MHZ_115200); printf("DS1722 temperature sensor test program\r\n"); ds1722_init(); ds1722_set_res(12); ds1722_sample_cont(); while (1) { temp1 = ds1722_read_MSB(); temp2 = ds1722_read_LSB(); printf("t=%u,%u\r\n", temp1, temp2); delay(DELAY<<2); } }
/** * 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; }
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; }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }