Exemplo n.º 1
0
/*******************************************************************************
 * 名    称: Bsp_ConfgiSysClk
 * 功    能: 配置CPU系统时钟
 * 入口参数: 枚举SYS_CLK_E ; 可选参数为:
 *				HSI_2M = 0		内部高速RC振荡源16M, 分频倍率设置为 1/8 可得到2M
 *				HSI_4M,			内部高速RC振荡源16M, 分频倍率设置为 1/4 可得到4M
 *				HSI_8M,			内部高速RC振荡源16M, 分频倍率设置为 1/2 可得到8M
 *				HSI_16M,		内部高速RC振荡源16M, 分频倍率设置为 1/1 可得到16M
 *			  	LSI_128K,		内部低速RC时钟源,频率固定为128KHz
 *				HSE_XTAL,		外部高速时钟 (频率由用于外接晶振决定,无分频选项)
 * 出口参数: 无
 * 作  者: Roger-WY
 * 创建日期: 2014-08-20
 * 修    改:
 * 修改日期:
 * 备    注: 建议使用优化代码模式
 *******************************************************************************/
void Bsp_ConfgiSysClk(SYS_CLK_E _iSysClk)
{
#if 1	/* 空间不足,优化代码, 只保留需要的时钟设置 */
	if (_iSysClk == HSI_16M) {
		/* 自动切换, 切换到内部高速时钟HSI, 禁止系统时钟中断, 关闭当前的时钟源  */
		CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO, CLK_SOURCE_HSI, DISABLE, CLK_CURRENTCLOCKSTATE_DISABLE);
		CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);  /* 设置内部高速RC时钟HSI为时钟源,分频系数为1 */
		while (CLK_GetFlagStatus(CLK_FLAG_HSIRDY) == RESET);	/* 等待HSI时钟稳定 */
	}
#else
	switch (_iSysClk) {
		case HSE_XTAL:
			/* 自动切换, 切换到外部高速时钟HSE, 禁止系统时钟中断, 关闭当前的时钟源  */
			CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO, CLK_SOURCE_HSE, DISABLE, CLK_CURRENTCLOCKSTATE_DISABLE);
			break;

		case LSI_128K:
			/* 自动切换, 切换到内部低速时钟LSI, 禁止系统时钟中断, 关闭当前的时钟源  */
			CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO, CLK_SOURCE_LSI, DISABLE, CLK_CURRENTCLOCKSTATE_DISABLE);
			break;

		case HSI_16M:
			/* 自动切换, 切换到内部高速时钟HSI, 禁止系统时钟中断, 关闭当前的时钟源  */
			CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO, CLK_SOURCE_HSI, DISABLE, CLK_CURRENTCLOCKSTATE_DISABLE);
			CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);  /* 设置内部高速RC时钟HSI为时钟源,分频系数为1 */
			while (CLK_GetFlagStatus(CLK_FLAG_HSIRDY) == RESET);	/* 等待HSI时钟稳定 */
			break;

		case HSI_8M:
			/* 自动切换, 切换到内部高速时钟HSI, 禁止系统时钟中断, 关闭当前的时钟源  */
			CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO, CLK_SOURCE_HSI, DISABLE, CLK_CURRENTCLOCKSTATE_DISABLE);
			CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV2);  /* 设置内部高速RC时钟HSI为时钟源,分频系数为2 */
			while (CLK_GetFlagStatus(CLK_FLAG_HSIRDY) == RESET);	/* 等待HSI时钟稳定 */
			break;

		case HSI_4M:
			/* 自动切换, 切换到内部高速时钟HSI, 禁止系统时钟中断, 关闭当前的时钟源  */
			CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO, CLK_SOURCE_HSI, DISABLE, CLK_CURRENTCLOCKSTATE_DISABLE);
			CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV4);  /* 设置内部高速RC时钟HSI为时钟源,分频系数为4 */
			while (CLK_GetFlagStatus(CLK_FLAG_HSIRDY) == RESET);	/* 等待HSI时钟稳定 */
			break;

		case HSI_2M:
			/* 自动切换, 切换到内部高速时钟HSI, 禁止系统时钟中断, 关闭当前的时钟源  */
			CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO, CLK_SOURCE_HSI, DISABLE, CLK_CURRENTCLOCKSTATE_DISABLE);
			CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV8);  /* 设置内部高速RC时钟HSI为时钟源,分频系数为8 */
			while (CLK_GetFlagStatus(CLK_FLAG_HSIRDY) == RESET);	/* 等待HSI时钟稳定 */
			break;

		default:
			break;
	}
#endif
}
Exemplo n.º 2
0
/**
  * @brief Example main entry point.
  * @par Parameters:
  * None
  * @retval 
  * None
  */
void main(void)
{

    u8 i = 0;
		u16 Timer2Count;

    /* Configuration of the GPIO*/
		GPIO_Configuration();
		
		/* Clock divider to HSI/1 */
    CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);

    /* BEEP calibration */
    BEEP_LSICalibrationConfig(LSIMeasurment());
		
		/* TS Library Initialisation */
		TSL_Init();

    /* TS Application Initialisation */
		ExtraCode_Init();

		/* Tim2 Configuration */
		InitializeTim2();

    while (1)
    {
			ExtraCode_StateMachine();
			TSL_Action();
			BeepDriver_Action();
			//SubCounterSounds();
    }

}
Exemplo n.º 3
0
/**
  ******************************************************************************
  * @brief Configures clocks
  * @par Parameters:
  * None
  * @retval void None
  * @par Required preconditions:
  * None
  ******************************************************************************
  */
void CLK_Configuration(void)
{

  /* Fmaster = 16MHz */
  CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);

}
Exemplo n.º 4
0
/**
  * @brief Example firmware main entry point.
  * @par Parameters:
  * None
  * @retval 
  * None
  */
