Exemplo n.º 1
0
/**
  * @brief Measures the BIAS current PJ1 Must be on OFF position
  * @caller main 
  * @param None
  * @retval None
  */  
void Bias_measurement(void)
{
  uint16_t V_Current;
  uint8_t B_Current;
  
  LCD_GLASS_ScrollSentence("      ** BIAS CURRENT ** JP1 OFF **",1,SCROLL_SPEED);	
  
  B_Current = ADC_Icc_Test(MCU_HALT);
  V_Current = (uint16_t)(B_Current * (Vdd_appli()/ADC_CONV)); 
  V_Current *= 10L;
  display_MuAmp(V_Current);

/* To store the value in E²Prom */
  FLASH_ProgramBias(B_Current);
	
  while (1)  /* Infinite loop for force to restart application */
  { 
    B_Current = ADC_Icc_Test(MCU_HALT);
    V_Current = (uint16_t)(B_Current * (Vdd_appli()/ADC_CONV)); 
    V_Current *= 10L;
    display_MuAmp(V_Current);
    delay_ms(300);
  }

}
Exemplo n.º 2
0
/**
  * @brief  Run auto test
  * @caller main 
  * @param None
  * @retval None
  */ 
void auto_test(void)
{
  uint16_t tab[6]={0x20,0x20,0x20,0x20,0x20,0x20};
  
  Auto_test = TRUE;
	
	/* Switch off leds*/
  GPIO_LOW(LED_GREEN_PORT,LED_GREEN_PIN);	
  GPIO_LOW(LED_BLUE_PORT,LED_BLUE_PIN);		
  
  /* To display version */
  LCD_GLASS_DisplayString(" TEST ");
  delay_ms(150);
  STR_VERSION;
  LCD_GLASS_DisplayStrDeci(tab);
  delay_ms(200);
			
	/* And launch the tests*/
  test_LSE();
  test_vdd();
  test_icc_Run();
  test_icc_HALT();
  test_icc_LP();
  
  Auto_test = FALSE;

  /* Infinite loop: Press reset button at the end of test for exit*/
  while (1)
  {
    LCD_GLASS_ScrollSentence("TEST OK ",1,SCROLL_SPEED);
    KeyPressed = FALSE;
  }
}
Exemplo n.º 3
0
/**
  * @brief  Automatic test switch to LSE clock from HSI and return to HSI
  * @caller auto_test
  * @param None
  * @retval None
  */
void test_LSE(void)
{
	
/* Switch the clock to LSE */
	
  LCD_GLASS_DisplayString("LSE");
  
  CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_1);
  CLK_LSEConfig(CLK_LSE_ON);
  delay_ms(LSE_DELAY);	
  
  if((CLK->ECKCR & CLK_ECKCR_LSERDY) == RESET)
  {
    LCD_GLASS_DisplayString("LSE");
    delay_ms(LSE_DELAY);
    if((CLK->ECKCR & CLK_ECKCR_LSERDY) == RESET)
    {
      LCD_GLASS_DisplayString("LSE");
      delay_ms(LSE_DELAY);
      if((CLK->ECKCR & CLK_ECKCR_LSERDY) == RESET)
      {			
        /* Switch the clock to HSI*/
        CLK_LSEConfig(CLK_LSE_OFF);
        CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_8);
        CLK_HSICmd(ENABLE);
        while (((CLK->ICKCR)& 0x02)!=0x02);
        CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_HSI);
        CLK_SYSCLKSourceSwitchCmd(ENABLE);
        while (((CLK->SWCR)& 0x01)==0x01);
        
        while(1)
        {
          LCD_GLASS_ScrollSentence("LSE Not OK ",1,SCROLL_SPEED); //Press reset for exit
          KeyPressed = FALSE;
        }
      }
    }
  }

/* Wait flag LSE ready */
  while (!((CLK->ECKCR)& CLK_ECKCR_LSERDY));	

/* Switch in LSE clock */
  CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_LSE);
  CLK_SYSCLKSourceSwitchCmd(ENABLE);
  while (((CLK->SWCR)& 0x01)==0x01);
  
  LCD_GLASS_DisplayString("LSE OK");

