/** * @brief USB_OTG_BSP_mDelay * This function provides delay time in milli sec * @param msec : Value of delay required in milli sec * @retval None */ void USB_OTG_BSP_mDelay (const uint32_t msec) { #ifdef USE_ACCURATE_TIME BSP_Delay(msec, TIM_MSEC_DELAY); #else USB_OTG_BSP_uDelay(msec * 1000); #endif }
/** * @brief USB_OTG_BSP_uDelay * This function provides delay time in micro sec * @param usec : Value of delay required in micro sec * @retval None */ void USB_OTG_BSP_uDelay (const uint32_t usec) { #ifdef USE_ACCURATE_TIME BSP_Delay(usec,TIM_USEC_DELAY); #else __IO uint32_t count = 0; const uint32_t utime = (120 * usec / 7); do { if ( ++count > utime ) { return ; } } while (1); #endif }
void takeLuxes() { //WDTCTL = WDTPW + WDTHOLD; error = 0; error += write_byte (LUX_WRITE_ADDRESS, COM_REG); error += write_byte (LUX_WRITE_ADDRESS, POW_UP); //transfer address //500 ms delay for measure //__delay_cycles (8000000); BSP_Delay(500); error += write_byte (LUX_WRITE_ADDRESS, READ_CH0); //reading from CH0 ch0 = read_word (LUX_READ_ADDRESS); error += write_byte (LUX_WRITE_ADDRESS, READ_CH1); //reading from CH1 ch1 = read_word (LUX_READ_ADDRESS); //lux calculation value = (float) ch1 / (float) ch0; if ((value > 0) && (value <= 0.5)) //CH1=1 CH0=4 (value=0.25) (lux=0.08599) lux = (0.0304 * ch0) - (0.062 * ch0 * pow(value, 1.4)); if ((value > 0.5) && (value <= 0.61)) //CH1=5.5 CH0=10 (value=0.55) (lux=0.0535) lux = (0.0224 * ch0) - (0.031 * ch1); if ((value > 0.61) && (value <= 0.8)) //CH1=7 CH0=10 (value=0.7) (lux=0.02089) lux = (0.0128 * ch0) - (0.0153 * ch1); if ((value > 0.8) && (value <= 1.3)) //CH1=12 CH0=10 (value=1.2) (lux=0.00116) lux = (0.00146 * ch0) - (0.00112 * ch1); if (value > 1.3) lux = 0; }
void main(void) { sensor.cadc = 'A'; sensor.iadc = 125; trigger(0x5 + (0x6 << 3) + (0x1 << 6) + (0x7 << 9)); BSP_Init(); // init bsp first, then simpliciti BCSCTL3 = LFXT1S_2; // aclk = vlo // address check and creation Flash_Addr = (char *)0x10F0; // RF Address = 0x10F0 if( Flash_Addr[0] == 0xFF && // Check if device Address is missing Flash_Addr[1] == 0xFF && Flash_Addr[2] == 0xFF && Flash_Addr[3] == 0xFF ) { createRandomAddress(); // Create Random device address at } // initial startup if missing lAddr.addr[0] = Flash_Addr[0]; lAddr.addr[1] = Flash_Addr[1]; lAddr.addr[2] = Flash_Addr[2]; lAddr.addr[3] = Flash_Addr[3]; // load address SMPL_Ioctl(IOCTL_OBJ_ADDR, IOCTL_ACT_SET, &lAddr); SMPL_Init(NULL); // null callback for TX Init_ADC10(); Init_TIMER0A0(); do { // wait for button if (BSP_BUTTON1()) { break; } } while (1); while (SMPL_SUCCESS != SMPL_Link(&linkIDTemp)) // link to Rx { BSP_TOGGLE_LED1(); // toggle red for not linked } BSP_TURN_OFF_LED1(); // red off BSP_Delay(2000); // for 2 seconds BSP_TURN_ON_LED1(); _EINT(); // Enable Global Interupts while (1) { BSP_TOGGLE_LED2(); // adc with dtc in use ADC10CTL0 &= ~ENC; // turn off adc10 while (ADC10CTL1 & BUSY); // wait if adc10 core is active ADC10SA = (unsigned int)ADCdata; // data buffer start ADC10CTL0 |= ENC + ADC10SC; // sampling and conversion start LPM3; // insert sensor calculations here // or // send raw adc data from P1.0 sensor.iadc = ADCdata[0]; // turn on radio and tx sensor struct SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_AWAKE, 0); SMPL_Send(linkIDTemp, (uint8_t *)&sensor, sizeof( my_sensors )); } }
/** * @brief USB_OTG_BSP_mDelay * This function provides delay time in milli sec * @param msec : Value of delay required in milli sec * @retval None */ void USB_OTG_BSP_mDelay (const uint32_t msec) { BSP_Delay(msec,TIM_MSEC_DELAY); }
/** * @brief USB_OTG_BSP_uDelay * This function provides delay time in micro sec * @param usec : Value of delay required in micro sec * @retval None */ void USB_OTG_BSP_uDelay (const uint32_t usec) { BSP_Delay(usec,TIM_USEC_DELAY); }
/************************************************************************************************** * @fn BSP_InitBoard * * @brief Initialize the board. * * @param none * * @return none ************************************************************************************************** */ void BSP_InitBoard(void) { /*unused pins are output low */ //P1, P2 PADIR = 0xF901; //P2.2. P2.3 GD0 GD1, P1.3 P1.2 connected to I2C lines! P1.1 button input PAOUT = 0; PASEL = 0; __bsp_BUTTON1_CONFIG_def__(); // Enable pull-ups //P3, P4 PBDIR = 0xFFFF; PBOUT = 0; PBSEL = 0; //P5, P6 PCDIR = 0xFFFF; PCOUT = 0; PCSEL = 0; //P7, P8 PDDIR = 0xFFFE; //Enable xtal pins PDOUT = (BIT6|BIT5); //ensure LED P7.6 P7.5 off PDSEL = 0x0003; //XT1 crystal //P9, P10 PEDIR = 0xFFFF; PEOUT = 0; PESEL = 0; //P11 P11DIR = 0xFF; P11OUT = 0; P11SEL = 0; /* disable watchdog timer */ WDTCTL = WDTPW+WDTHOLD; /* Setup XT1 crystal */ while ( (SFRIFG1 & OFIFG) ) { UCSCTL7 &= ~(XT1LFOFFG + DCOFFG); SFRIFG1 &= ~OFIFG; } UCSCTL6 &= ~(XT1DRIVE_3); // Xtal is now stable, reduce drive strength /* Set appropriate core voltage */ if(BSP_CONFIG_CLOCK_MHZ_SELECT <= 8) SetVCore(0); else if(BSP_CONFIG_CLOCK_MHZ_SELECT <= 12) SetVCore(1); else if(BSP_CONFIG_CLOCK_MHZ_SELECT <= 20) SetVCore(2); else SetVCore(3); /* Initialize the UCS module*/ __bis_SR_register(SCG0); // Disable the FLL control loop UCSCTL0 = 0x0000; // Set lowest possible DCOx, MODx UCSCTL1 = BSP_CONFIG_MSP430_DCORSEL; // Select suitable range UCSCTL2 = BSP_CONFIG_MSP430_FLLDx + BSP_CONFIG_MSP430_N; // Select divider, multiplier bits UCSCTL3 = 0; // FLL Reference Clock = XT1 UCSCTL4 = SELS__DCOCLK | SELM__DCOCLK; // MCLK & SMCLK = DCOCLK UCSCTL4 |= SELA__XT1CLK; // ACLK = XT1 (32 kHz REFO) UCSCTL6 &= ~XT1DRIVE_3; // Set DCO drive to consume least power UCSCTL6 |= XCAP_3 ; // Setup internal caps for crystal __bic_SR_register(SCG0); /* Give FLL enough time to settle */ if(BSP_CONFIG_CLOCK_MHZ_SELECT <= 8) __delay_cycles(250000); else if(BSP_CONFIG_CLOCK_MHZ_SELECT <= 12) __delay_cycles(375000); else if(BSP_CONFIG_CLOCK_MHZ_SELECT <= 20) __delay_cycles(625000); else __delay_cycles(812500); //ensure 3.3 V for MSP430 power supply P6DIR |= (BIT7); P6OUT &= ~(BIT7); //enable Vio power supply P8DIR |= (BIT5); P8OUT |= (BIT5); /* Configure TimerA for use by BSP_Delay*/ TA1CTL |= TACLR; // Reset the timer TA1CTL = 0x0; // Clear all settings TA1CTL |= TASSEL_2; // Select the clk source to be // - SMCLK (Sub-Main CLK) //give time for Vio power supplies to settle { int i; for(i = 0; i < 10; i++) BSP_Delay(1000); } }