Example #1
0
/**
 * @brief  Configures MCU GPIO and EXTI Line for SPIRIT GPIOs.
 * @param  xGpio Specifies the GPIO to be configured.
 *         This parameter can be one of following parameters:
 *         @arg M2S_GPIO_0: SPIRIT GPIO_0
 *         @arg M2S_GPIO_1: SPIRIT GPIO_1
 *         @arg M2S_GPIO_2: SPIRIT GPIO_2
 *         @arg M2S_GPIO_3: SPIRIT GPIO_3
 *         @arg M2S_GPIO_SDN: SPIRIT GPIO_SDN
 * @param  xGpioMode Specifies GPIO mode.
 *         This parameter can be one of following parameters:
 *         @arg M2S_MODE_GPIO_IN: MCU GPIO will be used as simple input.
 *         @arg M2S_MODE_EXTI_IN: MCU GPIO will be connected to EXTI line with interrupt
 *         generation capability.
 *         @arg M2S_MODE_GPIO_OUT: MCU GPIO will be used as simple output.
 * @retval None.
 */
void SdkEvalM2SGpioInit(M2SGpioPin xGpio, M2SGpioMode xGpioMode)
{
  GPIO_TypeDef GPIO_Type;
  GPIO_Mode_TypeDef GPIO_Mode;

  /* Check the parameters */
  assert_param(IS_M2S_GPIO_PIN(xGpio));
  assert_param(IS_M2S_GPIO_MODE(xGpioMode));
  
  /* Configures MCU GPIO */
  if(xGpioMode == M2S_MODE_GPIO_OUT)
  {
    GPIO_Mode = GPIO_Mode_Out_PP_High_Fast;
  }
  else
    if(xGpioMode == M2S_MODE_GPIO_IN)
    {
    GPIO_Mode = GPIO_Mode_In_FL_No_IT;
    }
  else
    if(xGpioMode == M2S_MODE_EXTI_IN)
  {
    GPIO_Mode = GPIO_Mode_In_FL_IT;
    EXTI_SetPinSensitivity(s_vectnM2SGpioLine[xGpio], EXTI_Trigger_Falling);
  }
 
  GPIO_Init(vectpxM2SGpioPort[xGpio], s_vectnM2SGpioPin[xGpio], GPIO_Mode);
    
}
/*
 *******************************************************************************
 *                                 FUNCTIONS
 *******************************************************************************
 */
void HalIRSensorInit(void)
{
  //GPIO_Init(GPIOB, GPIO_Pin_1, GPIO_Mode_Out_PP_High_Slow);  // 红外模块的使能(暂时被硬件取代)
  GPIO_Init(GPIOB, GPIO_Pin_1, GPIO_Mode_Out_PP_Low_Slow);     // 不使用的情况下使用低功耗模式

  GPIO_Init(GPIOB, GPIO_Pin_0, GPIO_Mode_In_FL_IT);
  EXTI_SetPinSensitivity(EXTI_Pin_0, EXTI_Trigger_Rising);
}
/***********************************************************************
  * @brief  Initialize AT88SC102 for IC card insert
  * @param  None
  * @retval None
************************************************************************/
void SLE4442_Init(void)
{
	#ifdef SLE4442_DEBUG
		printf("\r\n[IC] SLE4442_Init...\r\n");
	#endif
#if 0
    /* Disable interrupts */
	disableInterrupts();

	GPIO_Init(GPIO_PORT_IC_CARD_RST, GPIO_PIN_IC_CARD_RST, GPIO_Mode_Out_OD_Low_Fast);
	SLE4442_I2C_Init();
	
	GPIO_Init(GPIO_PORT_IC_CARD_BIT, GPIO_PIN_IC_CARD_BIT, GPIO_Mode_In_FL_IT);
    EXTI_SetPinSensitivity(EXTI_PIN_IC_CARD_BIT, EXTI_Trigger_IC_CARD_BIT);
	
	/* Enable interrupts */
	enableInterrupts();
	EXTI_ClearITPendingBit(EXTI_IT_PIN_IC_CARD_BIT);
#else
	GPIO_Init(GPIO_PORT_IC_CARD_PGM, GPIO_PIN_IC_CARD_PGM, GPIO_Mode_Out_PP_Low_Fast);
	GPIO_Init(GPIO_PORT_IC_CARD_PW, GPIO_PIN_IC_CARD_PW, GPIO_Mode_Out_PP_High_Fast);
	GPIO_Init(GPIO_PORT_IC_CARD_PRE, GPIO_PIN_IC_CARD_PRE, GPIO_Mode_Out_PP_Low_Fast);
	GPIO_Init(GPIO_PORT_IC_CARD_RST, GPIO_PIN_IC_CARD_RST, GPIO_Mode_Out_PP_Low_Fast);
	GPIO_Init(GPIO_PORT_IC_CARD_CLK, GPIO_PIN_IC_CARD_CLK, GPIO_Mode_Out_PP_Low_Fast);
	GPIO_Init(GPIO_PORT_IC_CARD_IO, GPIO_PIN_IC_CARD_IO, GPIO_Mode_Out_PP_Low_Fast);

	/* Disable interrupts */
	disableInterrupts();

	GPIO_Init(GPIO_PORT_IC_CARD_BIT, GPIO_PIN_IC_CARD_BIT, GPIO_Mode_In_PU_IT);
    EXTI_SetPinSensitivity(EXTI_PIN_IC_CARD_BIT, EXTI_Trigger_IC_CARD_BIT);

	EXTI_ClearITPendingBit(EXTI_IT_PIN_IC_CARD_BIT);
	
	/* Enable interrupts */
	enableInterrupts();
#endif
}
Example #4
0
/**
  * @brief  Configures Button GPIO and EXTI Line.
  * @param  Button: Specifies the Button to be configured.
  *   This parameter can be one of following parameters:
  *     @arg BUTTON_KEY: Key Push Button
  *     @arg BUTTON_RIGHT: Joystick Right Push Button
  *     @arg BUTTON_LEFT: Joystick Left Push Button
  *     @arg BUTTON_UP: Joystick Up Push Button
  *     @arg BUTTON_DOWN: Joystick Down Push Button
  *     @arg BUTTON_SEL: Joystick Sel Push Button
  * @param  Button_Mode: Specifies Button mode.
  *   This parameter can be one of following parameters:
  *     @arg BUTTON_MODE_GPIO: Button will be used as simple IO
  *     @arg BUTTON_MODE_EXTI: Button will be connected to EXTI pin (sensitive to falling trigger)
  * @retval None
  */