void main(void)
{
    /*High speed internal clock prescaler: 1*/
    CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);

    /* Enable general interrupts */
    enableInterrupts();

    /* Deinitializes the UART1 and UART3 peripheral */
    UART1_DeInit();
    UART3_DeInit();
    /* UART1 and UART3 configuration -------------------------------------------------*/
    /* UART1 and UART3 configured as follow:
          - BaudRate = 9600 baud  
          - Word Length = 8 Bits
          - One Stop Bit
          - No parity
          - Receive and transmit enabled
          - UART1 Clock disabled
     */
    /* Configure the UART1 */
    UART1_Init((u32)9600, UART1_WORDLENGTH_8D, UART1_STOPBITS_1, UART1_PARITY_NO, UART1_SYNCMODE_CLOCK_DISABLE, UART1_MODE_TXRX_ENABLE);

    /* Configure the UART3 */
 		UART3_Init((u32)9600, UART3_WORDLENGTH_8D, UART3_STOPBITS_1, UART3_PARITY_NO, UART3_MODE_TXRX_ENABLE);

    /* Enable UART3 Receive and UART1 Transmit interrupt */

    UART3_ITConfig(UART3_IT_RXNE_OR, ENABLE);
    UART1_ITConfig(UART1_IT_TXE, ENABLE);

    /* Wait until end of transmission from UART1 to UART3 */
    while (GetVar_RxCounter2() < GetVar_NbrOfDataToTransfer1())
    {
    }
    /* Enable UART1 Receive and UART3 Transmit interrupt */
    UART1_ITConfig(UART1_IT_RXNE_OR, ENABLE);
    UART3_ITConfig(UART3_IT_TXE, ENABLE);
    /* Wait until end of transmission from UART3 to UART1 */
    while (GetVar_RxCounter1() < GetVar_NbrOfDataToTransfer2())
    {
    }

    /* Check the received data with the send ones */
    TransferStatus1 = Buffercmp(TxBuffer2, RxBuffer1, RxBufferSize1);
    /* TransferStatus1 = PASSED, if the data transmitted from UART3 and
       received by UART1 are the same */
    /* TransferStatus1 = FAILED, if the data transmitted from UART3 and
       received by UART1 are different */
    TransferStatus2 = Buffercmp(TxBuffer1, RxBuffer2, RxBufferSize2);
    /* TransferStatus2 = PASSED, if the data transmitted from UART1 and
       received by UART3 are the same */
    /* TransferStatus2 = FAILED, if the data transmitted from UART1 and
       received by UART3 are different */

    while (1);
}
Exemplo n.º 5
0
/**
  * @brief  Configure system clock to run at 16Mhz and output the system clock on
  *         CCO pin
  * @param  None
  * @retval None
  */
static void CLK_Config(void)
{
    CLK_DeInit();

    /* Clock divider to HSI/1 */
    CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);

    /* Output Fcpu on CLK_CCO pin */
    CLK_CCOConfig(CLK_OUTPUT_MASTER);
}
Exemplo n.º 6
0
/**
  * @brief  Configure system clock to run at 16Mhz
  * @param  None
  * @retval None
  */
void CLK_Config(void)
{
    /* Initialization of the clock */
    /* Clock divider to HSI/1 */
	CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);
	CLK_SYSCLKConfig(CLK_PRESCALER_CPUDIV1);
	CLK_HSICmd(ENABLE);
	
	CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER1, ENABLE);	
	CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER2, ENABLE);	
	CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER3, ENABLE);	
	CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER4, ENABLE);	
	CLK_PeripheralClockConfig(CLK_PERIPHERAL_UART1, ENABLE);
	#ifdef __DEBUG__
	CLK_PeripheralClockConfig(CLK_PERIPHERAL_UART3, ENABLE);
	#endif
}
Exemplo n.º 7
0
int main(void) {
	
	// Set the internal high-speed oscillator to 1 to run at 16/1=16MHz.
    CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);
	
	// Reset ("de-initialise") GPIO port D.
	GPIO_DeInit(GPIOD);
	// Initialise pin 0 of port D by setting it as:
	// - an output pin,
	// - using a push-pull driver,
	// - at a low logic level (0V), and
	// - 10MHz.
	GPIO_Init(GPIOD, GPIO_PIN_0, GPIO_MODE_OUT_PP_LOW_FAST);
	
	UART2_DeInit();
	
	/* UART2 configuration ------------------------------------------------------*/
	/* UART2 configured as follow:
		- BaudRate = 9600 baud  
		- Word Length = 8 Bits
		- One Stop Bit
		- Even parity
		- Receive and transmit enabled
		- UART2 Clock disabled
	*/
	/* Configure the UART2 */
	UART2_Init((u32)9600, UART2_WORDLENGTH_8D, UART2_STOPBITS_1, UART2_PARITY_NO, 
		UART2_SYNCMODE_CLOCK_DISABLE, UART2_MODE_TXRX_ENABLE);
		
	LCDInit();
	
	DrawScreen();
	UpdateLCD();
	
	UART2_ITConfig(UART2_IT_RXNE, ENABLE);
	
	enableInterrupts();
	// Infinite loop.
	for(;;) {
							
		DrawDemo();	
		Delay(80);
	}
}
Exemplo n.º 8
0
/********************************************************************************
* clk_setup																		*
********************************************************************************/
void _Device_System_clk_setup(void)
{
	CLK_HSIPrescalerConfig(dSourceFreqDivided); // fMaster, speed 16MHz / 4 = 4MHz, for peripheral device
	CLK_SYSCLKConfig(dMCUFreqDivided); // CPU speed, 4MHz / 1 = 4MHz
    
    // I2C 
	//CLK_PeripheralClockConfig(CLK_PERIPHERAL_I2C, ENABLE);
	// V_BAT, T_SENSOR, I_CHARGE, I_DISCHARGE
	CLK_PeripheralClockConfig(CLK_PERIPHERAL_ADC, ENABLE);
	// LED 1 ~ 4, PWM
	CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER1, ENABLE);
	// LED 0, PWM
	CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER2, ENABLE);
	// tick
	CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER4, ENABLE);
	// UART
	CLK_PeripheralClockConfig(CLK_PERIPHERAL_UART2, ENABLE);
    