/* Switch the clock to HSI */

  CLK_LSEConfig(CLK_LSE_OFF);
  CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_8);
  CLK_HSICmd(ENABLE);
  while (((CLK->ICKCR)& 0x02)!=0x02);
  CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_HSI);
  CLK_SYSCLKSourceSwitchCmd(ENABLE);
  while (((CLK->SWCR)& 0x01)==0x01);
  delay_ms(100);
}
Exemplo n.º 4
0
/**
  * @brief  Automatic test current in low power mode
  * @caller auto_test
  * @param None
  * @retval None
  */
void test_icc_LP(void)
{
  uint16_t icc_test;
  
  LCD_GLASS_DisplayString("LP");
  delay_ms(200);
  
  /* Current value measured in low power mode*/	
  icc_test = (int)Icc_measure_LPR();
  delay_ms(200);

  /* Test if value is correct */  
  if ((icc_test>ICC_LP_MAX) || (icc_test<ICC_LP_MIN))
  {
  /* check in twice measurements*/
    delay_ms(400);
    icc_test = (int)Icc_measure_LPR();
    delay_ms(200);			
      
	/* Test if value is correct */
    if ((icc_test>ICC_LP_MAX) || (icc_test<ICC_LP_MIN))
    {
      while(1)
      {
        LCD_GLASS_ScrollSentence("LP Not OK ",1,SCROLL_SPEED); //press reset for exit
        KeyPressed = FALSE;
      }
    }
  }
  
  LCD_GLASS_DisplayString("LP OK");
  delay_ms(200);
}
Exemplo n.º 5
0
/**
  * @brief  Automatic test current in HALT Mode
  * @caller auto_test
  * @param None
  * @retval None
  */
void test_icc_HALT(void)
{
  uint16_t icc_test;
  
  LCD_GLASS_DisplayString("HALT");
  delay_ms(200);
  
  /* Current value measured in Halt mode*/	
  icc_test = (int)Icc_measure_HALT();
  delay_ms(200);
  
  /* Test if value is correct */
  if ((icc_test>ICC_HALT_MAX) || (icc_test<ICC_HALT_MIN))
  {
    delay_ms(400);	
    icc_test = (int)Icc_measure_HALT();
    delay_ms(200);		
    
  /* Test if value is correct */
    if ((icc_test>ICC_HALT_MAX) || (icc_test<ICC_HALT_MIN))
    {
      while (1)
      {
        LCD_GLASS_ScrollSentence("ICC HALT Not OK ",1,SCROLL_SPEED); //Press reset for exit
        KeyPressed = FALSE;
      }
    }
  }
  
  LCD_GLASS_DisplayString("HALTOK");
  delay_ms(200);
}
Exemplo n.º 6
0
/**
  * @brief  Automatic test current in Run Mode
  * @caller auto_test
  * @param None
  * @retval None
  */ 
void test_icc_Run(void)
{
  uint16_t icc_test;
  
  LCD_GLASS_DisplayString("RUN");
  delay_ms(200);
  
  icc_test = (int)Icc_measure_RUN();
  delay_ms(200);
  
  if ((icc_test>ICC_RUN_MAX) || (icc_test<ICC_RUN_MIN))
  {
    while (1)
    {
      LCD_GLASS_ScrollSentence("RUN Not OK ",1,SCROLL_SPEED); //Press reset for exit
      KeyPressed = FALSE;
    }
  }

  LCD_GLASS_DisplayString("RUN OK");
  delay_ms(200);
}
Exemplo n.º 7
0
/**
  * @brief  automatic test for VDD
  * @caller auto_test
  * @param None
  * @retval None
  */