void STM_EVAL_PBInit(Button_TypeDef Button, ButtonMode_TypeDef Button_Mode)
{

  if (Button_Mode == BUTTON_MODE_EXTI)
  { /* Pin configured in input floating mode with interrupt enabled
                       --> connected to EXTIx Interrupt, where x:0..7 */
    GPIO_Init(BUTTON_PORT[Button], BUTTON_PIN[Button], GPIO_Mode_In_FL_IT);
    EXTI_SetPinSensitivity((EXTI_Pin_TypeDef)BUTTON_EXTI[(uint8_t)Button], EXTI_Trigger_Falling);
  }
  else
  { /* Pin configured in input floating mode with interrupt disabled */
    GPIO_Init(BUTTON_PORT[Button], BUTTON_PIN[Button], GPIO_Mode_In_FL_No_IT);
  }
}
Example #5
0
void _Device_Uart_Disable(void){

    Usart_Peripheral_Flag &= ~fUart_Enable;


    Interrupt_USART1_ReceiveData_ptr_fuc = Empty_USART1_fun;

    /* disable the USART Receive interrupt: this interrupt is generated when the USART
    receive data register is not empty */
    USART_ITConfig(USART1, USART_IT_RXNE, DISABLE);

    /* disable the USART Transmit complete interrupt: this interrupt is generated when the USART
    transmit Shift Register is empty */
    USART_ITConfig(USART1, USART_IT_TC, DISABLE);

    /* disable USART */
    USART_Cmd(USART1, DISABLE);

    /* disable USART1 clock */
    CLK_PeripheralClockConfig(CLK_Peripheral_USART1, DISABLE);

    USART_DeInit(USART1);


#if defined(_USE_PHOTO_ISOALTOR_FOR_COMMUNICATION_)
    //set as floating pin
	//GPIO_Init(USART_RX_PORT, USART_RX_PIN, GPIO_Mode_In_FL_No_IT);  // Input floating, no external interrupt
	GPIO_Init(USART_TX_PORT, USART_TX_PIN, GPIO_Mode_In_FL_No_IT);  // Input floating, no external interrupt

	GPIO_Init(USART_RX_PORT, USART_RX_PIN, GPIO_Mode_In_PU_IT);  // Input pull-up, external interrupt
	//GPIO_Init(USART_TX_PORT, USART_TX_PIN, GPIO_Mode_In_PU_IT);  // Input pull-up, external interrupt
#else
    //for low power setting and save power
	//GPIO_Init(USART_RX_PORT, USART_RX_PIN, GPIO_Mode_Out_PP_Low_Slow);  // set as output and PP Low level
	GPIO_Init(USART_TX_PORT, USART_TX_PIN, GPIO_Mode_Out_PP_Low_Slow);  // set as output and PP Low level

	GPIO_Init(USART_RX_PORT, USART_RX_PIN, GPIO_Mode_In_PU_IT);  // Input pull-up, external interrupt
#endif

	/* Initialize the Interrupt sensitivity */
    EXTI_SetPinSensitivity(USART_RX_EXTI_PIN, EXTI_Trigger_Falling);  /*!< Interrupt on Falling edge only */

    _Device_delay_cycles(15);     //100 = 1ms at CCLK=4MHz, 15 ~= 150 us
    Usart_Peripheral_Flag |= fUart_RX_IT_Enable;
    Usart_Peripheral_Flag &= ~fUart_RX_IT_Received; //clear reveived status

    SendingWhileTimeOutCount = 0;


}
Example #6
0
void KEY_Init(void)
{
	#ifdef KEY_DEBUG
		printf("[KEY] KEY_Init...\r\n");
	#endif
	
	/* Disable interrupts */
	disableInterrupts();
	
	GPIO_Init(GPIO_PORT_KEY, GPIO_PIN_KEY, GPIO_Mode_In_FL_IT);
    EXTI_SetPinSensitivity(EXTI_PIN_KEY, EXTI_Trigger_KEY);
	
	EXTI_ClearITPendingBit(EXTI_IT_PIN_KEY);
	
	/* Enable interrupts */
	enableInterrupts();
}
Example #7
0
void Config()
{
  //System clock at power up is HSI/8 = 16MHz/8 = 2MHz
  //CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_1);  //set HSI/4 = 4MHz SysClk to Core and Memory, minimum clock = 125KHz for CLK_SYSCLKDiv_128
  //PWR_PVDCmd(ENABLE);  //Power voltage detector and brownout Reset unit supply current 2,6uA
  //PWR_PVDLevelConfig(PWR_PVDLevel_2V26); //set Programmable voltage detector threshold to 2,26V
  //PWR_GetFlagStatus(PWR_FLAG_PVDOF);  //checks whether the specified PWR flag is set or not
  
  //Configure external interrupts - BTN1 and BTN2 presses
  EXTI_SetPinSensitivity(EXTI_Pin_0, EXTI_Trigger_Falling_Low);
  //EXTI_SetPinSensitivity(EXTI_Pin_4, EXTI_Trigger_Falling_Low);
  //EXTI_SelectPort(EXTI_Port_B);
  //EXTI_SetHalfPortSelection(EXTI_HalfPort_B_MSB, ENABLE);
  
  
  
  /* SPI configuration */
  CLK_PeripheralClockConfig(CLK_Peripheral_SPI1, ENABLE);
  SPI_Init(SPI1, SPI_FirstBit_MSB, SPI_BaudRatePrescaler_2, SPI_Mode_Master, SPI_CPOL_Low, SPI_CPHA_1Edge, SPI_Direction_2Lines_FullDuplex, SPI_NSS_Soft, 0);
  SPI_Cmd(SPI1, ENABLE);
  
  /* Output PP High - bicolor LED to GND */
  GPIO_Init(LED_PORT, LED_PIN1, GPIO_Mode_Out_PP_Low_Slow);
  GPIO_Init(LED_PORT, LED_PIN2, GPIO_Mode_Out_PP_Low_Slow);

  /* Input FL IT - onboard Button, external pull-up */
  GPIO_Init(BTN1_PORT, BTN1_PIN, GPIO_Mode_In_FL_IT);
  GPIO_Init(BTN2_PORT, BTN2_PIN, GPIO_Mode_In_FL_IT);
  
  /* nRF24L01+ pins */
  GPIO_Init(NRF_CE_PORT,   NRF_CE_PIN,   GPIO_Mode_Out_PP_Low_Fast);
  GPIO_Init(NRF_CSN_PORT,  NRF_CSN_PIN,  GPIO_Mode_Out_PP_Low_Fast);
  GPIO_Init(NRF_SCK_PORT,  NRF_SCK_PIN,  GPIO_Mode_Out_PP_Low_Fast);
  GPIO_Init(NRF_MOSI_PORT, NRF_MOSI_PIN, GPIO_Mode_Out_PP_Low_Fast);
  GPIO_Init(NRF_ON_PORT,   NRF_ON_PIN,   GPIO_Mode_Out_PP_High_Fast);
  GPIO_Init(NRF_MISO_PORT, NRF_MISO_PIN, GPIO_Mode_In_FL_No_IT);
  GPIO_Init(NRF_IRQ_PORT,  NRF_IRQ_PIN,  GPIO_Mode_In_FL_No_IT);

  NRF_OFF;
  NRF_CE(0);
  NRF_CSN(0);
  //NRF_SCK(0);
  //NRF_MOSI(0);
}
Example #8
0
void cc112x_init(void)
{
    #ifdef CC112x_DEBUG
	    printf("[CC112X] cc112x_init...\r\n");   
	#endif
#if 1
	// Disable interrupts 
	disableInterrupts();
	
	trxRfSpiInterfaceInit();
	
	GPIO_Init(GPIO_PORT_CC112X_TE, GPIO_PIN_CC112X_TE, GPIO_Mode_Out_PP_Low_Fast);
	GPIO_Init(GPIO_PORT_CC112X_RE, GPIO_PIN_CC112X_RE, GPIO_Mode_Out_PP_Low_Fast);
	GPIO_Init(GPIO_PORT_CC112X_RESET, GPIO_PIN_CC112X_RESET, GPIO_Mode_Out_PP_Low_Fast);
	GPIO_Init(GPIO_PORT_CC112X_GPIO2, GPIO_PIN_CC112X_GPIO2, GPIO_Mode_Out_PP_Low_Fast);
	GPIO_Init(GPIO_PORT_CC112X_GPIO3, GPIO_PIN_CC112X_GPIO3, GPIO_Mode_Out_PP_Low_Fast);

	GPIO_Init(GPIO_PORT_CC112X_GPIO0, GPIO_PIN_CC112X_GPIO0, GPIO_Mode_In_FL_IT);
    EXTI_SetPinSensitivity(EXTI_PIN_CC112X_GPIO0, EXTI_Trigger_CC112X_GPIO0);

	//GPIO_Init(GPIO_PORT_CC112X_GPIO2, GPIO_PIN_CC112X_GPIO2, GPIO_Mode_In_FL_IT);
    //EXTI_SetPinSensitivity(EXTI_PIN_CC112X_GPIO2, EXTI_Trigger_CC112X_GPIO2);
	
	// Enable interrupts 
	enableInterrupts();
	EXTI_ClearITPendingBit(EXTI_IT_PIN_CC112X_GPIO0);
	//EXTI_ClearITPendingBit(EXTI_IT_PIN_CC112X_GPIO2);
#else	

	GPIO_Init(GPIO_PORT_CC112X_TE, GPIO_PIN_CC112X_TE, GPIO_Mode_Out_PP_Low_Fast);
	GPIO_Init(GPIO_PORT_CC112X_RE, GPIO_PIN_CC112X_RE, GPIO_Mode_Out_PP_Low_Fast);
	GPIO_Init(GPIO_PORT_CC112X_RESET, GPIO_PIN_CC112X_RESET, GPIO_Mode_Out_PP_Low_Fast);
	GPIO_Init(GPIO_PORT_CC112X_GPIO2, GPIO_PIN_CC112X_GPIO2, GPIO_Mode_Out_PP_Low_Fast);
	GPIO_Init(GPIO_PORT_CC112X_GPIO3, GPIO_PIN_CC112X_GPIO3, GPIO_Mode_Out_PP_Low_Fast);
	GPIO_Init(GPIO_PORT_CC112X_GPIO0, GPIO_PIN_CC112X_GPIO0, GPIO_Mode_Out_PP_Low_Fast);

	GPIO_Init(GPIO_PORT_CC112X_SPI_NSS, GPIO_PIN_CC112X_SPI_NSS, GPIO_Mode_Out_PP_Low_Fast);
	GPIO_Init(GPIO_PORT_CC112X_SPI_SCK, GPIO_PIN_CC112X_SPI_SCK, GPIO_Mode_Out_PP_Low_Fast);
	GPIO_Init(GPIO_PORT_CC112X_SPI_MOSI, GPIO_PIN_CC112X_SPI_MOSI, GPIO_Mode_Out_PP_Low_Fast);
	GPIO_Init(GPIO_PORT_CC112X_SPI_MISO, GPIO_PIN_CC112X_SPI_MISO, GPIO_Mode_Out_PP_Low_Fast);
#endif
	
}
Example #9
0
void Config()
{
  //System clock at power up is HSI/8 = 16MHz/8 = 2MHz
  //CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_1);  //set HSI/4 = 4MHz SysClk to Core and Memory, minimum clock = 125KHz for CLK_SYSCLKDiv_128
  //PWR_PVDCmd(ENABLE);  //Power voltage detector and brownout Reset unit supply current 2,6uA
  //PWR_PVDLevelConfig(PWR_PVDLevel_2V26); //set Programmable voltage detector threshold to 2,26V
  //PWR_GetFlagStatus(PWR_FLAG_PVDOF);  //checks whether the specified PWR flag is set or not
  
  //Configure external interrupts - BTN1 and BTN2 presses
  EXTI_SetPinSensitivity(EXTI_Pin_0, EXTI_Trigger_Falling_Low);
  //EXTI_SetPinSensitivity(EXTI_Pin_4, EXTI_Trigger_Falling_Low);
  //EXTI_SelectPort(EXTI_Port_B);
  //EXTI_SetHalfPortSelection(EXTI_HalfPort_B_MSB, ENABLE);

  /* Input FL IT - onboard Button, external pull-up */
  GPIO_Init(BTN1_PORT, BTN1_PIN, GPIO_Mode_In_FL_IT);
  GPIO_Init(BTN2_PORT, BTN2_PIN, GPIO_Mode_In_FL_IT);

  // Timer 3 Configuration
  CLK_PeripheralClockConfig(CLK_Peripheral_TIM3, ENABLE);
  TIM3_TimeBaseInit(TIM3_Prescaler_2, TIM3_CounterMode_Up, 700); // 1MHz timer clock
  TIM3_OC1Init(TIM3_OCMode_PWM1,
               TIM3_OutputState_Enable,
               350,
               TIM3_OCPolarity_Low,
               TIM3_OCIdleState_Reset);
  TIM3_ARRPreloadConfig(ENABLE);
  TIM3_OC1PreloadConfig(ENABLE);
  TIM3_CtrlPWMOutputs(ENABLE);
  TIM3_Cmd(DISABLE);
  
  /* RFM85W pins */
  GPIO_Init(RFM_DATA_PORT, RFM_DATA_PIN, GPIO_Mode_Out_PP_Low_Fast);
  GPIO_Init(RFM_ON_PORT,   RFM_ON_PIN,   GPIO_Mode_Out_PP_Low_Fast);
  
  /* Output PP High - bicolor LED to GND */
  GPIO_Init(LED_PORT, LED_PIN1, GPIO_Mode_Out_PP_Low_Slow);
  GPIO_Init(LED_PORT, LED_PIN2, GPIO_Mode_Out_PP_Low_Slow);

  RFM_OFF;
  //RFM_DATA(0);
}
Example #10
0
void main(void)
{
    deInitClock();
    deInitGPIO();

    CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_HSI);
    CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_16);

    initDigitalControls();
    initAnalogControls();

    GPIO_Init(GPIOF, GPIO_Pin_0, GPIO_Mode_In_FL_IT);
    EXTI_SetPinSensitivity(EXTI_Pin_0, EXTI_Trigger_Rising);

    enableInterrupts();
    initMemory();

    while (1)
    {
        halt();
    }
}
Example #11
0
/**
  * @brief main entry point.
  * @par Parameters None
  * @retval void None
  * @par Required preconditions: None
  */