//  GPIO_Init(GPIOD, GPIO_PIN_0, GPIO_MODE_OUT_PP_LOW_FAST);
//  CLK_CCOConfig(CLK_OUTPUT_CPUDIV8);
//    CLK_CCOConfig(CLK_OUTPUT_CPU);
//  CLK_CCOCmd(ENABLE); 
    /* Output Fcpu on CLK_CCO pin */
    //CLK_CCOConfig(CLK_OUTPUT_CPU);
    
//    
//    //Lsi
//    unsigned char status;
//    CLK_ClockSwitchCmd(ENABLE);
//    status = CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO, CLK_SOURCE_LSI, DISABLE, CLK_CURRENTCLOCKSTATE_DISABLE); 
//    
//    while(status == 0);
    //CLK_ClockSwitchConfig(CLK_SWITCHMODE_MANUAL, CLK_SOURCE_LSI, DISABLE, CLK_CURRENTCLOCKSTATE_DISABLE);    
    //CLK_LSICmd(ENABLE);
    //CLK_HSECmd(DISABLE);
    
//    //hsi
//    CLK_ClockSwitchCmd(ENABLE);
//    CLK_HSICmd(ENABLE);
//    CLK_LSICmd(DISABLE);
//    CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO, CLK_SOURCE_HSI, DISABLE, CLK_CURRENTCLOCKSTATE_DISABLE);	
    
}
Exemplo n.º 9
0
/**
  * @brief Example  main entry point.
  * @par Parameters:
  * None
  * @retval 
  * None
  */
void main(void)
{

    /* Initialize SPI for LCD */
    SPI_DeInit();
    SPI_Init(SPI_FIRSTBIT_MSB, SPI_BAUDRATEPRESCALER_128, SPI_MODE_MASTER, SPI_CLOCKPOLARITY_HIGH, SPI_CLOCKPHASE_2EDGE, SPI_DATADIRECTION_1LINE_TX, SPI_NSS_SOFT, 0x07);
    SPI_Cmd(ENABLE);

    
    /* Configure GPIO used to drive the joystick
	      JOYSTICK_UP    --> PB6
	      JOYSTICK_DOWN  --> PB7
	      JOYSTICK_LEFT --> PB4
	*/
  GPIO_Init(GPIOB, GPIO_PIN_4 | GPIO_PIN_6 | GPIO_PIN_7, GPIO_MODE_IN_FL_IT);
  EXTI_SetExtIntSensitivity(EXTI_PORT_GPIOB, EXTI_SENSITIVITY_FALL_LOW);
	
	enableInterrupts();
    
    
    /* Initialize LCD */
    LCD_Init();

    /* Clear LCD lines */
    LCD_Clear();

    LCD_Backlight(ENABLE);

    LCD_PrintString(LCD_LINE1, ENABLE, DISABLE, "Clock Selection");
    LCD_PrintString(LCD_LINE2, ENABLE, DISABLE, " Use joystick");

    CLK_DeInit();
		CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);
    /* Output Fcpu on CLK_CCO pin */
    CLK_CCOConfig(CLK_OUTPUT_MASTER);

    while (1)
    {
  
    }

}
Exemplo n.º 10
0
/**
  * @brief Example firmware main entry point.
  * @par Parameters:
  * None
  * @retval
  * None
  */
void main(void)
{
    /*High speed internal clock prescaler: 1*/
    CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);

    UART1_DeInit();
    /* UART1 configuration ------------------------------------------------------*/
    /* UART1 configured as follow:
          - BaudRate = 115200 baud
          - Word Length = 8 Bits
          - One Stop Bit
          - No parity
          - Receive and transmit enabled
          - UART1 Clock disabled
    */
    /* Configure UART1 */
    UART1_Init((u32)115200, UART1_WORDLENGTH_8D, UART1_STOPBITS_1, UART1_PARITY_NO, UART1_SYNCMODE_CLOCK_DISABLE, UART1_MODE_TXRX_ENABLE);

    /* Output a message on Hyperterminal using printf function */
    printf("\n\rUART1 Example :Retarget the C library printf function to the UART1\n\r");

    while (1);
}
Exemplo n.º 11
0
//Modbus Initialization
void Modbus_Init(void)
{
//Clock divider equals 1.Clock 16MHz
	CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);
//Clear bits 
	TIM2_DeInit();
	GPIO_DeInit(GPIOA);
	UART2_DeInit();
//Peripetial Initialization
	TIM2_TimeBaseInit(TIM2_PRESCALER_2048, 78);
	GPIO_Init(GPIOA, GPIO_PIN_3, GPIO_MODE_OUT_PP_LOW_FAST);
	UART2_Init(BAUDRATE, UART2_WORDLENGTH_8D, UART2_STOPBITS_2,UART2_PARITY_NO,UART2_SYNCMODE_CLOCK_DISABLE,UART2_MODE_TXRX_ENABLE );  
//Enable Periphs
	TIM2_Cmd(ENABLE);
	UART2_Cmd(ENABLE);
//Interrupt configuration
	TIM2_ITConfig(TIM2_IT_UPDATE, ENABLE);
	UART2_ITConfig(UART2_IT_RXNE_OR, ENABLE);
#ifndef __DELAY_EN
	#define __MODBUS_EN
	enableInterrupts();
