예제 #1
0
/**
  * @brief  Initializes peripherals used by the I2C EEPROM driver.
  * @param  None
  * @retval None
  */
void sEE_LowLevel_Init(void)
{
  /*!< sEE_I2C Periph clock enable */
  CLK_PeripheralClockConfig(sEE_I2C_CLK, ENABLE);

  /*!< Enable the DMA clock */
  CLK_PeripheralClockConfig(CLK_Peripheral_DMA1, ENABLE);

  /* I2C TX DMA Channel configuration */
  DMA_DeInit(sEE_I2C_DMA_CHANNEL_TX);
  DMA_Init(sEE_I2C_DMA_CHANNEL_TX,
           0, /* This parameter will be configured durig communication */
           sEE_I2C_DR_Address,
           0xFF, /* This parameter will be configured durig communication */
           DMA_DIR_PeripheralToMemory,/* This parameter will be configured durig communication */
           DMA_Mode_Normal,
           DMA_MemoryIncMode_Inc,
           DMA_Priority_VeryHigh,
           DMA_MemoryDataSize_Byte);

  /* I2C RX DMA Channel configuration */
  DMA_DeInit(sEE_I2C_DMA_CHANNEL_RX);
  DMA_Init(sEE_I2C_DMA_CHANNEL_RX, 0, /* This parameter will be configured durig communication */
           sEE_I2C_DR_Address,
           0xFF, /* This parameter will be configured durig communication */
           DMA_DIR_PeripheralToMemory,/* This parameter will be configured durig communication */
           DMA_Mode_Normal,
           DMA_MemoryIncMode_Inc,
           DMA_Priority_VeryHigh,
           DMA_MemoryDataSize_Byte);


}
예제 #2
0
/**
  * @brief This function initializes in Ultra Low Power mode, 
	*				disable the LCD, LSE and configures the unused IOs 
	*				in output push-pull
	* @caller main and ADC_Icc_Test
  * @param None
  * @retval None
  */ 
void Halt_Init(void)
{

/* Set STM8 in low power */
  PWR->CSR2 = 0x2;
  
  LCD_Cmd(DISABLE);

  /* To wait LCD disable */
  while ((LCD->CR3 & 0x40) != 0x00);
  
/* Set GPIO in low power*/	
  GPIO_LowPower_Config();
  
/* Stop RTC Source clock */
  CLK_RTCClockConfig(CLK_RTCCLKSource_Off, CLK_RTCCLKDiv_1);
  
  #ifdef USE_LSE
    CLK_LSEConfig(CLK_LSE_OFF);
    while ((CLK->ECKCR & 0x04) != 0x00);
  #else
    CLK_LSICmd(DISABLE);
    while ((CLK->ICKCR & 0x04) != 0x00);
  #endif
  
  /* Stop clock RTC and LCD */ 	
  CLK_PeripheralClockConfig(CLK_Peripheral_RTC, DISABLE);
  CLK_PeripheralClockConfig(CLK_Peripheral_LCD, DISABLE);
}
예제 #3
0
파일: main.c 프로젝트: chalot/360_MBoard
/*主程序*/
void main()
{	
	CLK_Config();

	CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER2, ENABLE);	
	CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER3, ENABLE);	

	/* Check if the system has resumed from IWDG reset */
	if (RST_GetFlagStatus(RST_FLAG_IWDGF) != RESET)
	{
	  /* Clear IWDGF Flag */
	  RST_ClearFlag(RST_FLAG_IWDGF);
	}
	
	/*通信串口初始化*/
	DBG_Config();
	
	IR_Init();
	
	printf("starting...\n");

	/*打开全局中断*/
	enableInterrupts();    

	while (1)
	{
		IR_Process();
	}
		
}
예제 #4
0
char sampleADC(void)
{
    char res = 0x0;

    CLK_PeripheralClockConfig(CLK_Peripheral_ADC1, ENABLE);
    ADC_DeInit(ADC1);

    ADC_VrefintCmd(ENABLE);
    delay_10us(3);

    ADC_Cmd(ADC1, ENABLE);
    ADC_Init(ADC1, ADC_ConversionMode_Single,
             ADC_Resolution_6Bit, ADC_Prescaler_1);

    ADC_SamplingTimeConfig(ADC1, ADC_Group_SlowChannels, ADC_SamplingTime_9Cycles);
    ADC_ChannelCmd(ADC1, ADC_Channel_0, ENABLE);
    delay_10us(3);

    ADC_SoftwareStartConv(ADC1);
    while( ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == 0);
    res = (char)ADC_GetConversionValue(ADC1);

    ADC_VrefintCmd(DISABLE);
    ADC_DeInit(ADC1);

    /* disable SchmittTrigger for ADC_Channel_24, to save power */
    //ADC_SchmittTriggerConfig(ADC1, ADC_Channel_24, DISABLE);

    CLK_PeripheralClockConfig(CLK_Peripheral_ADC1, DISABLE);
    ADC_ChannelCmd(ADC1, ADC_Channel_0, DISABLE);

    return res;
}
예제 #5
0
파일: adc.c 프로젝트: devinzhang91/TinyECG
void ADC_Config(void)
{
	CLK_PeripheralClockConfig(CLK_Peripheral_ADC1, ENABLE);
	CLK_PeripheralClockConfig(CLK_Peripheral_DMA1, ENABLE);
	
	ADC_Init(ADC1, ADC_ConversionMode_Continuous, ADC_Resolution_12Bit, ADC_Prescaler_2);
	ADC_SamplingTimeConfig(ADC1, ADC_Group_SlowChannels, ADC_SamplingTime_384Cycles);
	ADC_Cmd(ADC1, ENABLE);
	
	ADC_ChannelCmd(ADC1, ADC_Channel_24, ENABLE); //设置ADC通道
	
	SYSCFG_REMAPDMAChannelConfig(REMAP_DMA1Channel_ADC1ToChannel0);
	
	DMA_Init(DMA1_Channel0, 
		BUFFER_ADDRESS,
		ADC1_DR_ADDRESS,
		BUFFER_SIZE,
		DMA_DIR_PeripheralToMemory,
		DMA_Mode_Circular,
		DMA_MemoryIncMode_Inc,
		DMA_Priority_High,
		DMA_MemoryDataSize_HalfWord);
	
	DMA_Cmd(DMA1_Channel0, ENABLE);
	DMA_ITConfig(DMA1_Channel0, DMA_ITx_TC, ENABLE);
	DMA_GlobalCmd(ENABLE);
}        
예제 #6
0
파일: delay.c 프로젝트: cristi85/PCRemote
/**
  * @brief  delay for some time in ms unit
  * @param  n_ms is how many ms of time to delay
  * @retval None
  */