void main(void)
{ 
uint8_t PayloadLength,
				data_sensor,
				*bufMessage;
		
	/* deinit I/O ports */
	DeInitClock();
	DeInitGPIO();
	
	/* Select HSI as system clock source */
	#ifdef USE_HSI
		CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_HSI);
		CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_16);	
	 #else
		CLK_SYSCLKSourceSwitchCmd(ENABLE);
		/* Select 2MHz HSE as system clock source */
		CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_HSE);
		CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_4);	
		CLK_HSICmd(DISABLE);
	#endif

	// Initializes the LCD glass 
  LCD_GLASS_Init();

	
	/* LED button init: GPIO set in push pull */
	GPIO_Init( LED_GPIO_PORT, LED_GPIO_PIN, GPIO_Mode_Out_PP_Low_Fast);
	// set to 0 
	GPIOE->ODR &= ~LED_GPIO_PIN;
	
	/* USER button init: GPIO set in input interrupt active mode */
  GPIO_Init( BUTTON_GPIO_PORT, USER_GPIO_PIN, GPIO_Mode_In_FL_IT);
	EXTI_SetPinSensitivity(EXTI_Pin_7, EXTI_Trigger_Falling);

  //* Init Bar on LCD all are OFF
  BAR0_OFF;
  BAR1_OFF;
  BAR2_OFF;
  BAR3_OFF;	
	
	enableInterrupts();
	
  
  //* At power on VDD diplays 
	bufMessage = NDEFmessage;
	
	if (EEMenuState > STATE_TEMPMEAS) 
		EEMenuState = STATE_CHECKNDEFMESSAGE;
		
	FLASH_Unlock(FLASH_MemType_Data );
	
	state_machine = EEMenuState ; 
	
	delayLFO_ms (1);
	
	if (EEInitial == 0)
	{
			User_WriteFirmwareVersion ();
			EEInitial =1;
	}
	
  while (1)
  {
    
    switch (state_machine)
    {
			  
				case STATE_VREF:
					// measure the voltage available at the output of the M24LR04E-R
					Vref_measure();

					delayLFO_ms (2);
        break;
			
        case STATE_CHECKNDEFMESSAGE:
				
						// read the NDEF message from the M24LR04E-R EEPROM and display it if it is found 				
					if (User_ReadNDEFMessage (&PayloadLength) == SUCCESS)						
						User_DisplayMessage (bufMessage,PayloadLength);
	//					User_DisplayMessageActiveHaltMode (PayloadLength);
					else 
						User_DisplayMessage((uint8_t*)ErrorMessage,20);		
		
					
	
        break;
				
				case STATE_TEMPMEAS:
						
						// read the ambiant tempserature from the STTS751
						User_GetOneTemperature (&data_sensor);
						// display the temperature
						User_DisplayOneTemperature (data_sensor);
			
						delayLFO_ms (2);
						
				break;
			
			break;
  
        /* for safe: normaly never reaches */ 			
        default:
					LCD_GLASS_Clear();
					LCD_GLASS_DisplayString("Error");
					state_machine = STATE_VREF;
        break;
      }
    
		
    }
}	
Example #12
0
void main(void)
{
  /*----------IO口设置----------*/
  GPIO_Init(ADDR_LOW_PORT, GPIO_Pin_All, GPIO_Mode_Out_PP_Low_Slow);        //8位地址
  
  GPIO_Init(ADDR_HIGH_PORT0, ADDR_HIGH_PIN0, GPIO_Mode_Out_PP_Low_Slow);    //未使用口设置为输出低电平
  
  //P1.3/mode0 - 模块输入睡眠,stm8输出睡眠
  GPIO_Init( MODE0_PORT, MODE0_PIN, GPIO_Mode_Out_PP_Low_Slow);
  
  //P1.5/mode1 - 模块输出睡眠,stm8输入睡眠
  //Zigbee透传模块输出给stm8的唤醒信号为高电平,并在10ms后开始发送串口信号
  //由于stm8输入无内部下拉选项,因此只能设置为浮动输入
  //当不接Zigbee模块单独进行stm8程序调试时,浮动输入将可能导致持续发生中断,所以请务必接入Zigbee模块或在不接入模块时改为输入上拉
  GPIO_Init( MODE1_PORT, MODE1_PIN, GPIO_Mode_In_FL_IT);
  EXTI_SetPinSensitivity(EXTI_Pin_3, EXTI_Trigger_Rising);
  
  GPIO_Init(SENSOR_DATA_PORT, SENSOR_DATA_PIN, GPIO_Mode_Out_PP_High_Fast);   //传感器数据口拉高
  //等效为如下配置
  //SENSOR_DATA_PORT->ODR |= SENSOR_DATA_PIN;   //输出高电平
  //SENSOR_DATA_PORT->CR1 |= SENSOR_DATA_PIN;   //推挽输出
  //SENSOR_DATA_PORT->CR2 &= (uint8_t)(~(SENSOR_DATA_PIN));   //10MHz高速输出
  //SENSOR_DATA_PORT->DDR |= SENSOR_DATA_PIN;   //设置为输出
  
  //GPIO_Init(SENSOR_DATA_PORT, SENSOR_DATA_PIN, GPIO_Mode_In_PU_No_IT);   //传感器数据口输入上拉无中断
  //等效为如下配置
  //SENSOR_DATA_PORT->ODR |= SENSOR_DATA_PIN;   //输出高电平,此项在输入时无关紧要
  //SENSOR_DATA_PORT->CR1 |= SENSOR_DATA_PIN;   //输入上拉
  //SENSOR_DATA_PORT->CR2 &= (uint8_t)(~(SENSOR_DATA_PIN));   //无中断
  //SENSOR_DATA_PORT->DDR &= (uint8_t)(~(SENSOR_DATA_PIN));   //设置为输入
  //由此可见,当进行18B20的单总线输入输出切换时,只需要最后一行配置DDR即可以高速切换,这样就可以精确控制时间
  
  
  /*----------系统周期设置与内部模块使能----------*/
  CLK_DeInit();
  CLK_PeripheralClockConfig(CLK_Peripheral_AWU, ENABLE);      //使能唤醒
  CLK_MasterPrescalerConfig(CLK_MasterPrescaler_HSIDiv8);     //时钟8分频,2MHz
  
  
  /*----------唤醒初始化----------*/
  AWU_DeInit();
  
  
  /*----------串口初始化----------*/
  CLK_PeripheralClockConfig(CLK_Peripheral_USART, ENABLE);   //使能串口
  GPIO_ExternalPullUpConfig(GPIOC,GPIO_Pin_2|GPIO_Pin_3, ENABLE);   //拉高电平
  USART_DeInit();
  USART_Init(115200,                            //波特率115200
            USART_WordLength_8D,                //8位数据位
            USART_StopBits_1,                   //1位停止位
            USART_Parity_No,                    //无校验
            USART_Mode_Rx | USART_Mode_Tx);     //接收和发送使能
  //USART_ITConfig(USART_IT_TXE, ENABLE);         //使能发送中断
  USART_Cmd(ENABLE);    //串口开始工作
  
  
  /*----------看门狗初始化----------*/
  //注意!!看门狗的最长喂狗时限仅1~2秒,而本程序中单片机休眠时间最长设置为30秒
  //所以需要将Option Byte中的OPT4由默认的0x00改为0x01,以使休眠时看门狗暂停
  //Option Byte无法在程序中修改,只能通过烧写软件如STVP在烧写时由SWIM协议外部写入
  //因此在调试时看门狗功能无法实现
  //由SWIM外部烧写时请自行宏定义WATCHDOG以使看门狗生效
#ifdef  WATCHDOG
  IWDG_Enable();
  IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);
  IWDG_SetPrescaler(IWDG_Prescaler_256);    //看门狗时限设为最长的1724.63ms
  IWDG_SetReload(0xFF);
  IWDG_ReloadCounter();