#endif
}
Exemplo n.º 12
0
void main(void) {
    
    CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1); // 16Mhz
    
    wl315_init();  
    flash_init();
    uart_init();
    
    // recovery the key value
    flash_read_key(LEARN_KEY1, &tKey1);
    flash_read_key(LEARN_KEY2, &tKey2);
    flash_read_key(LEARN_KEY3, &tKey3);
    flash_read_key(LEARN_KEY4, &tKey4);
    
    WL315_START();
    rim();
    
    /* Infinite loop */
    while (1) {
        wl315_learn_task(); // 按键学习任务
        uart_print_task();  // 串口打印任务
    }
}
Exemplo n.º 13
0
void main(void)
{    
  CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);
  
  Delay_Init();
  RS485_Init(115200);
#if DEBUG
  //  UART_Init(115200);
#endif
  SRF05_Init();
  SRF05_AutoPoolEnable();
  
  //flash_read_buffer((char *)&my_data, sizeof (struct flash_data));
  my_data.id = 0x21;
  //  UART_SendByte(0x21, HEX);
  //  RS485_SendStr("Hello world.\n");
  
  // LED run
  GPIO_Init(LED_RUN_PORT, LED_RUN_PIN, GPIO_MODE_OUT_PP_HIGH_FAST);
  GPIO_WriteHigh(LED_RUN_PORT, LED_RUN_PIN);
  
  while (1)
  {
    if (Millis() - tmp_time > 500)
    {
      LED_RUN_TOGGLE;
      tmp_time = Millis();
			
#if DEBUG
			RS485_DIR_OUTPUT;
			RS485_SendStr("\n");
			RS485_SendFloat(SRF05_GetDistance());
			RS485_DIR_INPUT;
#endif
    }
    
    if (GPIO_ReadInputPin(RS485_SEL_PORT, RS485_SEL_PIN) == RESET)
    {
      if (RS485_Available() >= 8)
      {
        //      memset(packet_buff, 0, PACKET_BUFFER_SIZE);
        packet_len = RS485_GetData(packet_buff);
        packet = (struct Packet *)packet_buff;
        if (packet_len < 4 + getTypeLength(packet->data_type))
        {
          // not enough length
        }
        else
        {
          switch (packet->cmd)
          {
          case CMD_QUERY:
            if (packet->id == my_data.id)
            {
              LED_RUN_TOGGLE;
              
              tmp_distance = SRF05_GetDistance();
              packet->data_type = TYPE_FLOAT | BIG_ENDIAN_BYTE_ORDER;
              memcpy(packet->data, &tmp_distance, getTypeLength(packet->data_type));
              packet->data[getTypeLength(packet->data_type)] = checksum((char *)packet);
              RS485_DIR_OUTPUT;
              RS485_SendData(packet_buff, 4 + getTypeLength(packet->data_type));
              RS485_DIR_INPUT;
            }
            else if (IS_BROADCAST_ID(packet->id))
            {
              //              if (GPIO_ReadInputPin(RS485_SEL_PORT, RS485_SEL_PIN) == RESET)
              //              {
              LED_RUN_TOGGLE;
              
              packet->id = my_data.id;
              tmp_distance = SRF05_GetDistance();
              packet->data_type = TYPE_FLOAT | BIG_ENDIAN_BYTE_ORDER;
              memcpy(packet->data, &tmp_distance, getTypeLength(packet->data_type));
              packet->data[getTypeLength(packet->data_type)] = checksum((char *)packet);
              RS485_DIR_OUTPUT;
              RS485_SendData(packet_buff, 4 + getTypeLength(packet->data_type));
              RS485_DIR_INPUT;
              //              }
            }
            else
            {
              // not own id
            }
            break;
          case CMD_CONTROL:
            // by default, this mode used only for setting id
            // the id stored on the first bytes of data bytes
            if (IS_BROADCAST_ID(packet->id))
            {
              LED_RUN_TOGGLE;
              if (IS_SENSOR_ULTRA_SONIC(packet->data[0]))
              {
                my_data.id = packet->data[0];
              }
            }
            break;
          default:
            break;
          }
          
          RS485_Flush();
        }
      }
    }
    else
    {
      RS485_Flush();
    }
		
		SRF05_ProcessTrigger();
  }
}
Exemplo n.º 14
0
void main(void)
{
  //CFG->GCR |= 0x01; //disable swim pin
  
  /* Configure the Fcpu to DIV1*/
  CLK_SYSCLKConfig(CLK_PRESCALER_CPUDIV1);
  
   /* select Clock = 16 MHz */
  CLK_SYSCLKConfig(CLK_PRESCALER_HSIDIV1);
  
  /* Configure the system clock to use HSI clock source and to run at 16Mhz */
  CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO, CLK_SOURCE_HSI, DISABLE, CLK_CURRENTCLOCKSTATE_DISABLE);
  
  CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);
  
  CLK_HSICmd(ENABLE);
  
  FLASH_Config();
  
  EXTI_DeInit();
  
//You should add:
// Define FLASH programming time 
//FLASH_SetProgrammingTime(FLASH_PROGRAMTIME_STANDARD);

//optbyte1 = FLASH_ReadOptionByte(0x4803); //255 by def
//optbyte2 = FLASH_ReadOptionByte(0x4804); //255 by def
/*
if (optbyte != 765)
{
FLASH_Unlock(FLASH_MEMTYPE_DATA);     // unlock data memory by passing the RASS key in the proper order
FLASH_ProgramOptionByte(0x4803, 0xFD);     // byte OPT2 resides at address x4803, write a 1 to bit 7.  This will also write to the NOPT2 complement byte
FLASH_Lock(FLASH_MEMTYPE_DATA);       // re-lock data memory
}
  */
  
  //General purpose timer
  TIM4_Config(); 

  #ifdef DFS_90
  HotAir_Config();
  #endif
  
  #ifndef DFS_90
  GPIO_Init(CONTROL_GPIO_PORT, CONTROL_GPIO_PIN, GPIO_MODE_OUT_PP_LOW_FAST);
  #endif
  
  Temperature_ADC_Config();  
  
  STM_EVAL_SEGInit(SEG1);
  STM_EVAL_SEGInit(SEG2);
  STM_EVAL_SEGInit(SEG3);
  
  STM_EVAL_LEDInit(LEDA);
  STM_EVAL_LEDInit(LEDB);
  STM_EVAL_LEDInit(LEDC);
  STM_EVAL_LEDInit(LEDD);
  STM_EVAL_LEDInit(LEDE);
  STM_EVAL_LEDInit(LEDF);
  STM_EVAL_LEDInit(LEDG);
  STM_EVAL_LEDInit(LEDP);

