昨天上午拿到的st-link-ii和一块最小系统;
呵呵,东西到了,不好好看看心里过意不去,就着手做了一个简单的控制台(串口),顺便做了一下遥控解码,测试TIMx,
以前一直在看103的资料,最小系统上的却是101,我也懒得去换了,就用它了. 接线如下: UART2----PIN12(TX),PIN13(RX)--->对接到PL2303的TX,RX上去,便于笔记本调试嘛,
IR信号---PIN21 (图方便装,直接把遥控头的PIN2(GND)-->PIN23,PIN3(VS)-->PIN24,PIN1(信号)-->PIN21,因为是DEMO嘛,不用加电容了,呵呵,)
因为是48PIN封装,有些地方不能直接用LIB库中的源码, 下面是要注意的地方,使用UART2的PIN脚,不需重映射 用例程里的代码时注意去掉这句话: //GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE);
至于串口调通就不说了,以前好多兄弟都写过了, 下面主要说下遥控解码对时钟的基本设置: 配置TIM2的时钟为1MHz,这个每个cnt即为1us,便于计算时钟值, /* PCLK1 = HCLK/4 */ RCC_PCLK1Config(RCC_HCLK_Div4);能
/* TIM2 clock enable */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
/* Time base configuration */ TIM_TimeBaseStructure.TIM_Period = 65535; //时钟一直运行 TIM_TimeBaseStructure.TIM_Prescaler = 0; TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); /* --------------------------------------------------------------- TIM2 Configuration: Output Compare Timing Mode: TIM2CLK = 36 MHz, Prescaler = 36, TIM2 counter clock = 1 MHz ---------------------------------------------------------------*/ /* Prescaler configuration */ TIM_PrescalerConfig(TIM2, 36, TIM_PSCReloadMode_Immediate); /* TIM2 enable counter */ TIM_Cmd(TIM2, ENABLE);
配置PIN21下降沿中断 /* Configure PB.10 as input floating (EXTI Line 10) */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOB, &GPIO_InitStructure);
/* Enable the EXTI15_10 Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQChannel; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource10); /* Configure EXTI Line10 to generate an interrupt on falling edge */ EXTI_InitStructure.EXTI_Line = EXTI_Line10; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); /* Generate software interrupt: simulate a falling edge applied on EXTI line 9 */ EXTI_GenerateSWInterrupt(EXTI_Line9);
在中断中处理如下: if(EXTI_GetITStatus(EXTI_Line10) != RESET) { IrDecode(TIM_GetCounter(TIM2)); /* Toggle PB8 pin */ //收到遥控器时其中的一个小灯闪烁,交替变换亮暗 GPIO_WriteBit(GPIOB, GPIO_Pin_8, (BitAction)((1-GPIO_ReadOutputDataBit(GPIOB, GPIO_Pin_8)))); /* Clear the EXTI line 9 pending bit */ EXTI_ClearITPendingBit(EXTI_Line10); } 主循环任务也很简单,如下: UartConsoleMain(); // 检查有没有串口输入: // decode ir if (gIrMsgTx) // 看看有没有检测到IR按下: { key = gIrMsgTx; gIrMsgTx = MSG_NONE; printf("IrCode: %02x-%02x-%02x-%02x\r\n",gIrBuf[0],gIrBuf[1],gIrBuf[2],gIrBuf[3]); }
//写得很乱,呵呵,
-----------------------------
慢慢整理,并把其中的部分东西讲一讲,呵呵,因为近期在做资源规划,打算把STM32用到产品中去,前期加班抽空做得测试也没有白费,稍感欣慰…… 附图像:
|
walnutcy_696810119 2009-11-16 08:20
用户1487022 2009-11-16 01:16
walnutcy_696810119 2008-7-30 23:03