|
本帖最后由 wuwovicky 于 2015-3-11 13:12 编辑 ! E/ ^" U6 K9 p$ R; n5 x7 W 原因:图一,画PCB时,因为看到PC13离LED比较近,就用PC13来驱动LED,查看手册后,也没说不能驱动LED,所以硬件是可以的。但是在调试软件时发现时钟点亮不了LED,然后在网上找资料,但都是STMF103系列的(PC13最大输出速度不能大于2MHZ,且不能驱动LED)。, V9 C7 [* h( j% o* [$ R STM32F103系列,当PC14,PC15外接晶振时,好像PC13不能当IO口使用,用过103的人谁帮忙验证下? 我又仔细看了下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口功能了。) N& ?$ L+ e% J9 \; t5 P void LED_Config(void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC,ENABLE);0 w. M' ]0 v3 V9 r; ?; N /* Configure the test LED pin */4 M3 x% l6 o( h& }! S1 ? GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;5 H: n! B3 ]; v9 M( G1 M GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;7 m3 S) }$ |( K0 ] GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;1 d& M/ U& t d$ o GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;9 w$ Z1 s& m% i J GPIO_Init(GPIOC, &GPIO_InitStructure); }: c, u3 P+ g* L! P& }3 A1 q2 R % @; B( w" ?. T# J) B4 F void RTC_Config(void) {( \; L* H% d5 N* M- i$ Z /* Enable the PWR clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);4 @0 |$ D6 i$ i% X /* Allow access to RTC */ PWR_RTCAccessCmd(ENABLE);+ {6 }, l" \; u, X; ]. ] ' i5 R" F- J; c+ [ #if defined (RTC_CLOCK_SOURCE_LSI) /* LSI used as RTC source clock*/" f0 x: I% [% @ /* The RTC Clock may varies due to LSI frequency dispersion. */ /* Enable the LSI OSC */ # a- K! M3 Y ~! N9 F RCC_LSICmd(ENABLE); " M* u" {% C! h/ u4 g) }& X /* Wait till LSI is ready */ while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET)# N) X% R+ J+ V5 W( B v7 { {3 z8 {2 P6 B: U! v! a3 S9 x4 c } /* Select the RTC Clock Source */4 V/ T7 q6 L- B8 z RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI); 0 v% A& C- a9 o+ B/ A9 Y- i% @ SynchPrediv = 0xFF;% j$ k! K+ X O9 ?) j5 \ AsynchPrediv = 0x7F;8 ~% L. O5 U" A- I #elif defined (RTC_CLOCK_SOURCE_LSE) /* LSE used as RTC source clock */ /* Enable the LSE OSC */ RCC_LSEConfig(RCC_LSE_ON); /* Wait till LSE is ready */ while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET) { } ! g! i: I- N* x4 K9 C# N /* Select the RTC Clock Source */ RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);- }# Q: B# E$ D5 P* A* N/ Y9 h SynchPrediv = 0xFF; AsynchPrediv = 0x7F; ( M; K- i2 r% w+ R9 z #else #error Please select the RTC Clock source inside the main.c file #endif /* RTC_CLOCK_SOURCE_LSI */ /* Enable the RTC Clock */ RCC_RTCCLKCmd(ENABLE);" m! U0 p% D" L /* Wait for RTC APB registers synchronisation */ RTC_WaitForSynchro();$ L# w+ t- P* n* G! j # t3 u, P5 \3 q4 c/ L0 N8 @ /* Enable The TimeStamp */ RTC_TimeStampCmd(RTC_TimeStampEdge_Rising, DISABLE); //RTC->CR TSE位清0 RTC_TimeStampCmd(RTC_TimeStampEdge_Falling, DISABLE); //RTC->CR TSE位清0 }$ u' E/ H" [! M1 g( x6 p( z1 [ ( x4 _5 P2 _, _& a" P8 I: ~ v 成功点亮LED,并且能够使用RTC , F/ i2 S0 d. h2 M9 z, g: o! J* Z 7 ^3 R6 L2 A5 `1 s L+ h , f' Z$ f+ E H* T |
å¾ä¸
å¾äº
å¾ä¸
微信公众号
手机版
对的,2.4*4.1厘米
哈哈,还行~