#ifndef SOLDERING_VAR2
  //STM_EVAL_LEDInit(LEDP);
#endif
//  STM_EVAL_SEGOn(SEG1);
//  STM_EVAL_SEGOn(SEG2);
//  STM_EVAL_SEGOn(SEG3);
//  
//  STM_EVAL_LEDOn(LEDA);
//  STM_EVAL_LEDOn(LEDB);
//  STM_EVAL_LEDOn(LEDC);
//  STM_EVAL_LEDOn(LEDD);
//  STM_EVAL_LEDOn(LEDE);
//  STM_EVAL_LEDOn(LEDF);
//  STM_EVAL_LEDOn(LEDG);
//  
//  STM_EVAL_LEDOff(LEDA);
//  STM_EVAL_LEDOff(LEDB);
//  STM_EVAL_LEDOff(LEDC);
//  STM_EVAL_LEDOff(LEDD);
//  STM_EVAL_LEDOff(LEDE);
//  STM_EVAL_LEDOff(LEDF);
//  STM_EVAL_LEDOff(LEDG);
//  STM_EVAL_LEDOff(LEDP);
//  
//  STM_EVAL_SEGOff(SEG1);
//  STM_EVAL_SEGOff(SEG2);
//  STM_EVAL_SEGOff(SEG3);
  
  
  //STM_EVAL_LEDOn(LEDP);
  //GPIO_Init(ENC_DN_BUTTON_PORT, ENC_DN_BUTTON_PIN, GPIO_MODE_IN_PU_NO_IT);
  //GPIO_Init(ENC_UP_BUTTON_PORT, ENC_UP_BUTTON_PIN, GPIO_MODE_IN_PU_NO_IT);
  STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_GPIO);
  STM_EVAL_PBInit(BUTTON_UP, BUTTON_MODE_GPIO);
  STM_EVAL_PBInit(BUTTON_DOWN, BUTTON_MODE_GPIO);
  STM_EVAL_PBInit(BUTTON_REED, BUTTON_MODE_GPIO);
  
  ssegInit();
  
  ssegWriteStr("1.0.1", 5, SEG1);
  
  enableInterrupts();
  
  #ifdef DFS_90
  HotAir_Main();
  #endif
  
  #ifdef SOLDERING_HAKKO_A1321
  Soldering_Main();
  #endif
  
  while(1)
  {
    /*
    #if 0
     for (level = 0; level < calUpperLimit; level +=5)
     {
       Delayms(1);
     }
     
          for (level = calUpperLimit; level > 0; level -=5)
     {
       Delayms(1);
     }
    #else   
    RawData  = GetAdcValue(ADC_SOLDER_TEMP_CHANNEL);
    SmoothData = SmoothData - (LPF_Beta * (SmoothData - RawData));
    level = ((int)SmoothData)*26;
    #endif
    */
  }
}
Exemplo n.º 15
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main()
{

#ifdef FAST_I2C_MODE
  /* system_clock / 1 */
  CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);
#else
  /* system_clock / 2 */
  CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV2);
#endif

  /* Initialize LEDs mounted on STM8/128-EVAL board */
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);
  STM_EVAL_LEDInit(LED3);
  STM_EVAL_LEDInit(LED4);
	
	STM_EVAL_LEDOff(LED1);
  STM_EVAL_LEDOff(LED2);
  STM_EVAL_LEDOff(LED3);
  STM_EVAL_LEDOff(LED4);


  /* I2C Initialize */
  I2C_Init(I2C_SPEED, 0xA0, I2C_DUTYCYCLE_2, I2C_ACK_CURR, I2C_ADDMODE_7BIT, 16);


  /* Enable Buffer and Event Interrupt*/
  I2C_ITConfig((I2C_IT_TypeDef)(I2C_IT_EVT | I2C_IT_BUF) , ENABLE);

  enableInterrupts();

  /* TXBuffer initializtion */
  for (i = 0; i < BUFFERSIZE; i++)
    TxBuffer[i] = i;

  /* Send START condition */
  I2C_GenerateSTART(ENABLE);
  while (NumOfBytes);
  while (I2C_GetFlagStatus(I2C_FLAG_BUSBUSY));

  /* Add a delay to be sure that communication is finished */
  Delay(0xFFFF);

  /*****  reception phase ***/
  /*  Wait while the bus is busy */
  while (I2C_GetFlagStatus(I2C_FLAG_BUSBUSY));

  /* Send START condition */
  I2C_GenerateSTART(ENABLE);

  /* Test on EV5 and clear it */
  while (!I2C_CheckEvent(I2C_EVENT_MASTER_MODE_SELECT));

#ifdef TEN_BITS_ADDRESS
  /* Send Header to Slave for write */
  I2C_SendData(HEADER_ADDRESS_Write);

  /* Test on EV9 and clear it*/
  while (!I2C_CheckEvent(I2C_EVENT_MASTER_MODE_ADDRESS10));

  /* Send slave Address */
  I2C_Send7bitAddress(SLAVE_ADDRESS, I2C_DIRECTION_TX);

  /* Test on EV6 and clear it */
  while (!I2C_CheckEvent(I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));

  /* Repeated Start */
  I2C_GenerateSTART(ENABLE);

  /* Test on EV5 and clear it */
  while (!I2C_CheckEvent(I2C_EVENT_MASTER_MODE_SELECT));

  /* Send Header to Slave for Read */
  I2C_SendData(HEADER_ADDRESS_Read);

  /* Test on EV6 and clear it */
  while (!I2C_CheckEvent(I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));