void delay_ms(u16 n_ms)
{
/* Init TIMER 4 */
  CLK_PeripheralClockConfig(CLK_Peripheral_TIM4, ENABLE);

/* Init TIMER 4 prescaler: TIM4_Prescaler_1: 38KHz / 1 = 38KHz */
  TIM4->PSCR = 0;

/* LSI 38KHz --> Auto-Reload value: 38KHz / 1 = 38KHz, 38KHz / 1k = 38 */
  TIM4->ARR = 38;
  
/* Counter value: 4, to compensate the initialization of TIMER*/
    
  TIM4->CNTR = 4;  //value may have to be changed

/* clear update flag */
  TIM4->SR1 &= (u8)(~TIM4_FLAG_Update);

/* Enable Counter */
  TIM4->CR1 |= TIM4_CR1_CEN;

  while(n_ms--)
  {
    while((TIM4->SR1 & TIM4_FLAG_Update) == 0);
    TIM4->SR1 &= (u8)(~TIM4_FLAG_Update);
  }

/* Disable Counter */
  TIM4->CR1 &= (u8)(~TIM4_CR1_CEN);
  CLK_PeripheralClockConfig(CLK_Peripheral_TIM4, DISABLE);
}
예제 #7
0
/**
  * @brief  delay for some time in ms unit
  * @caller auto_test
  * @param  n_ms is how many ms of time to delay
  * @retval None
  */
static void delay_ms(u16 n_ms)
{
	/* Init TIMER 4 */
	CLK_PeripheralClockConfig(CLK_Peripheral_TIM2, ENABLE);

	/* Init TIMER 4 prescaler: / (2^6) = /64 */
	TIM2->PSCR = 6;

	/* HSI div by 1 --> Auto-Reload value: 16M / 64 = 1/4M, 1/4M / 1k = 250*/
	TIM2->ARRH = 0;
	TIM2->ARRL = 250;

	/* Counter value: 2, to compensate the initialization of TIMER*/

	TIM2->CNTRH = 0;
	TIM2->CNTRL = 2;

	/* clear update flag */
	TIM2->SR1 &= ~TIM_SR1_UIF;

	/* Enable Counter */
	TIM2->CR1 |= TIM_CR1_CEN;

	while(n_ms--)
	{
	while((TIM2->SR1 & TIM_SR1_UIF) == 0) ;
	TIM2->SR1 &= ~TIM_SR1_UIF;
	}

	/* Disable Counter */
	TIM2->CR1 &= ~TIM_CR1_CEN;
	CLK_PeripheralClockConfig(CLK_Peripheral_TIM2, DISABLE);
}
예제 #8
0
/**
  * @brief  delay for some time in 10us unit(partial accurate)
  * @caller auto_test
  * @param n_10us is how many 10us of time to delay
  * @retval None
  */