#endif
  
  
  /*----------以下进行Zigbee串口透传模块地址的设置----------*/
  //我们以STM8L 96bit唯一序列号中的8bit作为地址低位,地址高3bit放空为0x000,实际应用中可以采用拨码开关等方式进行设定
  //注意!如果采用IO口设置地址,IO口电平很大程度将影响设备功耗,为此做如下考虑
  //Zigbee串口透传模块的输入为内部下拉,如STM8L长期将IO口置于高电平将有近毫安级的电流损耗
  //因此Zigbee模块在开机后1秒时读入IO口设置地址,其余时间应将IO口置于低电平以降低功耗(见模块手册)
  //对于STM8L而言应在开机时设置地址IO口,并在0.5秒后将IO口恢复低电平
  //如采用拨码设置地址的方式,则首先应拨好设置地址,然后上电,并在0.5秒后将开关拨回至0
  
  //如果采用串口设置地址模式,则将地址设置IO口全部下拉,写入串口设置地址值后重启模块即可以完成地址设置
  
  AddrHi=0;   //地址高位置0  注意!!本程序放空了模块地址高位设置口,故地址高位为0,如需改为自己的程序请记得设置该地址并在下面的程序中设置对应的地址IO
  FLASH_SetProgrammingTime(FLASH_ProgramTime_Standard);
  FLASH_Unlock(FLASH_MemType_Program);
  //AddrLo=FLASH_ReadByte(0x4926);    //采用X-coordinator
  AddrLo=FLASH_ReadByte(0x4928);    //采用Y-coordinator
  //AddrLo=(FLASH_ReadByte(0x4926)<<4) | (FLASH_ReadByte(0x4928)&0x0F);   //X-coordinator和Y-coordinator各占4bit
  FLASH_Lock(FLASH_MemType_Program);
  Addr = ((u16)AddrHi<<8) | AddrLo; //将高低位地址组合成完整地址
  
  //等待模块初始化完成以能响应串口设置命令
  //注意!!这里
  for(u8 i=0; i<6; i++)
  {
    Delay(0xFFFF);    //每个Delay约200ms,总延时1秒以上,这里要有足量等待时间,因为模块上电一段时间后串口才开始工作接收数据
  }
  