#else
  /* Send slave Address for write */
  I2C_Send7bitAddress(SLAVE_ADDRESS, I2C_DIRECTION_RX);

  /* Test on EV6 and clear it */
  while (!I2C_CheckEvent(I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));
#endif /* TEN_BITS_ADDRESS */

  /* While there is data to be read */
  while (NumByteToRead)
  {
#ifdef SAFE_PROCEDURE
    if (NumByteToRead != 3) /* Receive bytes from first byte until byte N-3 */
    {
      while ((I2C_GetFlagStatus(I2C_FLAG_TRANSFERFINISHED) == RESET)); /* Poll on BTF */

      /* Read a byte from the Slave */
      RxBuffer[Rx_Idx] = I2C_ReceiveData();

      /* Point to the next location where the byte read will be saved */
      Rx_Idx++;

      /* Decrement the read bytes counter */
      NumByteToRead--;
    }

    if (NumByteToRead == 3)  /* it remains to read three data: data N-2, data N-1, Data N */
    {
      /* Data N-2 in DR and data N -1 in shift register */
      while ((I2C_GetFlagStatus(I2C_FLAG_TRANSFERFINISHED) == RESET)); /* Poll on BTF */

      /* Clear ACK */
      I2C_AcknowledgeConfig(I2C_ACK_NONE);

      /* Disable general interrupts */
      disableInterrupts();

      /* Read Data N-2 */
      RxBuffer[Rx_Idx] = I2C_ReceiveData();

      /* Point to the next location where the byte read will be saved */
      Rx_Idx++;

      /* Program the STOP */
      I2C_GenerateSTOP(ENABLE);

      /* Read DataN-1 */
      RxBuffer[Rx_Idx] = I2C_ReceiveData();

      /* Enable General interrupts */
      enableInterrupts();

      /* Point to the next location where the byte read will be saved */
      Rx_Idx++;

      while ((I2C_GetFlagStatus(I2C_FLAG_RXNOTEMPTY) == RESET)); /* Poll on RxNE */

      /* Read DataN */
      RxBuffer[Rx_Idx] = I2C_ReceiveData();

      /* Reset the number of bytes to be read by master */
      NumByteToRead = 0;

    }
#else
    if (NumByteToRead == 1)
    {
      /* Disable Acknowledgement */
      I2C_AcknowledgeConfig(I2C_ACK_NONE);

      /* Send STOP Condition */
      I2C_GenerateSTOP(ENABLE);

      /* Poll on RxNE Flag */
      while ((I2C_GetFlagStatus(I2C_FLAG_RXNOTEMPTY) == RESET));
      /* Read a byte from the Slave */
      RxBuffer[Rx_Idx] = I2C_ReceiveData();

      /* Point to the next location where the byte read will be saved */
      Rx_Idx++;

      /* Decrement the read bytes counter */
      NumByteToRead--;
    }

    /* Test on EV7 and clear it */
    if (I2C_CheckEvent(I2C_EVENT_MASTER_BYTE_RECEIVED) )
    {
      /* Read a byte from the EEPROM */
      RxBuffer[Rx_Idx] = I2C_ReceiveData();

      /* Point to the next location where the byte read will be saved */
      Rx_Idx++;

      /* Decrement the read bytes counter */
      NumByteToRead--;
	}
#endif /* SAFE_PROCEDURE */
  }

  /* check if sent and received data are not corrupted */
  TransferStatus1 = Buffercmp((uint8_t*)TxBuffer, (uint8_t*) RxBuffer, BUFFERSIZE);

  if (TransferStatus1 != FAILED)
  {
    while (1)
    {
      /* Toggle LED1*/
      STM_EVAL_LEDToggle(LED1);
      /* Insert delay */
      Delay(0x7FFF);
    }
  }
  else
  {
    while (1)
    {
      /* Toggle LED4*/
      STM_EVAL_LEDToggle(LED4);
      /* Insert delay */
      Delay(0x7FFF);
    }
  }
}
Exemplo n.º 16
0
static void CLK_Config(void){
    //CLK_DeInit();
    CLK_HSIPrescalerConfig(CLK_PRESCALER_CPUDIV128);
}
Exemplo n.º 17
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main(void)
{
   /*High speed internal clock prescaler: 1*/
   CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);

   /* UART1 configuration -------------------------------------------------------*/
   /* UART1 configured as follow:
          - Word Length = 8 Bits
          - 1 Stop Bit
          - No parity
          - BaudRate = 9600 baud
          - UART1 Clock enabled
          - Polarity Low
          - Phase Middle
          - Last Bit enabled
          - Receive and transmit enabled
   */
  UART1_DeInit();
  
  UART1_Init((uint32_t)9600, UART1_WORDLENGTH_8D, UART1_STOPBITS_1, UART1_PARITY_NO, 
              (UART1_SyncMode_TypeDef)(UART1_SYNCMODE_CLOCK_ENABLE | UART1_SYNCMODE_CPOL_LOW |UART1_SYNCMODE_CPHA_MIDDLE |UART1_SYNCMODE_LASTBIT_ENABLE),
              UART1_MODE_TXRX_ENABLE);
  UART1_Cmd(DISABLE);

  /* SPI configuration */
  SPI_DeInit();
  /* Initialize SPI in Slave mode  */
  SPI_Init(SPI_FIRSTBIT_LSB, SPI_BAUDRATEPRESCALER_2, SPI_MODE_SLAVE, SPI_CLOCKPOLARITY_LOW,
           SPI_CLOCKPHASE_1EDGE, SPI_DATADIRECTION_2LINES_FULLDUPLEX, SPI_NSS_SOFT,(uint8_t)0x07);

  /* Enable the UART1*/
  UART1_Cmd(ENABLE);
  
	Delay(0xFFF);
  
	/* Enable the SPI*/
  SPI_Cmd(ENABLE);
  
    while (NbrOfDataToRead--)
    {
        /* Wait until end of transmit */
        while (SPI_GetFlagStatus(SPI_FLAG_TXE)== RESET)
        {
        }
        /* Write one byte in the SPI Transmit Data Register */
        SPI_SendData(TxBuffer2[TxCounter]);
        /* Write one byte in the UART1 Transmit Data Register */
        UART1_SendData8(TxBuffer1[TxCounter++]);
        /* Wait until end of transmit */
        while (UART1_GetFlagStatus(UART1_FLAG_TXE) == RESET)
        {
        }
        /* Wait the byte is entirely received by UART1 */
        while (UART1_GetFlagStatus(UART1_FLAG_RXNE) == RESET)
        {
        }
        /* Store the received byte in the RxBuffer1 */
        RxBuffer1[RxCounter] = UART1_ReceiveData8();
        /* Wait the byte is entirely received by SPI */
        while (SPI_GetFlagStatus(SPI_FLAG_RXNE) == RESET)
        {
        }
        /* Store the received byte in the RxBuffer2 */
        RxBuffer2[RxCounter++] = SPI_ReceiveData();
    }

    /* Check the received data with the sent ones */
    TransferStatus1 = Buffercmp(TxBuffer1, RxBuffer2, TxBufferSize1);
    /* TransferStatus = PASSED, if the data transmitted from UART1 and received by SPI are the same */
    /* TransferStatus = FAILED, if the data transmitted from UART1 and received by SPI are different */
    TransferStatus2 = Buffercmp(TxBuffer2, RxBuffer1, TxBufferSize2);
    /* TransferStatus = PASSED, if the data transmitted from SPI and received by UART1 are the same */
    /* TransferStatus = FAILED, if the data transmitted from SPI and received by UART11 are different */

    while (1);
}
Exemplo n.º 18
0
void clk_init(void)
{
    /*High speed internal clock prescaler: 1*/
   CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);
}
Exemplo n.º 19
0
Arquivo: main.c Projeto: msrLi/Robot
void main(void)
{
  uint8_t i;
  BitStatus bytes;
  CLK_HSICmd(ENABLE);//开始内部高频RC
  CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);//不分频  16MHz
  /* Initialize I/Os in Output Mode */
  init_usart1();   // 输入判断
  GPIO_Init(GPIOA, GPIO_PIN_3, GPIO_MODE_OUT_PP_LOW_FAST);// 输出 模式 用于Trag 
  GPIO_Init(GPIOA, GPIO_PIN_2, GPIO_MODE_OUT_PP_LOW_FAST);// 输出 模式 用于Trag 
  GPIO_WriteHigh(GPIOA, GPIO_PIN_2);
  GPIO_Init(GPIOA,GPIO_PIN_1,GPIO_MODE_IN_PU_NO_IT);       // 输入包含  上拉  中断 