static void delay_10us(u16 n_10us)
{
	/* Init TIMER 4 */
	CLK_PeripheralClockConfig(CLK_Peripheral_TIM2, ENABLE);

	/* prescaler: / (2^0) = /1 */
	TIM2->PSCR = 0;

	/* SYS_CLK_HSI_DIV1 Auto-Reload value: 16M / 1 = 16M, 16M / 100k = 160 */
	TIM2->ARRH = 0;
	TIM2->ARRL = 160;

	/* Counter value: 10, to compensate the initialization of TIMER */
	TIM2->CNTRH = 0;
	TIM2->CNTRL = 10;

	/* clear update flag */
	TIM2->SR1 &= ~TIM_SR1_UIF;

	/* Enable Counter */
	TIM2->CR1 |= TIM_CR1_CEN;

	while(n_10us--)
	{
		while((TIM2->SR1 & TIM_SR1_UIF) == 0) ;
		TIM2->SR1 &= ~TIM_SR1_UIF;
	}

	/* Disable Counter */
	TIM2->CR1 &= ~TIM_CR1_CEN;
	CLK_PeripheralClockConfig(CLK_Peripheral_TIM2, DISABLE);

}
예제 #9
0
/**
  * @brief  Delay x sec
  * @param  Seconds : number of seconds to delay
  * @retval None.
  * Note : TIM4 is configured for a system clock = 2MHz
  */
void Delay_Seconds(uint8_t Seconds)
{
  uint8_t i = 0;

  /* Enable TIM4 Clock */
  CLK_PeripheralClockConfig(CLK_Peripheral_TIM4, ENABLE);

  /* Configure TIM4 to generate an update event each 1 s */
  TIM4_TimeBaseInit(TIM4_Prescaler_16384, 123);

  /* Enable TIM4 */
  TIM4_Cmd(ENABLE);

  /* Clear the Flag */
  TIM4_ClearFlag(TIM4_FLAG_Update);

  for (i = 0; i < Seconds; i++)
  {
    /* Wait 1 sec */
    while ( TIM4_GetFlagStatus(TIM4_FLAG_Update) == RESET )
    {}

    /* Clear the Flag */
    TIM4_ClearFlag(TIM4_FLAG_Update);
  }

  /* Disable TIM4 */
  TIM4_Cmd(DISABLE);

  /* Disable TIM4 Clock */
  CLK_PeripheralClockConfig(CLK_Peripheral_TIM4, DISABLE);
}
예제 #10
0
/**
  * @brief  Configure peripherals clock 
  * @param  None
  * @retval None
  */
static void CLK_Config(void)
{
  /* Enable ADC1 clock */
  CLK_PeripheralClockConfig(CLK_Peripheral_ADC1, ENABLE);
  
  /* Enable COMP clock */
  CLK_PeripheralClockConfig(CLK_Peripheral_COMP, ENABLE);
}
예제 #11
0
/**
  * @brief  Configure peripherals clock
  * @param  None
  * @retval None
  */
static void CLK_Config(void)
{
    /* Enable COMP clock */
    CLK_PeripheralClockConfig(CLK_Peripheral_COMP, ENABLE);
    /* Enable TIM1 clock */
    CLK_PeripheralClockConfig(CLK_Peripheral_TIM1, ENABLE);
    /* Enable DAC clock */
    CLK_PeripheralClockConfig(CLK_Peripheral_DAC, ENABLE);
}
예제 #12
0
/**
  * @brief  Configure peripherals Clock   
  * @param  None
  * @retval None
  */
static void CLK_Config(void)
{
  /* Enable TIM1 clock */
  CLK_PeripheralClockConfig(CLK_Peripheral_TIM1, ENABLE);
  /* Enable TIM2 clock */
  CLK_PeripheralClockConfig(CLK_Peripheral_TIM2, ENABLE);
  /* Enable TIM3 clock */
  CLK_PeripheralClockConfig(CLK_Peripheral_TIM3, ENABLE);
}
예제 #13
0
/**
  * @brief  Read ADC1
	* @caller several functions
  * @param None
  * @retval ADC value
  */ 
