|
本帖最后由 wuwovicky 于 2015-3-11 13:12 编辑 ?/ ]" @) u& H6 K' z 原因:图一,画PCB时,因为看到PC13离LED比较近,就用PC13来驱动LED,查看手册后,也没说不能驱动LED,所以硬件是可以的。但是在调试软件时发现时钟点亮不了LED,然后在网上找资料,但都是STMF103系列的(PC13最大输出速度不能大于2MHZ,且不能驱动LED)。8 C% T' f# S) q8 m. \ STM32F103系列,当PC14,PC15外接晶振时,好像PC13不能当IO口使用,用过103的人谁帮忙验证下? 6 e* M7 p1 t# S/ r$ v' t) R 我又仔细看了下STM32L的参考手册(RM0038),7.3.15 Selection of RTC_AF1 alternate function章节,可以当IO口使用,于是启动KEIL调试,查看图二所描述的寄存器, 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口功能了。 6 T7 R+ s6 p* [0 x0 g8 a3 E void LED_Config(void)( `, t1 D: U) [) H1 v7 M7 m/ ~ {1 d3 f$ r# _1 [7 X. N GPIO_InitTypeDef GPIO_InitStructure; RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC,ENABLE);. f& o9 ^. R0 a, }" L: |/ }5 c+ O _ /* Configure the test LED pin */4 d3 c5 ?1 z1 }+ Q GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;8 E5 m" q+ `" W/ Z GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;. I6 q8 g& c4 B GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;% {/ l8 c6 D( \. E1 z# ~, h GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;" N( [- ~# r! c. P" f2 x GPIO_Init(GPIOC, &GPIO_InitStructure);7 q# n' b7 I# v: X }$ V6 i& @ _( {! e $ \- p6 R+ t2 w void RTC_Config(void) { /* Enable the PWR clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); * Y' W6 K8 N* o2 K /* Allow access to RTC */) Q) d& C" w+ G g w0 v PWR_RTCAccessCmd(ENABLE); ' w1 q1 d& {2 W* s7 ^" L #if defined (RTC_CLOCK_SOURCE_LSI) /* LSI used as RTC source clock*/" S0 R9 ?' W% _8 ~9 X( t /* The RTC Clock may varies due to LSI frequency dispersion. */3 x1 f; v! j; E5 ]- R, [' F, J3 `3 l /* Enable the LSI OSC */ RCC_LSICmd(ENABLE); /* Wait till LSI is ready */ while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET)0 ~& b3 V$ H1 G9 K9 V { } /* Select the RTC Clock Source */ RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);: r9 Z: U, i* w , g6 u# I4 T3 V: G9 L7 \8 Y# z SynchPrediv = 0xFF; AsynchPrediv = 0x7F; #elif defined (RTC_CLOCK_SOURCE_LSE) /* LSE used as RTC source clock */+ A0 v* {' n+ K) n6 ?3 u! b /* Enable the LSE OSC */ RCC_LSEConfig(RCC_LSE_ON); /* Wait till LSE is ready */ while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)* U$ f# i0 x1 ^4 D, H {; P) C( Z6 ?8 M* h7 j9 r } /* Select the RTC Clock Source */4 S9 r: j7 H2 s; W3 w RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);- W7 P: m2 j: ~4 x2 D D: l ' v7 f+ A8 b' N3 l/ y SynchPrediv = 0xFF;' l7 [- {% U. U& i1 o7 j4 x# Z. P AsynchPrediv = 0x7F; & r' j8 U H& a7 j( P/ t" w #else$ _& v) V. I& G; a. F9 ^6 J #error Please select the RTC Clock source inside the main.c file+ L, \7 g7 ^+ R" W6 H1 ? #endif /* RTC_CLOCK_SOURCE_LSI */ " j$ S H, L1 ~6 ^- S7 s /* Enable the RTC Clock */8 o; ?1 a$ m& \% B$ K RCC_RTCCLKCmd(ENABLE); ! ?) a7 o6 a" O9 K /* Wait for RTC APB registers synchronisation */ RTC_WaitForSynchro(); /* Enable The TimeStamp */" ^9 S7 Q) S9 ]; a% j RTC_TimeStampCmd(RTC_TimeStampEdge_Rising, DISABLE); //RTC->CR TSE位清0 RTC_TimeStampCmd(RTC_TimeStampEdge_Falling, DISABLE); //RTC->CR TSE位清0 }4 |& F2 }: w8 n6 P # b8 r/ w- z- P, G4 w9 f 成功点亮LED,并且能够使用RTC& k; n' t: E/ h$ f5 i: U 7 c( n$ K# |9 \% E! n, Z |
å¾ä¸
å¾äº
å¾ä¸
微信公众号
手机版
对的,2.4*4.1厘米
哈哈,还行~