12
返回列表 发新帖
楼主: wfjwhy

[求助] KL05的RTC秒中断,怎么进不了中断

[复制链接]

该用户从未签到

124

主题

3600

帖子

0

金牌会员

Rank: 6Rank: 6

积分
5781
最后登录
1970-1-1
发表于 2015-9-6 10:28:57 | 显示全部楼层
本帖最后由 FSL_TICS_ZP 于 2015-9-6 10:29 编辑
wfjwhy 发表于 2015-9-6 08:50
刚看到,我用的RTC_INT就是版主在阿莫论坛的KL03例程移植过来的,这个论坛地址:http://www.freescaleic.o ...

我这边在FRDM-KL05Z上试过啊,也是可以使用的,我把代码贴上来,你对比一下rtc.c
  1. /********************************************************************/
  2. /*
  3. * Initialize the RTC
  4. *
  5. *
  6. * Parameters:
  7. *  seconds         Start value of seconds register
  8. *  alarm           Time in seconds of first alarm. Set to 0xFFFFFFFF to effectively disable alarm
  9. *  c_interval      Interval at which to apply time compensation can range from 1 second (0x0) to 256 (0xFF)
  10. *  c_value         Compensation value ranges from -127 32kHz cycles to +128 32 kHz cycles
  11. *                  80h Time prescaler register overflows every 32896 clock cycles.
  12. *                  FFh Time prescaler register overflows every 32769 clock cycles.
  13. *                  00h Time prescaler register overflows every 32768 clock cycles.
  14. *                  01h Time prescaler register overflows every 32767 clock cycles.
  15. *                  7Fh Time prescaler register overflows every 32641 clock cycles.
  16. *  rtc_irqc        interrupt configuration
  17. *                   |__RTC_INT_DIS        -disable interrupt
  18. *                  |__RTC_INT_INVALID    -Time Invaild Interrupt
  19. *                  |__RTC_INT_OVERFLOW   -Time Overflow Interrupt
  20. *                   |__RTC_INT_ALARM     -Time Alarm Interrupt
  21. *  isr_func        point to interrupt service function
  22. */

  23. uint8 RTC_Init(uint32 seconds, uint32 alarm, uint8 c_interval, uint8 c_value,uint8 rtc_irqc, RTC_ISR_CALLBACK isr_func)
  24. {
  25.   int i;
  26.   
  27.   SIM_SCGC6 |= SIM_SCGC6_RTC_MASK;
  28.   SIM_SOPT1 = SIM_SOPT1_OSC32KSEL(0);
  29.   disable_irq(20);
  30.   disable_irq(21);

  31.   RTC_CR  = RTC_CR_SWR_MASK;

  32.   RTC_CR  &= ~RTC_CR_SWR_MASK;  

  33.    if (RTC_SR & RTC_SR_TIF_MASK){
  34.         RTC_TSR = 0x00000000;   //  this action clears the TIF
  35.         printf("RTC Invalid flag was set - Write to TSR done to clears RTC_SR =  %#02X \n",  (RTC_SR) )  ;
  36.     }
  37.     /*Set time compensation parameters*/
  38.   RTC_TCR = RTC_TCR_CIR(c_interval) | RTC_TCR_TCR(c_value);
  39.    /*Enable the oscillator*/
  40. RTC_CR |= RTC_CR_OSCE_MASK|RTC_CR_SC16P_MASK;
  41.   
  42.   /*Wait to all the 32 kHz to stabilize, refer to the crystal startup time in the crystal datasheet*/
  43.   for(i=0;i<0x600000;i++);
  44.   
  45.   RTC_SR &= ~RTC_SR_TCE_MASK;
  46.   
  47.   if(rtc_irqc)
  48.   {
  49.     RTC_IER = (rtc_irqc & 0x07);
  50.    
  51.     RTC_ISR[0]=isr_func;
  52.    
  53.     enable_irq(20);
  54.   }

  55. //  RTC_CR |RTC_CR_SC16P_MASK;

  56.   RTC_TSR = seconds;

  57.   RTC_TAR = alarm;

  58.   RTC_SR |= RTC_SR_TCE_MASK;
  59.   
  60.   return 1;
  61. }


  62. /*
  63.    RTC interrupt service function
  64. */
  65. void rtc_isr(void)
  66. {
  67.   if((RTC_SR & RTC_SR_TIF_MASK)== 0x01)
  68.   {
  69.    
  70.     RTC_ISR[0]();
  71.     //clear flag
  72.     RTC_SR |= RTC_SR_TIF_MASK;
  73.    
  74.   }        
  75.   else if((RTC_SR & RTC_SR_TOF_MASK) == 0x02)
  76.   {
  77.    
  78.     RTC_ISR[0]();  

  79.     RTC_SR |= RTC_SR_TOF_MASK;
  80.   }                 
  81.   else if((RTC_SR & RTC_SR_TAF_MASK) == 0x04)
  82.   {

  83.     RTC_ISR[0]();  

  84.     RTC_SR |= RTC_SR_TAF_MASK;
  85.     printf("\nInterrupt happen .\n");  
  86.   }        
  87. }
复制代码


rtc.h
  1. /*
  2. * File:                rtc.h
  3. * Purpose:     Provide common rtc functions
  4. *
  5. * Notes:
  6. */
  7. #include "common.h"
  8. #ifndef __RTC_H__
  9. #define __RTC_H__


  10. void rtc_reset( void );


  11. #define RTC_INT_DIS           0
  12. #define RTC_INT_INVALID       1
  13. #define RTC_INT_OVERFLOW      2
  14. #define RTC_INT_ALARM         4


  15. typedef void (*RTC_ISR_CALLBACK)(void);


  16. uint8 RTC_Init(uint32,uint32,uint8,uint8,uint8,RTC_ISR_CALLBACK);

  17. #endif /* __RTC_H__ */
复制代码


回复 支持 反对

使用道具 举报

该用户从未签到

10

主题

42

帖子

0

注册会员

Rank: 2

积分
147
最后登录
2021-10-25
 楼主| 发表于 2015-9-6 10:59:21 | 显示全部楼层
请问版主使用KL05测试的吗?我对比了代码没有区别,要不我把我的工程发个你,你帮我测试下行吗?
回复 支持 反对

使用道具 举报

该用户从未签到

10

主题

42

帖子

0

注册会员

Rank: 2

积分
147
最后登录
2021-10-25
 楼主| 发表于 2015-9-14 11:47:14 | 显示全部楼层
好了,谢谢版主,是因为我的硬件电路晶振部分和软件晶振设置没有配合好。
回复 支持 反对

使用道具 举报

  • TA的每日心情
    开心
    2017-2-9 14:16
  • 签到天数: 17 天

    连续签到: 1 天

    [LV.4]偶尔看看III

    25

    主题

    1785

    帖子

    0

    金牌会员

    Rank: 6Rank: 6

    积分
    2250
    最后登录
    2024-6-11
    发表于 2015-9-14 13:58:05 | 显示全部楼层
    遇到问题晶振各种问题啊
    freescaleic.org.png
    回复 支持 反对

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /3 下一条

    Archiver|手机版|小黑屋|恩智浦技术社区

    GMT+8, 2025-7-28 17:43 , Processed in 0.092291 second(s), 24 queries , MemCache On.

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.

    快速回复 返回顶部 返回列表