u16 ADC_Supply(void)
{
	uint8_t i;
	uint16_t res;

/* Enable ADC clock */
  CLK_PeripheralClockConfig(CLK_Peripheral_ADC1, ENABLE);

/* de-initialize ADC */
  ADC_DeInit(ADC1);

/*ADC configuration
  ADC configured as follow:
  - Channel VREF
  - Mode = Single ConversionMode(ContinuousConvMode disabled)
  - Resolution = 12Bit
  - Prescaler = /1
  - sampling time 9 */
  
  ADC_VrefintCmd(ENABLE);
  delay_10us(3);
  
  
  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_Vrefint, ENABLE);
  delay_10us(3);

/* initialize result */
  res = 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_24, DISABLE);
	
  CLK_PeripheralClockConfig(CLK_Peripheral_ADC1, DISABLE);
  ADC_ChannelCmd(ADC1, ADC_Channel_Vrefint, DISABLE);
	
  return (res>>3);
}
예제 #14
0
void Battery_Int_Measure(float * p_bat_voltage)
{
	float voltage_shift = 0;
	float voltage_VCC = 0;
	
	#ifdef BATTERY_DEBUG
		printf("[Battery] Start measuring battery ...\r\n");
	#endif

	result = 0;
	GPIO_Init(GPIO_PORT_ADC_OUT, GPIO_PIN_ADC_OUT, GPIO_Mode_Out_PP_High_Fast);
	GPIO_Init(GPIO_PORT_VTEST_5V, GPIO_PIN_VTEST_5V, GPIO_Mode_In_FL_No_IT);

	/* Enable ADC1 clock */
    CLK_PeripheralClockConfig(CLK_Peripheral_ADC1, ENABLE);

    ADC_Config();

    /* Infinite loop*/
    for(uint8_t i = 0;i < BUFFER_SIZE;i ++)
    {
        /* Start ADC1 Conversion using Software trigger*/
        ADC_SoftwareStartConv(ADC1);

        /* Wait until ADC Channel 15 end of conversion */
        while (ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET)
        {}
        
        /* read ADC convertion result */
        adc_value[i] = ADC_GetConversionValue(ADC1);
		result += adc_value[i];
    }

	voltage_shift = (result * 3.6) / (BUFFER_SIZE * 4096);
	voltage_VCC = (voltage_shift * (BAT_INT_SHIFT_PULLDOWN_RES + BAT_INT_SHIFT_PULLUP_RES)) / BAT_INT_SHIFT_PULLDOWN_RES;

	/* Disable ADC1 */
    ADC_Cmd(ADC1, DISABLE);

	/* Disable ADC1 clock */
    CLK_PeripheralClockConfig(CLK_Peripheral_ADC1, DISABLE);
	
	GPIO_Init(GPIO_PORT_ADC_OUT, GPIO_PIN_ADC_OUT, GPIO_Mode_Out_PP_Low_Fast);
	GPIO_Init(GPIO_PORT_VTEST_5V, GPIO_PIN_VTEST_5V, GPIO_Mode_Out_PP_Low_Fast);

	*p_bat_voltage = voltage_VCC;
	
	#ifdef BATTERY_DEBUG
		for (uint8_t i = 0; i < BUFFER_SIZE; i++)
        {
            printf("[Battery] voltage is 0x%04x\r\n",adc_value[i]);
		}
	#endif
}
예제 #15
0
/**
  * @brief  Configure peripherals clock 
  * @param  None
  * @retval None
  */