void test_vdd(void)
{
  uint16_t vdd_test;
  
  LCD_GLASS_DisplayString("VDD");
  delay_ms(200);
  
  vdd_test = (int)Vref_measure();
  delay_ms(200);
  
  /* Test if value is correct */	
  if ((vdd_test>VCC_MAX) || (vdd_test<VCC_MIN))
  {
    while(1)
    {
      LCD_GLASS_ScrollSentence("VDD Not OK ",1,SCROLL_SPEED); //Press reset for exit
      KeyPressed = FALSE;
    }
  }
  
  LCD_GLASS_DisplayString("VDD OK");
  delay_ms(200);
}
int main(void)
{

    /*!< At this stage the microcontroller clock setting is already configured,
          this is done through SystemInit() function which is called from startup
          file (startup_stm32l1xx_md.s) before to branch to application main.
          To reconfigure the default setting of SystemInit() function, refer to
          system_stm32l1xx.c file
        */

    /* Configure Clocks for Application need */
    RCC_Configuration();

    /* Configure RTC Clocks */
    RTC_Configuration();

    /* Set internal voltage regulator to 1.8V */
    PWR_VoltageScalingConfig(PWR_VoltageScaling_Range1);

    /* Wait Until the Voltage Regulator is ready */
    while (PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET) ;

    /* Enable debug features in low power modes (Sleep, STOP and STANDBY) */
#ifdef  DEBUG_SWD_PIN
    DBGMCU_Config(DBGMCU_SLEEP | DBGMCU_STOP | DBGMCU_STANDBY, ENABLE);
#endif

    /* Configure SysTick IRQ and SysTick Timer to generate interrupts */
    RCC_GetClocksFreq(&RCC_Clocks);
    SysTick_Config(RCC_Clocks.HCLK_Frequency / 500);

    /* Init I/O ports */
    Init_GPIOs();

    /* Initializes the LCD glass */
    LCD_GLASS_Configure_GPIO();
    LCD_GLASS_Init();

    /* Display Welcome message */

    LCD_GLASS_ScrollSentence("   ** TEMPERATURE SENSOR EXAMPLE **    ",1,SCROLL_SPEED);

    /* Disable SysTick IRQ and SysTick Timer */
    SysTick->CTRL  &= ~ ( SysTick_CTRL_TICKINT_Msk | SysTick_CTRL_ENABLE_Msk );

    /* Test user or factory temperature sensor calibration value */
    if ( testFactoryCalibData() == SUCCESS ) getFactoryTSCalibData(&calibdata);
    else if ( testUserCalibData() == SUCCESS ) calibdata = *USER_CALIB_DATA;
    else {
        /* User calibration or factory calibration TS data are not available */
        calibdata.TS_CAL_1 = DEFAULT_COLD_VAL;
        calibdata.TS_CAL_2 = DEFAULT_HOT_VAL;
        writeCalibData(&calibdata);
        calibdata = *USER_CALIB_DATA;
    }

    /* Configure Wakeup from sleep using RTC event*/
    configureWakeup();

    /* Configure direct memory access for ADC usage*/
    configureDMA();

    /* Configure ADC for temperature sensor value conversion */
    configureADC_Temp();


    while(1) {

        /* Re-enable DMA and ADC conf and start Temperature Data acquisition */
        acquireTemperatureData();

        /* Stay in SLEEP mode untill the data are acquired by ADC */
        __WFI();

        /* for DEBUG purpose uncomment the following line and comment the __WFI call to do not enter STOP mode */
        // while (!flag_ADCDMA_TransferComplete);

        /* Disable ADC, DMA and clock*/
        powerDownADC_Temper();

        /* Process mesured Temperature data - calculate average temperature value in °C */
        processTempData();

        if (flag_UserButton == TRUE) {
            clearUserButtonFlag();
            if (CurrentlyDisplayed == Display_TemperatureDegC)
                CurrentlyDisplayed = Display_ADCval;
            else
                CurrentlyDisplayed = Display_TemperatureDegC;
        }

        if (CurrentlyDisplayed == Display_TemperatureDegC) {
            /* print average temperature value in °C  */
            sprintf(strDisp, "%d °C", temperature_C );
        } else {
            /* print result of ADC conversion  */
            sprintf(strDisp, "> %d", tempAVG );
        }

        LCD_GLASS_Clear();
        LCD_GLASS_DisplayString( (unsigned char *) strDisp );

        /* Enable RTC Wakeup */
        RTC_WakeUpCmd(ENABLE);

        /* Clear WakeUp flag */
        PWR_ClearFlag(PWR_FLAG_WU);

        /* Enter in wait for interrupt stop mode*/
        PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI);

        RCC_Configuration();  // reinitialize clock

        /* After Wake up : Disable Wake up from RTC*/
        RTC_WakeUpCmd(DISABLE);
    }

}