#ifndef USE_SEC_ADDR    //未定义使用串口设置方案,则采用IO口设置方案

  //GPIO_Write(ADDR_HIGH_PORT, AddrHi);   //注意!!本程序放空了模块地址高位设置口,所以这里无需再拉IO口,如改为自己的程序请记得设置高位的地址并在此设置IO
  GPIO_Write(ADDR_LOW_PORT, AddrLo);    //写入低8位地址,高3位放空
  for(u8 i=0; i<3; i++)
  {
    Delay(0xFFFF);    //每个Delay约200ms,总延时0.5秒以上,因为在0.5秒时读入地址IO口,之后地址IO口状态不影响地址设置
  }
  //GPIO_Write(ADDR_HIGH_PORT, 0);
  GPIO_Write(ADDR_LOW_PORT, 0x00);    //将地址IO口置回0以降低功耗

#else   //定义了串口设置地址方案,采用串口设置地址

  //采用串口设置地址方式需下拉所有地址IO口使之为0x0000
  //本程序IO口初始化时均为下拉低电平,无需更改电平,注意如果拉高任何地址IO口,则串口地址无效,自动采用IO口所设置的地址
  //GPIO_Write(ADDR_LOW_PORT, 0);   //地址低位写入低电平,初始化已为低电平,无需写入
  //GPIO_Write(ADDR_HIGH_PORT, 0);  //地址高位写入低电平,初始化已为低电平,无需写入
  
  //以下将地址转换为串口设置命令字符串,首先输入设置命令UNI_SEC_ADDR和命令与设置值之间的空格
  UARTSendDataBuf[0]='U';UARTSendDataBuf[1]='N';UARTSendDataBuf[2]='I';UARTSendDataBuf[3]='_';UARTSendDataBuf[4]='S';
  UARTSendDataBuf[5]='E';UARTSendDataBuf[6]='C';UARTSendDataBuf[7]='_';UARTSendDataBuf[8]='A';UARTSendDataBuf[9]='D';
  UARTSendDataBuf[10]='D';UARTSendDataBuf[11]='R';UARTSendDataBuf[12]=' ';
  //然后将13bit地址转换为四字节字符串,如0x0789转化为“1929”,0x0089转化为“0137”,并将值填入UARTSendDataBuf[13]~UARTSendDataBuf[16]
  SettingTemp=Addr;
  for(u8 i=0; i<4; i++)
  {
    UARTSendDataBuf[16-i] = '0' + (SettingTemp % 10);
    SettingTemp /= 10;
  }
  //发送设置地址命令
  UART_Send_Data(UARTSendDataBuf, 17);
  
  Delay(0x3000);    //稍作等待
  
#endif
  
  /*----------以下进行其他参数设置,请在35行处取消需要设置值的#define注释并设置相应值----------*/
  
#ifdef  SETTING_PANID   //PANID设置,注意设置的PANID要与主机和路由器一致才可正常工作
  assert_param(SETTING_PANID>=1 && SETTING_PANID<=65535);
  
  UARTSendDataBuf[0]='P';UARTSendDataBuf[1]='A';UARTSendDataBuf[2]='N';UARTSendDataBuf[3]='I';UARTSendDataBuf[4]='D';
  UARTSendDataBuf[5]=' ';
  //然后将两字节PANID转换为五字节字符串,并将值填入UARTSendDataBuf[6]~UARTSendDataBuf[10]
  SettingTemp=SETTING_PANID;
  for(u8 i=0; i<5; i++)
  {
    UARTSendDataBuf[10-i] = '0' + (SettingTemp % 10);
    SettingTemp /= 10;
  }
  //发送设置命令
  UART_Send_Data(UARTSendDataBuf, 11);
  
  Delay(0x3000);    //稍作等待  