static void CLK_Config(void)
{
  /* Enable ADC1 clock */
  CLK_PeripheralClockConfig(CLK_Peripheral_ADC1, ENABLE);

  /* Enable TIM1 clock */
  CLK_PeripheralClockConfig(CLK_Peripheral_TIM1, ENABLE);

  /* Enable DMA1 clock */
  CLK_PeripheralClockConfig(CLK_Peripheral_DMA1, ENABLE);
}
예제 #16
0
/*
名称: void I2C_RTC_Init(void)
功能: 硬件IIC初始化
形参: 无
返回值:无
*/ 
void IIC_RTC_Init(void)
{
  I2C_Cmd(DISABLE);
  I2C_DeInit();
  CLK_PeripheralClockConfig(CLK_PERIPHERAL_I2C, DISABLE);
  GPIO_Init(GPIOE, GPIO_PIN_1, GPIO_MODE_IN_PU_NO_IT);
  GPIO_Init(GPIOE, GPIO_PIN_2, GPIO_MODE_IN_PU_NO_IT);
  CLK_PeripheralClockConfig(CLK_PERIPHERAL_I2C, ENABLE);
  I2C_Cmd( ENABLE);
  I2C_Init(400000, 0xA0, I2C_DUTYCYCLE_2, I2C_ACK_CURR, 
           I2C_ADDMODE_7BIT, 16);
}
예제 #17
0
void LCD_HardwareInit(void)
{
  unsigned long segments = S8 | S9 | S10 | S11 | S12 | S13 | S14 | S15 | S16 | S17 | S18 | S19;
  CLK_RTCClockConfig(CLK_RTCCLKSource_LSI, CLK_RTCCLKDiv_2);
  CLK_PeripheralClockConfig(CLK_Peripheral_RTC, ENABLE);
  
  CLK_PeripheralClockConfig(CLK_Peripheral_LCD, ENABLE);
  LCD_Init(LCD_Prescaler_4, LCD_Divider_24, LCD_Duty_1_3, LCD_Bias_1_3, LCD_VoltageSource_External);
  LCD_PortMaskConfig(LCD_PortMaskRegister_1, (uint8_t)(segments >> 8));
  LCD_PortMaskConfig(LCD_PortMaskRegister_2, (uint8_t)(segments >> 16));
  LCD_PortMaskConfig(LCD_PortMaskRegister_3, (uint8_t)(segments >> 24));
  LCD_PulseOnDurationConfig(LCD_PulseOnDuration_0);
  LCD_ContrastConfig(LCD_Contrast_Level_7);
  LCD_Cmd(ENABLE);
}
예제 #18
0
/**
  * @brief this function checks if a NDEF message is available in the M24LR04E-R EEPROM
	* @par PayloadLength : the number of byte of the NDEF message
  * @retval SUCCESS : A NDEF message has been found
	* @retval ERROR :  a NDEF message doens't have been found
  */
static int8_t User_WriteFirmwareVersion ( void )			
{
uint8_t *OneByte = 0x00;
uint16_t WriteAddr = 0x01FC;				
	
		
	M24LR04E_Init();
		
	M24LR04E_WriteOneByte (M24LR16_EEPROM_ADDRESS_USER, WriteAddr++, FirmwareVersion [0]);			

	
	I2C_Cmd(M24LR04E_I2C, DISABLE);			
		
	CLK_PeripheralClockConfig(CLK_Peripheral_I2C1, DISABLE);	
	
	GPIO_HIGH(M24LR04E_I2C_SCL_GPIO_PORT,M24LR04E_I2C_SCL_PIN);	
	GPIO_HIGH(M24LR04E_I2C_SCL_GPIO_PORT,M24LR04E_I2C_SDA_PIN);	
		
		
	M24LR04E_DeInit();
	I2C_Cmd(M24LR04E_I2C, DISABLE);
	
	
	return SUCCESS;
}
예제 #19
0
파일: main.c 프로젝트: rijn/HardwareWorks
static void TIM2_Config(void)
{
  /* Enable TIM2 CLK */
  CLK_PeripheralClockConfig(CLK_Peripheral_TIM2, ENABLE);
  
  /* Capture only every 8 events!!! */
  /* Enable capture of TIM2 */
  TIM2_ICInit(TIM2_Channel_1, TIM2_ICPolarity_Falling, TIM2_ICSelection_DirectTI, TIM2_ICPSC_Div8, 0);
  
  /* Enable timer1 */
  TIM2_Cmd(ENABLE);
  
  /* Config Channel 1 pin*/
  GPIO_Init(GPIOB, GPIO_Pin_0, GPIO_Mode_In_PU_No_IT);

  /* Clear CC1 Flag*/
  TIM2_ClearFlag(TIM2_FLAG_CC1);
  
  /* wait a Capture on CC1 */
  while((TIM2->SR1 & TIM2_FLAG_CC1) != TIM2_FLAG_CC1);
  
  /* Get CCR1 value*/
  ICValue1 = TIM2_GetCapture1();
  /* Clear CC1 Flag*/
  TIM2_ClearFlag(TIM2_FLAG_CC1);
  
  /* wait a capture on cc1 */
  while((TIM2->SR1 & TIM2_FLAG_CC1) != TIM2_FLAG_CC1);
  /* Get CCR1 value*/
  ICValue2 = TIM2_GetCapture1();
  TIM2_ClearFlag(TIM2_FLAG_CC1); 
}
예제 #20
0
/**
  * @brief ADC_Icc(ADC_24 of ADC_0~27) initialization
	* @caller main and ADC_Icc_Test
  * @param None
  * @retval None
  */ 