//  GPIO_Init(GPIOA,GPIO_PIN_1,GPIO_MODE_IN_PU_IT); 
//  EXTI_SetExtIntSensitivity(EXTI_PORT_GPIOA,EXTI_SENSITIVITY_RISE_ONLY); 
  InitADC();
  enableInterrupts();
  flageExtiA=0;  
  sendBuff[0]=DEVICE_ID;
  sendBuff[3]=0xff;
  sendBuff[4]=0xff;
  sendBuff[5]=0xFF;
  sendBuff[6]=0xA0;
  sendBuff[7]=0xFA; 

  while (1)
  {
     
    bytes=GPIO_ReadInputPin(GPIOA,GPIO_PIN_1);
    if(bytes==RESET && flageExtiA==0)    
    {
        flageExtiA=1;  
        GPIO_WriteReverse(GPIOA,GPIO_PIN_3);  
        for(i=0;i<8;i++)
        {  
          Send(sendBuff[i]);
         }
    }else if(bytes!=RESET)
    {
      flageExtiA=0;
    }  
    datas=readADCs();
  sendBuff[5]=0;
  sendBuff[1]=(uint8_t)(datas&0xff);
  sendBuff[2]=(uint8_t)((datas>>8)&0xff);
  for(i=0;i<5;i++)
  {
    sendBuff[5]+=sendBuff[i];
  }      
//    datas=datas;
//    bytes=GPIO_ReadInputPin(GPIOA,GPIO_PIN_1);
//    if(flageExtiA!=1)
//    {
//      sendBuff[1]=(uint8_t)(datas&0xff);
//      sendBuff[2]=(uint8_t)((datas>>8)&0xff);
//      sendBuff[5]=0;
//      for(i=0;i<5;i++)
//      {
//        sendBuff[5]+=sendBuff[i];
//      }
//    }
  }
  
}
Exemplo n.º 20
0
/**
  * @brief  Configure system clock to run at 16Mhz
  * @param  None
  * @retval None
  */
static void CLK_Config(void)
{
    /* Initialization of the clock */
    /* Clock divider to HSI/1 */
    CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);
}
Exemplo n.º 21
0
void clk_config(void)
{
  CLK_DeInit();
  CLK_HSICmd(ENABLE);
  CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);
}
Exemplo n.º 22
0
/**
  * @brief Example main entry point.
  * @par Parameters:
  * None
  * @retval
  * None
  */
