/*************************************************************************************************************************
* Function: TIM3.C
* Function: Infrared signal capture and transmission
* Parameters: None
* Return: None
* Dependency: underlying read and write functions
*************************************************************************************************************************/
voidIRDA_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
//LED1 LED2
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); //Enable PA, PD port clock
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); //Enable PA, PD port clock
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11|GPIO_Pin_12; //
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //Push-pull output
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //IO port speed is 50MHz
GPIO_Init(GPIOA, &GPIO_InitStructure); //Initialize GPIOA according to the set parameters.8
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; //PA6 clears the previous settings
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; //PA6 clears the previous settings
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_SetBits(GPIOA,GPIO_Pin_5); //PA.8 output high
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11; //PA6 clears previous settings
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
//Watchdog SP706 input pin PA7
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; //PA7 clears the previous settings
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
void TIM3_Int_Init(u16 arr,u16 psc)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_ICInitTypeDef TIM_ICInitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); //Clock enable
TIM_TimeBaseStructure.TIM_Period = arr; //Set the value of the auto-reload register period to count to 5000 for 500ms before the next update event
TIM_TimeBaseStructure.TIM_Prescaler =psc; //Set the prescaler value used as the TIMx clock frequency divisor 10Khz counting frequency
TIM_TimeBaseStructure.TIM_ClockDivision = 0; //Set clock division: TDTS = Tck_tim
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //TIM up counting mode
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure); //Initialize the time base unit of TIMx according to the parameters specified in TIM_TimeBaseInitStruct
TIM_ICInitStructure.TIM_Channel = TIM_Channel_1;
TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Falling;
TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
TIM_ICInitStructure.TIM_ICFilter = 0x0;
TIM_ICInit(TIM3, &TIM_ICInitStructure);
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn; //TIM3中断
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2; //Preempt priority level 0
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //From priority level 3
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ channel is enabled
NVIC_Init(&NVIC_InitStructure); //Initialize peripheral NVIC registers according to the parameters specified in NVIC_InitStruct
TIM_ITConfig(TIM3,TIM_IT_CC1,DISABLE); //Do not allow CC1IE to capture interrupts
TIM_ITConfig(TIM3,TIM_IT_Update,DISABLE);//Update interrupt is not allowed
TIM_Cmd(TIM3,DISABLE); //Enable timer 3
}
void TIM_Polarityset(u8 Polarity)
{
if(Polarity == 0) TIM3->CCER &= ~(1<<1); //Rise
else TIM3->CCER |= 1<<1; //Decline
}
void TIM3_IRQHandler(void) //TIM3中断
{
if(TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET) //Check whether the specified TIM interrupt occurs: TIM interrupt source
{
TIM_ClearITPendingBit(TIM3,TIM_IT_Update ); // Clear TIMx interrupt pending bit: TIM interrupt source
switch(Timer3)
{
case 0:
{
Timer3++;
if(u8Lev == 0x0) GPIO_SetBits(GPIOA,GPIO_Pin_5);
else GPIO_ResetBits(GPIOA,GPIO_Pin_5);
break;
}
case 1:
{
Timer3++;
GPIO_SetBits(GPIOA,GPIO_Pin_5);
break;
}
case 2:
{
Timer3 = 0;
Timer_PWM++;
if(Timer_PWM >= Capture)
{
Capture = u16P[u16Pcn++];
if(Capture == 0xffff) // Output ends
{
TIM_ITConfig(TIM3,TIM_IT_Update,DISABLE);
TIM_Cmd(TIM3,DISABLE);
GPIO_SetBits(GPIOA,GPIO_Pin_5);
irad_launch = 1;
u8FSMirda = IRDA_FSM_DILE;
}
else
{
u8Lev = ~u8Lev;
Timer_PWM = 0;
}
}
break;
}
default:
{
Timer3 = 0;
}
}
}
if(TIM_GetITStatus(TIM3, TIM_IT_CC1) == SET)
{
//TIM_ICInitTypeDef TIM_ICInitStructure;
/* Clear TIM3 Capture compare interrupt pending bit */
TIM_ClearITPendingBit(TIM3, TIM_IT_CC1);
u8Timerirda = 0;
if(CaptureNumber == 0)
{
/* Get the Input Capture value */
IC3ReadValue1 = TIM_GetCapture1(TIM3);
CaptureNumber = 1;
u8Lev = 0xff;
}
else if(CaptureNumber == 1)
{
/* Get the Input Capture value */
IC3ReadValue2 = TIM_GetCapture1(TIM3);
/* Capture computation */
if (IC3ReadValue2 > IC3ReadValue1)
{
Capture = (IC3ReadValue2 - IC3ReadValue1);
}
else
{
Capture = ((0xFFFF - IC3ReadValue1) + IC3ReadValue2);
}
u16P[u16Pcn++] = Capture;
IC3ReadValue1 = IC3ReadValue2;
/* Frequency computation */
//TIM3Freq = (uint32_t) SystemCoreClock / Capture;
//CaptureNumber = 0;
}
u8Lev = ~u8Lev;
TIM_Polarityset(u8Lev);
}
}
Previous article:DS18B20 driver based on STM32
Next article:Linux kernel transplantation based on S3C2440 and yaffs2 file system production--starting system
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Detailed explanation of intelligent car body perception system
- How to solve the problem that the servo drive is not enabled
- Why does the servo drive not power on?
- What point should I connect to when the servo is turned on?
- How to turn on the internal enable of Panasonic servo drive?
- What is the rigidity setting of Panasonic servo drive?
- How to change the inertia ratio of Panasonic servo drive
- What is the inertia ratio of the servo motor?
- Is it better for the motor to have a large or small moment of inertia?
- What is the difference between low inertia and high inertia of servo motors?
- STM8 serial port sending crashes, has anyone encountered this?
- dsp2812 12864 LCD display source code
- FPGA Practice (I) Light up 8 LEDs
- The first year of Wi-Fi 6 popularization has arrived. What chips and products are available?
- The new DY-FFTB6638 MSP430 development kit
- Various commonly used integrated IC component package libraries, is there any need?
- Please help me analyze the circuit. Thanks.
- Why does a seg pin (used for LCD) consume 40uA more when its ADS register is set to digital than when it is set to ADS?
- Microcontroller learning notes, teach you how to learn in three steps!
- The most comprehensive list of 5G segment leading concept stocks in history