void ADC_Icc_Init(void)
{

/* Enable ADC clock */
  CLK_PeripheralClockConfig(CLK_Peripheral_ADC1, ENABLE);

/* de-initialize ADC */
  ADC_DeInit(ADC1);
	
/*  ADC configured as follow:
  - NbrOfChannel = 1 - ADC_Channel_24
  - Mode = Single ConversionMode(ContinuousConvMode disabled)
  - Resolution = 12Bit
  - Prescaler = /1
  - sampling time 159 */
	
/* Enable ADC1 */
  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_24, ENABLE);

/* disable SchmittTrigger for ADC_Channel_24, to save power */
  ADC_SchmittTriggerConfig(ADC1, ADC_Channel_24, DISABLE);

/* a short time of delay is required after enable ADC */
  delay_10us(3);
	
}
예제 #21
0
파일: main.c 프로젝트: rijn/HardwareWorks
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main(void)
{
    /* I2C  clock Enable*/
    CLK_PeripheralClockConfig(CLK_Peripheral_I2C, ENABLE);

    /* system_clock / 1 */
    CLK_MasterPrescalerConfig(CLK_MasterPrescaler_HSIDiv1);

    /* Initialize LEDs mounted on the EVAL board */
    STM_EVAL_LEDInit(LED2);
    STM_EVAL_LEDInit(LED3);

    I2C_DeInit();
    /* Initialize I2C peripheral */

#ifdef I2C_slave_7Bits_Address
    I2C_Init(100000, SLAVE_ADDRESS, I2C_DutyCycle_2, I2C_Ack_Enable,
             I2C_AcknowledgedAddress_7bit);
#else
    I2C_Init(100000, SLAVE_ADDRESS, I2C_DutyCycle_2, I2C_Ack_Enable,
             I2C_AcknowledgedAddress_10bit);
#endif

    /* Enable Error Interrupt*/
    I2C_ITConfig((I2C_IT_TypeDef)(I2C_IT_ERR | I2C_IT_EVT | I2C_IT_BUF), ENABLE);

    /* Enable general interrupts */
    enableInterrupts();

    /*Main Loop */
    while (1)
    {
        /* infinite loop */
    }
}
static void HalConsoleDMAConfigration(void)
{
  CLK_PeripheralClockConfig(CLK_Peripheral_DMA1, ENABLE);
  
  /* Deinitialize DMA channels */
  DMA_GlobalDeInit();
  
  DMA_DeInit(USART_DMA_CHANNEL_TX);
  DMA_DeInit(USART_DMA_CHANNEL_RX);
  
  /* DMA channel Rx of USART Configuration */
  DMA_Init(USART_DMA_CHANNEL_RX, (uint16_t)HalConsoleRxBuffer, (uint16_t)USART_DR_ADDRESS,
           sizeof(HalConsoleRxBuffer), DMA_DIR_PeripheralToMemory, DMA_Mode_Normal,
           DMA_MemoryIncMode_Inc, DMA_Priority_Low, DMA_MemoryDataSize_Byte);
  
  
  /* Enable the USART Tx/Rx DMA requests */
  USART_DMACmd(USART2, USART_DMAReq_TX, ENABLE);
  USART_DMACmd(USART2, USART_DMAReq_RX, ENABLE);
  
  /* Global DMA Enable */
  DMA_GlobalCmd(ENABLE);
  
  /* Enable the USART Rx DMA channel */
  DMA_Cmd(USART_DMA_CHANNEL_RX, ENABLE);
  USART_Cmd(USART2, ENABLE);
}
예제 #23
0
/**
  * @brief  Initializes the SD_SPI and CS pins.
  * @param  None
  * @retval None
  */