#endif  //SETTING_PANID
  
#ifdef  SETTING_TX_POWER   //TX_POWER发射功率设置
  assert_param(SETTING_TX_POWER>=0 && SETTING_TX_POWER<=21);
  
  UARTSendDataBuf[0]='T';UARTSendDataBuf[1]='X';UARTSendDataBuf[2]='_';UARTSendDataBuf[3]='P';UARTSendDataBuf[4]='O';
  UARTSendDataBuf[5]='W';UARTSendDataBuf[6]='E';UARTSendDataBuf[7]='R';UARTSendDataBuf[8]=' ';
  //然后将TX_POWER转换为两字节字符串,并将值填入UARTSendDataBuf[9]~UARTSendDataBuf[10]
  SettingTemp=SETTING_TX_POWER;
  for(u8 i=0; i<2; i++)
  {
    UARTSendDataBuf[10-i] = '0' + (SettingTemp % 10);
    SettingTemp /= 10;
  }
  //发送设置命令
  UART_Send_Data(UARTSendDataBuf, 11);
  
  Delay(0x3000);    //稍作等待  
#endif  //SETTING_TX_POWER
  
#ifdef  SETTING_CHANNEL   //CHANNEL设置,注意设置的CHANNEL要与主机和路由器一致才可正常工作
  assert_param(SETTING_CHANNEL>=2048 && SETTING_CHANNEL<=134215680);
  
  UARTSendDataBuf[0]='C';UARTSendDataBuf[1]='H';UARTSendDataBuf[2]='A';UARTSendDataBuf[3]='N';UARTSendDataBuf[4]='N';
  UARTSendDataBuf[5]='E';UARTSendDataBuf[6]='L';UARTSendDataBuf[7]=' ';
  //然后将CHANNEL转换为十字节字符串,并将值填入UARTSendDataBuf[8]~UARTSendDataBuf[17]
  SettingTemp=SETTING_CHANNEL;
  for(u8 i=0; i<10; i++)
  {
    UARTSendDataBuf[17-i] = '0' + (SettingTemp % 10);
    SettingTemp /= 10;
  }
  //发送设置命令
  UART_Send_Data(UARTSendDataBuf, 18);
  
  Delay(0x3000);    //稍作等待  
#endif  //SETTING_CHANNEL
  
#ifdef  SETTING_POLL_RATE   //POLL_RATE终端定期唤醒查询数据时限 
  assert_param(SETTING_POLL_RATE>=0 && SETTING_POLL_RATE<=65535);
  
  UARTSendDataBuf[0]='P';UARTSendDataBuf[1]='O';UARTSendDataBuf[2]='L';UARTSendDataBuf[3]='L';UARTSendDataBuf[4]='_';
  UARTSendDataBuf[5]='R';UARTSendDataBuf[6]='A';UARTSendDataBuf[7]='T';UARTSendDataBuf[8]='E';UARTSendDataBuf[9]=' ';
  //然后将POLL_RATE转换为五字节字符串,并将值填入UARTSendDataBuf[10]~UARTSendDataBuf[14]
  SettingTemp=SETTING_POLL_RATE;
  for(u8 i=0; i<5; i++)
  {
    UARTSendDataBuf[14-i] = '0' + (SettingTemp % 10);
    SettingTemp /= 10;
  }
  //发送设置命令
  UART_Send_Data(UARTSendDataBuf, 15);
  
  Delay(0x3000);    //稍作等待  
#endif  //SETTING_POLL_RATE
  
  
  //写入重启模块命令PW_RESET 1
  UARTSendDataBuf[0]='P';UARTSendDataBuf[1]='W';UARTSendDataBuf[2]='_';UARTSendDataBuf[3]='R';UARTSendDataBuf[4]='E';
  UARTSendDataBuf[5]='S';UARTSendDataBuf[6]='E';UARTSendDataBuf[7]='T';UARTSendDataBuf[8]=' ';UARTSendDataBuf[9]='1';
  //发送重启命令
  UART_Send_Data(UARTSendDataBuf, 10);
  
  //等待模块重启,重启0.5秒时读入地址设置IO口为0x0000,进入串口设置地址模式,读取刚才我们串口所设置的地址并工作在该地址
  for(u8 i=0; i<6; i++)
  {
    Delay(0xFFFF);    //每个Delay约200ms,总延时1秒以上,这里要有足量等待时间,因为模块上电一段时间后串口才开始工作接收数据
  }
    
  
  //以下进行18B20采样精度设置
  DS18B20_Init();
  DS18B20_Write(0xCC);  //跳过ROM操作
  DS18B20_Write(0xBE);  //读配置
  //读出TH,TL值以便设置时将其原样写入不进行改变
  Temprature=DS18B20_Read();    //低8位
  Temprature=Temprature | (DS18B20_Read()<<8);  //高8位
  TH=DS18B20_Read();
  TL=DS18B20_Read();
  Config=DS18B20_Read();
  
  DS18B20_Init();
  DS18B20_Write(0xCC);  //跳过ROM操作
  DS18B20_Write(0x4E);  //写配置
  DS18B20_Write(TH);    //原样写入不改变
  DS18B20_Write(TL);    //原样写入不改变
  DS18B20_Write(0x1F);  //采用较低分辨率能大幅降低功耗 1F:9位,93.75ms 3F:10位,187.5ms 5F:11位,375ms 7F:12位,750ms
    
#ifdef UI_STRING    //字符串输出界面
  //格式 ID:1234 T:+025.0
  //0~3,AA XX XX 55,目的地址
  //4~6, 3字节头
  //7~10, 4字节地址
  //11~13, 3字节中
  //14,符号位
  //15~17,整数位
  //18,小数点
  //19,小数位
  //20,1字节尾
  UARTSendDataBuf[0]=0xAA;UARTSendDataBuf[1]=0x00;UARTSendDataBuf[2]=0x00;UARTSendDataBuf[3]=0x55;
  UARTSendDataBuf[4]='I';UARTSendDataBuf[5]='D';UARTSendDataBuf[6]=':';
  //将本机地址转换为十字节字符串,并将值填入UARTSendDataBuf[10]~UARTSendDataBuf[19]
  SettingTemp=Addr;
  for(u8 i=0; i<4; i++)
  {
    UARTSendDataBuf[10-i] = '0' + (SettingTemp % 10);
    SettingTemp /= 10;
  }
  //将头部的所有0替换为空格
  i=7;
  while(UARTSendDataBuf[i]=='0')
  {
    UARTSendDataBuf[i++]=' ';
  }
  UARTSendDataBuf[11]=' ';UARTSendDataBuf[12]='T';UARTSendDataBuf[13]=':';
  UARTSendDataBuf[18]='.';
  UARTSendDataBuf[20]=' ';
