
本帖最后由 wuwovicky 于 2015-3-11 13:12 编辑 原因:图一,画PCB时,因为看到PC13离LED比较近,就用PC13来驱动LED,查看手册后,也没说不能驱动LED,所以硬件是可以的。但是在调试软件时发现时钟点亮不了LED,然后在网上找资料,但都是STMF103系列的(PC13最大输出速度不能大于2MHZ,且不能驱动LED)。 STM32F103系列,当PC14,PC15外接晶振时,好像PC13不能当IO口使用,用过103的人谁帮忙验证下? 我又仔细看了下STM32L的参考手册(RM0038),7.3.15 Selection of RTC_AF1 alternate function章节,可以当IO口使用,于是启动KEIL调试,查看图二所描述的寄存器,' s( k0 z2 j( [1 D8 t" C RTC->CR OSE位L[1:0] = 00;RTC->CR COE位= 0; RTC_TAFCR TAMP1E位 = 0; RTC->CR TSE位 = 1; PWR_CS EWUP2 = 0; 对照图二发现RTC->CR TSE位被置一了,对应的功能是时间戳侵入和侵入输入,浮空输入,所以只要将改为置0,就能够使用普通IO口功能了。 void LED_Config(void) {" ]# {- h5 n/ k GPIO_InitTypeDef GPIO_InitStructure; & m6 P% V& I; X" x# u RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC,ENABLE);. Y3 H1 C1 n/ l) s& W+ M /* Configure the test LED pin */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;/ Z) \" [' ?1 t& g7 r/ r: I3 O$ s GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;" T7 `/ u) z. K; B$ K% Y GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;* G: H/ }% y) W3 s* t GPIO_Init(GPIOC, &GPIO_InitStructure); }9 u* H4 b: i8 x6 B 7 S2 p6 ]% F* R void RTC_Config(void)2 o6 b3 k7 X8 `, o) z0 S {, ]' {: n; m5 | /* Enable the PWR clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); \# r2 W/ F J& J; c5 x. W; g' l /* Allow access to RTC */; d. E% A: i# y& } PWR_RTCAccessCmd(ENABLE);3 E6 D( ?: h# I4 \ #if defined (RTC_CLOCK_SOURCE_LSI) /* LSI used as RTC source clock*/" F. S" J5 \2 I+ y# M /* The RTC Clock may varies due to LSI frequency dispersion. */ /* Enable the LSI OSC */ * d7 R' u# t# }" w( L k5 C' J RCC_LSICmd(ENABLE); , N* {( U' W3 H( t9 O /* Wait till LSI is ready */ while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET) { } /* Select the RTC Clock Source */ RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);' O1 G6 d# S% R1 I & {+ y4 j K# ^ SynchPrediv = 0xFF; AsynchPrediv = 0x7F; - w5 L; W2 N# g" L& I" E #elif defined (RTC_CLOCK_SOURCE_LSE) /* LSE used as RTC source clock */5 h; T/ L. g2 l- f$ t2 f/ v /* Enable the LSE OSC */' d3 P5 u! y1 @( ^* e0 f. q RCC_LSEConfig(RCC_LSE_ON); 6 I3 a1 l) e; m /* Wait till LSE is ready */ while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET) {. w8 E% E' {% m' ~ } /* Select the RTC Clock Source */ RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE); SynchPrediv = 0xFF; AsynchPrediv = 0x7F;) Y7 \- P; @/ N H( ^+ u u #else #error Please select the RTC Clock source inside the main.c file #endif /* RTC_CLOCK_SOURCE_LSI */' x* u; \7 N3 ~2 V8 a /* Enable the RTC Clock */ RCC_RTCCLKCmd(ENABLE); & `4 J! _; W1 v" q( c9 A /* Wait for RTC APB registers synchronisation */ RTC_WaitForSynchro();# G! @5 b/ C2 b. s ( P* R2 H% f$ b5 Q: u/ V9 E /* Enable The TimeStamp */& `8 c A3 ]6 z RTC_TimeStampCmd(RTC_TimeStampEdge_Rising, DISABLE); //RTC->CR TSE位清0 RTC_TimeStampCmd(RTC_TimeStampEdge_Falling, DISABLE); //RTC->CR TSE位清0- E/ g. A' P4 ~6 ]: l4 y }0 P) J- o1 ]$ M# ~, c7 J0 m ' u0 Z3 ^: K* f 成功点亮LED,并且能够使用RTC # O6 F& t+ w5 X % A2 ]2 {, F* \ |
å¾ä¸
å¾äº
å¾ä¸
对的,2.4*4.1厘米
哈哈,还行~