void SD_LowLevel_Init(void)
{
  /* Enable SPI clock */
  CLK_PeripheralClockConfig(SD_SPI_CLK, ENABLE);

  /* Set the MOSI,MISO and SCK at high level */
  GPIO_ExternalPullUpConfig(SD_SPI_SCK_GPIO_PORT, SD_SPI_MISO_PIN | SD_SPI_MOSI_PIN | \
                            SD_SPI_SCK_PIN, ENABLE);

  /* SPI2 pin remap on Port I*/
  SYSCFG_REMAPPinConfig(REMAP_Pin_SPI2Full, ENABLE);

  /* SD_SPI Config */
  SPI_Init(SD_SPI, SPI_FirstBit_MSB, SPI_BaudRatePrescaler_4, SPI_Mode_Master,
           SPI_CPOL_High, SPI_CPHA_2Edge, SPI_Direction_2Lines_FullDuplex,
           SPI_NSS_Soft, 0x07);


  /* SD_SPI enable */
  SPI_Cmd(SD_SPI, ENABLE);

  /* Configure the SD_Detect pin */
  GPIO_Init(SD_DETECT_GPIO_PORT, SD_DETECT_PIN, GPIO_Mode_In_PU_No_IT);

  /* Set MSD ChipSelect pin in Output push-pull high level */
  GPIO_Init(SD_CS_GPIO_PORT, SD_CS_PIN, GPIO_Mode_Out_PP_High_Slow);
}
예제 #24
0
/**
  * @brief  init usart1 
  * @param  None
  * @retval None
  */
void Init_usart1(uint32_t BaudRate)
{
	CLK_PeripheralClockConfig(CLK_Peripheral_USART1, ENABLE);
	USART_Init(USART1, BaudRate, USART_WordLength_8b, USART_StopBits_1, USART_Parity_No, USART_Mode_Tx|USART_Mode_Rx);
	USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
	USART_Cmd(USART1, ENABLE);
}
예제 #25
0
파일: main.c 프로젝트: zk1132/contiki
/**
  * @brief  Configure ADC and Analog watchdog
  * @param  None
  * @retval None
  */
static void ADC_Config(void)
{
    /* Enable ADC1 clock */
    CLK_PeripheralClockConfig(CLK_Peripheral_ADC1, ENABLE);

    /* Initialise and configure ADC1 */
    ADC_Init(ADC1, ADC_ConversionMode_Continuous, ADC_Resolution_12Bit, ADC_Prescaler_2);
    ADC_SamplingTimeConfig(ADC1, ADC_Group_SlowChannels, ADC_SamplingTime_384Cycles);

    /* Enable ADC1 */
    ADC_Cmd(ADC1, ENABLE);

    /* Enable ADC1 Channel 3 */
    ADC_ChannelCmd(ADC1, ADC_Channel_3, ENABLE);

    /* Calculate Threshold data value*/
    HighThresholdData = (uint16_t)(((uint32_t)HIGH_THRESHOLD_VOLTAGE * 1000) / (uint32_t)ADC_RATIO) ;
    LowThresholdData  = (uint16_t)(((uint32_t)LOW_THRESHOLD_VOLTAGE * 1000) / (uint32_t)ADC_RATIO) ;

    /* Configure Analog Watchdog selected channel and Thresholds */
    ADC_AnalogWatchdogConfig(ADC1, ADC_AnalogWatchdogSelection_Channel3,
                             HighThresholdData,
                             LowThresholdData);

    /* Enable Analog watchdog ADC1 Interrupt */
    ADC_ITConfig(ADC1, ADC_IT_AWD, ENABLE);

    /* Enable Interrupts */
    enableInterrupts();

    /* Start ADC1 Conversion using Software trigger*/
    ADC_SoftwareStartConv(ADC1);
}
/*
 *******************************************************************************
 *                                 FUNCTIONS                                 
 *******************************************************************************
 */