#endif


  disableInterrupts();
  
  /* Infinite loop */
  while (1)
  {
#ifdef  WATCHDOG
    IWDG_ReloadCounter();   //喂狗
#endif
    
    if(WakeCount<=0)    //每WORK_TO_WAKE_RATIO次唤醒采集一次传感器数据并上传,之所以采用初值-1这里<=0后面++并%WORK_TO_WAKE_RATIO的方式,是为了在开机时能连采两次使传感器工作正常
    {
      DS18B20_Init();
      DS18B20_Write(0xCC);  //跳过ROM操作
      DS18B20_Write(0x44);  //温度转换
      
      //9位分辨率93.75ms采样时间情况下,进入睡眠128ms,等待18B20采样完成
      //注意!如果提采样高分辨率会延长采样时间,此时应延长睡眠时间使之大于采样时间,否则会出错
      enableInterrupts();
      AWU_Init(AWU_Timebase_128ms);
      AWU_ReInitCounter();
      AWU_Cmd(ENABLE);
      halt();
      disableInterrupts();
      
#ifdef  WATCHDOG
      IWDG_ReloadCounter();   //喂狗
#endif
  
      while(GPIO_ReadInputDataBit(SENSOR_DATA_PORT, SENSOR_DATA_PIN)==RESET);   //如18B20还未采样完成则等待
      
      DS18B20_Init();
      DS18B20_Write(0xCC);  //跳过ROM操作
      DS18B20_Write(0xBE);  //读取RAM
      Temprature=DS18B20_Read();    //低8位
      Temprature=Temprature | (DS18B20_Read()<<8);  //高8位
      TH=DS18B20_Read();
      TL=DS18B20_Read();
      Config=DS18B20_Read();
      DS18B20_Init();       //reset,终止读写其他寄存器
      
#ifndef UI_STRING
      //将采集到的温度数据发送到主机
      UARTSendDataBuf[0]=0xAA;      //4字节目的地址包头,0xAA 目的地址高位 目的地址低位 0x55,主机目的地址高低位均为0x00
      UARTSendDataBuf[1]=0x00;
      UARTSendDataBuf[2]=0x00;
      UARTSendDataBuf[3]=0x55;
      UARTSendDataBuf[4]=AddrHi;    //发送给主机本机地址以方便主机的寻址,地址高位,这里我们放空了地址高位,模块的3位地址高位默认下拉设置为0
      UARTSendDataBuf[5]=AddrLo;    //发送给主机本机地址低位
      UARTSendDataBuf[6]=(u8)(Temprature>>8);     //温度高位
      UARTSendDataBuf[7]=(u8)(Temprature&0x00FF); //温度低位
      UART_Send_Data(UARTSendDataBuf, 8);         //将数据发送到主机
#else
      //字符串格式
      UARTSendDataBuf[14]='+';
      if(Temprature & 0x8000)   //最高位为1,负的,取反加一
      {
        UARTSendDataBuf[14]='-';
        Temprature = (~Temprature)+1;
      }
      //小数部分
      UARTSendDataBuf[19]='0';
      if(Temprature & 0x000F)
      {
        UARTSendDataBuf[19]='5';
      }
      //整数部分
      SettingTemp=Temprature>>4;
      for(u8 i=0; i<3; i++)
      {
        UARTSendDataBuf[17-i] = '0' + (SettingTemp % 10);
        SettingTemp /= 10;
      }
      UART_Send_Data(UARTSendDataBuf, 21);         //将数据发送到主机
#endif
    }

#ifdef  WATCHDOG
    IWDG_ReloadCounter();   //喂狗
#endif
    
    WakeCount++;
    WakeCount = WakeCount % WORK_TO_WAKE_RATIO;   //每WORK_TO_WAKE_RATIO次唤醒采集一次传感器数据并上传(约WORK_TO_WAKE_RATIO*30秒采集上传一次)

    enableInterrupts();
    AWU_Init(AWU_Timebase_30s);   //30秒睡眠,注意!!实测睡眠时间误差较大
    AWU_ReInitCounter();
    AWU_Cmd(ENABLE);
    halt();
    disableInterrupts();
    
  }
Example #13
0
/**
  * @brief main entry point.
  * @par Parameters None
  * @retval void None
  * @par Required preconditions: None
  */