void main(void)
{

    u8 i = 0;

    /* Initialization of the clock */
    /* Clock divider to HSI/1 */
    CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);

    /* Initialization of I/Os in Output Mode */
    GPIO_Init(LEDS_PORT, (LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN), GPIO_MODE_OUT_PP_LOW_FAST);

    /* Initialization of I/O in Input Mode with Interrupt */
    GPIO_Init(BUTTON_PORT, BUTTON_PIN, GPIO_MODE_IN_FL_IT);

    /* Initialization of the Interrupt sensitivity */
    EXTI_SetExtIntSensitivity(EXTI_PORT_GPIOC, EXTI_SENSITIVITY_FALL_ONLY);

    /* BEEP calibration */

    BEEP_LSICalibrationConfig(LSIMeasurment());

    GPIO_Write(LEDS_PORT, (LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN)); /* All LEDs ON */

    /* Initialize SPI for LCD */
    SPI_DeInit();
    SPI_Init(SPI_FIRSTBIT_MSB, SPI_BAUDRATEPRESCALER_128, SPI_MODE_MASTER, SPI_CLOCKPOLARITY_HIGH, SPI_CLOCKPHASE_2EDGE, SPI_DATADIRECTION_1LINE_TX, SPI_NSS_SOFT, 0x07);
    SPI_Cmd(ENABLE);

    /* Initialize LCD */
    LCD_Init();

    /* Clear LCD lines */
    LCD_Clear();

    /* Enable general interrupts for Key button reading */
    enableInterrupts();

    LCD_PrintString(LCD_LINE1, ENABLE, DISABLE, "  BEEPER OFF");
    LCD_PrintString(LCD_LINE2, ENABLE, DISABLE, "   Press Key");

    while (1)
    {
        /* Check button status */
        if (ButtonPressed == TRUE) /* Button is pressed */
        {
            ButtonPressed = FALSE;
            /* Change BEEP frequency */
            switch (i)
            {
            case 0:
                BEEP_Cmd(DISABLE);
                Delay(100);
                BEEP_Init(BEEP_FREQUENCY_1KHZ);
                BEEP_Cmd(ENABLE);
                GPIO_Write(LEDS_PORT, LED1_PIN); /* LED1 ON */
                LCD_PrintString(LCD_LINE1, ENABLE, DISABLE, "  BEEPER 1kHz");
                i = 1;
                break;
            case 1:
                BEEP_Cmd(DISABLE);
                Delay(100);
                BEEP_Init(BEEP_FREQUENCY_2KHZ);
                BEEP_Cmd(ENABLE);
                GPIO_Write(LEDS_PORT, LED2_PIN); /* LED2 ON */
                LCD_PrintString(LCD_LINE1, ENABLE, DISABLE, "  BEEPER 2kHz");
                i = 2;
                break;
            case 2:
                BEEP_Cmd(DISABLE);
                Delay(100);
                BEEP_Init(BEEP_FREQUENCY_4KHZ);
                BEEP_Cmd(ENABLE);
                GPIO_Write(LEDS_PORT, LED3_PIN); /* LED3 ON */
                LCD_PrintString(LCD_LINE1, ENABLE, DISABLE, "  BEEPER 4kHz");
                i = 3;
                break;
            case 3:
                BEEP_Cmd(DISABLE);
                GPIO_Write(LEDS_PORT, LED4_PIN); /* LED4 ON */
                LCD_PrintString(LCD_LINE1, ENABLE, DISABLE, "  BEEPER OFF");
                i = 0;
                break;
            default:
                break;
            }
        }

    }

}
Exemplo n.º 23
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main(void)
{
    uint32_t i = 0;
    /* Configure the multiplexer on the evalboard to select the smartCard*/
    Multiplexer_EvalBoard_Config();

    /* Configure the GPIO ports */
    GPIO_Config();
    
    /*High speed internal clock prescaler: 1*/
    CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);

    /* Enable general interrupts */
    enableInterrupts();

    UART1_DeInit();
    /* UART1 configuration -------------------------------------------------------*/
    /* UART1 configured as follow:
          - Word Length = 9 Bits
          - 1.5 Stop Bit
          - Even parity
          - BaudRate = 10752 baud
          - Receive and transmit enabled
          - UART1 Clock enabled
    */
  UART1_Init((uint32_t)10752, UART1_WORDLENGTH_9D, UART1_STOPBITS_1_5, UART1_PARITY_EVEN,
              UART1_SYNCMODE_CLOCK_ENABLE, UART1_MODE_TXRX_ENABLE);

    /* UART1 Clock set to 4MHz (frequence master 16 MHZ / 4) */
    UART1_SetPrescaler(0x02);

    /* UART1 Guard Time set to  Bit */
    UART1_SetGuardTime(0x2);

    /* Enable the UART1 Parity Error Interrupt */
    UART1_ITConfig(UART1_IT_PE, ENABLE);

    /* Enable the NACK Transmission */
    UART1_SmartCardNACKCmd(ENABLE);

    /* Enable the Smart Card Interface */
    UART1_SmartCardCmd(ENABLE);

    /* Loop while no smart card is detected */
    while ((GPIO_ReadInputData(GPIOE)& 0x01) == 0x00)
    {
    }
    
    /* PG7 - SmartCard_/CMDVCC: low */
    GPIO_WriteLow(GPIOG, GPIO_PIN_7);  

    /* release SmartCard_RESET signal */
    GPIO_WriteLow(GPIOG, GPIO_PIN_5);  

    for (i = 0; i < 6000; i++)
    {
    }
    /* set SmartCard_RESET signal */
    GPIO_WriteHigh(GPIOG, GPIO_PIN_5);  


    /* Read Smart Card ATR response */
    for (index = 0; index < 40; index++)
    {
        Counter = 0;
        while ((UART1_GetFlagStatus(UART1_FLAG_RXNE) == RESET) && (Counter != SC_Receive_Timeout))
        {
            Counter++;
        }

        if (Counter != SC_Receive_Timeout)
        {
            DST_Buffer[index] = UART1_ReceiveData8();
        }
    }

    /* Decode ATR */
    CardProtocol = SC_decode_Answer2reset(DST_Buffer);

    /* Test if the inserted card is ISO7816-3 T=0 compatible */
    if (CardProtocol == 0)
    {
        /* Inserted card is ISO7816-3 T=0 compatible */
        ATRDecodeStatus = PASSED;
    }
    else
    {
        /* Inserted smart card is not ISO7816-3 T=0 compatible */
        ATRDecodeStatus = FAILED;
    }

    while (1)
  {}
}