void HalLightInit(void)
{
  /* Enable TIM1 clock */
  CLK_PeripheralClockConfig(CLK_Peripheral_TIM1, ENABLE);
  
  /* GPIOD configuration */
  GPIO_Init(GPIOD, GPIO_Pin_2, GPIO_Mode_Out_PP_Low_Fast);
  GPIO_Init(GPIOD, GPIO_Pin_3, GPIO_Mode_Out_PP_Low_Fast);
  GPIO_SetBits(GPIOD, GPIO_Pin_3); /* Close relay output */
  /*
  - TIM1CLK = 16 MHz
  - TIM1 counter clock = TIM1CLK / 320 = 16MHz/320 = 50000Hz
  */
  /* Time base configuration */
  TIM1_TimeBaseInit(320, TIM1_CounterMode_Up, 100, 0);
  
  TIM1_OC1Init(TIM1_OCMode_PWM1, TIM1_OutputState_Enable, TIM1_OutputNState_Disable,
               10, TIM1_OCPolarity_Low, TIM1_OCNPolarity_High, TIM1_OCIdleState_Set,
               TIM1_OCNIdleState_Set);
  TIM1_OC1PreloadConfig(DISABLE);
  
  TIM1_ARRPreloadConfig(ENABLE);
  
  /* Enable TIM1 outputs */
//  TIM1_CtrlPWMOutputs(ENABLE);
  //HalLightOpen();
//  HalLightClose();
//  HalLightSetBrightness(10);
  HalLigthPWM = (80);
  HalLightOpen();
  
}
예제 #27
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main(void)
{
  /* Enable LSE */
  CLK_LSEConfig(CLK_LSE_ON);
  /* Wait for LSE clock to be ready */
  while (CLK_GetFlagStatus(CLK_FLAG_LSERDY) == RESET);

  /* wait for 1 second for the LSE Stabilisation */
  LSE_StabTime();

  /* Select LSE (32.768 KHz) as RTC clock source */
  CLK_RTCClockConfig(CLK_RTCCLKSource_LSE, CLK_RTCCLKDiv_1);

  CLK_PeripheralClockConfig(CLK_Peripheral_RTC, ENABLE);

  /* Calendar Configuration */
  Calendar_Init();

  /*RTC Tamper Configuration*/
  Tamper_Init();

  /* EvalBoard Configuration */
  EvalBoard_Init();

  Tamper_DelayShow(TampFilterIndex);

  while (1)
  {
    EnterSafeCode();
    Time_Show(LCD_LINE2, SHOW_POINT2);
    ExitSafeCode();
  }
}
예제 #28
0
파일: main.c 프로젝트: HorseMa/contiki
/**
  * @brief  Configure peripheral clock 
  * @param  None
  * @retval None
  */
static void CLK_Config(void)
{
  /* Select HSE as system clock source */
  CLK_SYSCLKSourceSwitchCmd(ENABLE);
  CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_HSE);
  
  /*High speed external clock prescaler: 1*/
  CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_2);

  while (CLK_GetSYSCLKSource() != CLK_SYSCLKSource_HSE)
  {}

  /* Enable SPI clock */
  CLK_PeripheralClockConfig(CLK_Peripheral_SPI1, ENABLE);
  /* Enable DMA clock */
  CLK_PeripheralClockConfig(CLK_Peripheral_DMA1, ENABLE);
}
예제 #29
0
//------------------------------------------------------------------------------
// Function Name : delay_10us
// Description   : delay for some time in 10us unit(partial accurate)
// Input         : n_10us is how many 10us of time to delay
//------------------------------------------------------------------------------
void delay_1us(u16 n_1us)
{
  CLK_PeripheralClockConfig(CLK_Peripheral_TIM4, ENABLE);
  // Init TIMER 4 //
  // prescaler: / (2^0) = /1
  TIM4->PSCR = 0;
#ifdef SYS_CLK_HSE_DIV1
  // Auto-Reload value: 16M / 1 = 16M, 16M / 100k = 160
  TIM4->ARR = 160;
#else
#ifdef SYS_CLK_HSE_DIV2
  // Auto-Reload value: 16M/2 / 1 = 8M, 8M / 100k = 80
  TIM4->ARR = 80;
#else
#ifdef SYS_CLK_HSI_DIV1
  // Auto-Reload value: 16M / 1 = 16M, 16M / 100k = 160
  TIM4->ARR = 16;
#else
#ifdef SYS_CLK_HSI_DIV2
  // Auto-Reload value: 16M/2 / 1 = 8M, 8M / 100k = 80
  TIM4->ARR = 80;
#else
#error "either SYS_CLK_HSE_DIV1/DIV2 or SYS_CLK_HSI_DIV1/DIV2 should be defined"
#endif
#endif
#endif
#endif
  // Counter value: 10, to compensate the initialization of TIMER
  TIM4->CNTR = 10;

  // clear update flag
  TIM4->SR1 &= ~TIM4_SR1_UIF;
  // Enable Counter
  TIM4->CR1 |= TIM4_CR1_CEN;

  while (n_1us--)
  {
    while ((TIM4->SR1 & TIM4_SR1_UIF) == 0) ;
    TIM4->SR1 &= ~TIM4_SR1_UIF;
  }

  // Disable Counter
  TIM4->CR1 &= ~TIM4_CR1_CEN;
  CLK_PeripheralClockConfig(CLK_Peripheral_TIM4, DISABLE);

}
예제 #30
0
void InitTimer(void)
{
  clk_config();
  TIM2_DeInit();
  CLK_PeripheralClockConfig(CLK_Peripheral_TIM2, ENABLE);
  TIM2_TimeBaseInit(TIM2_Prescaler_1, TIM2_CounterMode_Up, 500);
  TIM2_Cmd(ENABLE);
}