void main(void)
{ 
uint8_t PayloadLength,
				data_sensor,
				*bufMessage;
		
	/* deinit I/O ports */
	DeInitClock();
	DeInitGPIO();
	
	/* Select HSI as system clock source */
	#ifdef USE_HSI
		CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_HSI);
		CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_16);	
	 #else
		CLK_SYSCLKSourceSwitchCmd(ENABLE);
		/* Select 2MHz HSE as system clock source */
		CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_HSE);
		CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_4);	
		CLK_HSICmd(DISABLE);
	#endif

	// Initializes the LCD glass 
  LCD_GLASS_Init();

	
	/* LED button init: GPIO set in push pull */
	GPIO_Init( LED_GPIO_PORT, LED_GPIO_PIN, GPIO_Mode_Out_PP_Low_Fast);
	// set to 0 
	GPIOE->ODR &= ~LED_GPIO_PIN;
	
	/* USER button init: GPIO set in input interrupt active mode */
  GPIO_Init( BUTTON_GPIO_PORT, USER_GPIO_PIN, GPIO_Mode_In_FL_IT);
	EXTI_SetPinSensitivity(EXTI_Pin_7, EXTI_Trigger_Falling);

  //* Init Bar on LCD all are OFF
  BAR0_OFF;
  BAR1_OFF;
  BAR2_OFF;
  BAR3_OFF;	
	
	enableInterrupts();
	
  
  //* At power on VDD diplays 
	bufMessage = NDEFmessage;
	
	if (EEMenuState > STATE_TEMPMEAS) 
		EEMenuState = STATE_CHECKNDEFMESSAGE;
		
	FLASH_Unlock(FLASH_MemType_Data );

	
	state_machine = EEMenuState ; 
	
	delayLFO_ms (1);
	
	if (EEInitial == 0)
	{
			User_WriteFirmwareVersion ();
			EEInitial =1;
	}
	
  while (1)
  {
    
    switch (state_machine)
    {
			  
				case STATE_VREFF:
					// measure the voltage available at the output of the M24LR04E-R

					Vref_measure();
					delayLFO_ms (2);
					//turn on led
					GPIO_SetBits(GPIOE, GPIO_Pin_6);
			
        break;
				
				case STATE_VBIO:
				//measure the output voltage of biosensor through Pin 7 Port E
				
					CLK_PeripheralClockConfig(CLK_Peripheral_ADC1, ENABLE);
						ADC_DeInit(ADC1);
					ADC_VrefintCmd(ENABLE);
					delay_10us(3);
					GPIO_DeInit(GPIOE);
					GPIO_Init(GPIOE,GPIO_Pin_7 ,/*GPIO_Mode_In_FL_No_IT*/GPIO_Mode_In_PU_No_IT);
					ADC_Cmd(ADC1, ENABLE);
					
					ADC_Init(ADC1, ADC_ConversionMode_Single,ADC_Resolution_12Bit, ADC_Prescaler_1);
					
					ADC_SamplingTimeConfig(ADC1, ADC_Group_FastChannels, ADC_SamplingTime_9Cycles);
					ADC_ChannelCmd(ADC1, ADC_Channel_3, ENABLE);
					delay_10us(3); // Important delay
					res = 0;
					res_2 = 0;
					i=0;
					for(i=8; i>0; i--)
						{
						/* start ADC convertion by software */
							ADC_SoftwareStartConv(ADC1);
						/* wait until end-of-covertion */
							while( ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == 0 );
						/* read ADC convertion result */
							res += ADC_GetConversionValue(ADC1);
						}
					/* de-initialize ADC*/ 
					ADC_VrefintCmd(DISABLE);

					ADC_DeInit(ADC1);
 
					/* disable SchmittTrigger for ADC_Channel_24, to save power */
					ADC_SchmittTriggerConfig(ADC1, ADC_Channel_3, DISABLE);
	
					CLK_PeripheralClockConfig(CLK_Peripheral_ADC1, DISABLE);
					ADC_ChannelCmd(ADC1, ADC_Channel_3, DISABLE);
					res = res>>3;
					P_VREFINT_Factory = VREFINT_Factory_CONV_ADDRESS;
					
					
					#ifdef VREFINT_FACTORY_CONV
						if ((*P_VREFINT_Factory>VREFINT_Factory_CONV_MIN ) && (*P_VREFINT_Factory<VREFINT_Factory_CONV_MAX ))
						{
							/* If the value exists:
							Adds the hight byte to FullVREF_FACTORY */
							FullVREF_FACTORY = VREFINT_Factory_CONV_MSB;
							FullVREF_FACTORY += *P_VREFINT_Factory;
							res_2 = (float)(FullVREF_FACTORY*VDD_FACTORY);
							res_2 /= res;
							} else {
											res_2 = (VREF/res) * ADC_CONV; // usally res>>3
											}
											#else
										/* We use the theorcial value */
											res_2 = (VREF/res) * ADC_CONV;
												#endif
						/* Vdd_appli in mV */  
						res_2*= 1000L;
					

						convert_into_char (res_2, tab);
	
							/* To add unit and decimal point  */
						tab[5] = 'V';
						tab[4] = ' ';
						tab[1] |= DOT; /* To add decimal point for display in volt */
						tab[0] = ' ';

						LCD_GLASS_DisplayStrDeci(tab);
						delayLFO_ms (2);
						
					
					//LCD_GLASS_DisplayString("V BIO");
					
					break;
			
			
			
			
        case STATE_CHECKNDEFMESSAGE:
				
						// read the NDEF message from the M24LR04E-R EEPROM and display it if it is found 				
					if (User_ReadNDEFMessage (&PayloadLength) == SUCCESS)						
						User_DisplayMessage (bufMessage,PayloadLength);
	//					User_DisplayMessageActiveHaltMode (PayloadLength);
					else 
						User_DisplayMessage(ErrorMessage,20);		
		
	
        break;
				
				case STATE_TEMPMEAS:
						
						// read the ambiant tempserature from the STTS751
						User_GetOneTemperature (&data_sensor);
						// display the temperature
						User_DisplayOneTemperature (data_sensor);
			
						delayLFO_ms (2);
						
				break;
			
			break;
  
        /* for safe: normaly never reaches */ 			
        default:
					LCD_GLASS_Clear();
					LCD_GLASS_DisplayString("Error");
					state_machine = STATE_VREFF;
        break;
      }
    
		
    }
}	
Example #14
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main(void)
{
  /* Initialize LEDs mounted on STM8L152X-EVAL board */
  STM_EVAL_LEDInit(LED2);
  STM_EVAL_LEDInit(LED3);

  /* Initialize key and Joystick down buttons mounted on STM8L152X-EVAL board */
  STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_EXTI);
  STM_EVAL_PBInit(BUTTON_DOWN, BUTTON_MODE_EXTI);

#ifdef USE_STM8L1526_EVAL

  /* Set PC1 sensitivity to falling edge and low level */
  EXTI_SetPinSensitivity(EXTI_Pin_1, EXTI_Trigger_Falling_Low);
  /* Set PD4 sensitivity to falling edge and low level */
  EXTI_SetPinSensitivity(EXTI_Pin_4, EXTI_Trigger_Falling_Low);

  /*
    Change the software priority between key and joystick down buttons:
    - By default the Pin_1 (key) and Pin_4 have the same priority level: level3
    - We configure the Pin_4 (joystick_down) to have a higher sw priority than Pin_1 (key)
  */
  /* Set the EXTI1 IRQ (which is connected to key button) level to 1 */
  ITC_SetSoftwarePriority(EXTI1_IRQn, ITC_PriorityLevel_1);

  /* Set the EXTI4 IRQ (which is connected to joystick down button) software level to 2 */
  /* Thus joystick down button IRQ software priority is higher than key one */
  /* Pressing joystick down button interrupts the execution of the EXTI1 Interrupt Service Routine */
  ITC_SetSoftwarePriority(EXTI4_IRQn, ITC_PriorityLevel_2);

#elif defined USE_STM8L1528_EVAL

  /* Set PH6 sensitivity to falling edge and low level */
  EXTI_SetPinSensitivity(EXTI_Pin_6, EXTI_Trigger_Falling_Low);
  /* Set PG1 sensitivity to falling edge and low level */
  EXTI_SetPinSensitivity(EXTI_Pin_1, EXTI_Trigger_Falling_Low);

  /*
  Change the software priority between key and joystick down buttons:
  - By default the Pin_6 (key) and Pin_1 have the same priority level: level3
  - We configure the Pin_1 (joystick_down) to have a higher sw priority than Pin_6 (key)
  */
  /* Set the EXTI6 IRQ (which is connected to key button) level to 1 */
  ITC_SetSoftwarePriority(EXTI6_IRQn, ITC_PriorityLevel_1);

  /* Set the EXTI1 IRQ (which is connected to joystick down button) software level to 2 */
  /* Thus joystick down button IRQ software priority is higher than key one */
  /* Pressing joystick down button interrupts the execution of the EXTI6 Interrupt Service Routine */
  ITC_SetSoftwarePriority(EXTI1_IRQn, ITC_PriorityLevel_2);

#endif /* USE_STM8L152X_EVAL */

  /* enable interrupts by setting level 0 */
  enableInterrupts();

  /* LD2 and LD3 are on */
  STM_EVAL_LEDOn(LED2);
  STM_EVAL_LEDOn(LED3);

  while (1);
}