[Cortex-M0技术交流] 菜鸟学习M0第十三帖——BODCR

[复制链接]
 楼主| lixiaoxu2meng 发表于 2011-9-24 11:21 | 显示全部楼层 |阅读模式
dc, IO, TI, gp, TE
本工程实现 低电压检测 (分为低电压中断 及低电压复位 )电压门限值可设,经过测试 低电压复位好用  但是低电压中断 寄存器配置应该没什么问题 但是总死在startup_NUC1xx.s里,如果用人弄通了 告诉我一声不胜感激
main函数
  1. /*---------------------------------------------------------------------------------------------------------*/
  2. /* */
  3. /* Copyright(c) 2011 Nuvoton Technology Corp. All rights reserved. */
  4. /* */
  5. /*---------------------------------------------------------------------------------------------------------*/
  6. #include "includes.h" //包含所需的头文件
  7. /*************************************************************************************
  8. ** Function name: main
  9. ** Descriptions: 欠压检测(本来打算用欠压检测中断的,但是老是死机老死在startup_NUC1xx.s中)
  10. 后来只能用欠压检测复位(其中欠压检测中断的代码 没删 有兴趣的可以研究一下
  11. 如果解决了问题 告诉我一声 在下不胜感激 )
  12. ** input parameters: 无
  13. ** output parameters: 无
  14. ** Returned value: 无
  15. *************************************************************************************/
  16. int main (void)
  17. {
  18. Set_System(); //封装一些初始化模块
  19. while(1)
  20. {}
  21. }


hw_config函数
  1. #include "includes.h" //包含所需的头文件
  2. /*************************************************************************************
  3. ** Function name: Set_System
  4. ** Descriptions: 封装一些初始化模块
  5. ** input parameters: count
  6. ** output parameters: 无
  7. ** Returned value: 无
  8. *************************************************************************************/
  9. void Set_System(void)
  10. {
  11. RCC_Configuration(); //配置系统时钟

  12. GPIO_Configuration(); //配置GPIO

  13. DrvGPIO_ClrBit(E_GPA,2); //LED1 点亮
  14. DrvGPIO_ClrBit(E_GPA,3); //LED2 点亮
  15. DrvGPIO_ClrBit(E_GPA,4); //LED3 点亮
  16. delay_ms(1000);
  17. DrvGPIO_SetBit(E_GPA,4); //LED3 熄灭
  18. delay_ms(1000);

  19. BODCR_Configuration(); //配置欠压检测控制寄存器BODCR
  20. }
  21. /*************************************************************************************
  22. ** Function name: RCC_Configuration
  23. ** Descriptions: 系统时钟源设置
  24. ** input parameters: none
  25. ** output parameters: none
  26. ** Returned value: none
  27. *************************************************************************************/
  28. void RCC_Configuration(void)
  29. {
  30. UNLOCKREG(); // 对写保护位操作时 需要一次向0x50000 0100写入 0x59,0x16,0x88,
  31. DrvSYS_SetOscCtrl(E_SYS_XTL12M, 1);// 与其 SYSCLK->PWRCON.XTL12M_EN = 1; 等同
  32. // PWRCON寄存器(这些寄存器在上电复位到用户解锁定之前是锁定的)除了 BIT[6]位其他位都受写保护
  33. // 解除这些需要向 0x50000 0100写入 0x59,0x16,0x88,
  34. // 令PWRCON寄存器的BITP[0]为1(即设定12M外部晶振)
  35. delay_ms(100); // while (DrvSYS_GetChipClockSourceStatus(E_SYS_XTL12M) != 1);//等待外部12MHZ晶振就绪
  36. LOCKREG(); // 向“0x5000_0100”写入任何值,就可以重锁保护寄存器
  37. }
  38. /*************************************************************************************
  39. ** Function name: GPIO_Configuration
  40. ** Descriptions: GPIO配置
  41. ** input parameters: none
  42. ** output parameters: none
  43. ** Returned value: none
  44. *************************************************************************************/
  45. void GPIO_Configuration()
  46. {
  47. DrvGPIO_Open( E_GPA, 2, E_IO_OUTPUT ); //led端口设置为输出
  48. DrvGPIO_Open( E_GPA, 3, E_IO_OUTPUT );
  49. DrvGPIO_Open( E_GPA, 4, E_IO_OUTPUT );
  50. DrvGPIO_Open( E_GPA, 5, E_IO_OUTPUT );
  51. }
  52. /*************************************************************************************
  53. ** Function name: BODCR_Configuration
  54. ** Descriptions: BODCR配置
  55. ** input parameters: none
  56. ** output parameters: none
  57. ** Returned value: none
  58. *************************************************************************************/
  59. void BODCR_Configuration()
  60. {
  61. UNLOCKREG(); // 对写保护位操作时 需要一次向0x50000 0100写入 0x59,0x16,0x88,
  62. DrvSYS_SelectBODVolt(3); //设置欠压检测门限值为2.2V (3: 4.5V, 2: 3.8V, 1: 2.7V, 0: 2.2V)

  63. DrvSYS_DisableBODLowPowerMode(); //SYS->BODCR.BOD_LPM = 0;BOD工作于正常模式
  64. DrvSYS_DisableLowVoltReset(); //SYS->BODCR.LVR_EN = 0; 禁止低压复位功能
  65. DrvSYS_SetBODFunction (1, 1,BODCR_CALLBACK); // SYS->BODCR.BOD_EN = 1;使能欠压检测功能
  66. //SYS->BODCR.BOD_RSTEN = 0;使能欠压中断功能 SYS->BODCR.BOD_RSTEN = 1;使能欠压复位功能
  67. //备注:我尝试使用欠压中断功能 但是老是死在startup_NUC1xx.s中 不知为什么

  68. //BODCR_CALLBACK 设置欠压中断的回调函数
  69. LOCKREG(); // 向“0x5000_0100”写入任何值,就可以重锁保护寄存器
  70. }
  71. /*************************************************************************************
  72. ** Function name: BODCR_CALLBACK
  73. ** Descriptions: 欠压中断的回调函数
  74. ** input parameters: none
  75. ** output parameters: none
  76. ** Returned value: none
  77. *************************************************************************************/
  78. void BODCR_CALLBACK()
  79. {
  80. DrvGPIO_SetBit(E_GPA,2);
  81. }
  82. /*************************************************************************************
  83. ** Function name: delay_ms
  84. ** Descriptions: 1ms(晶振为12MHZ)延时子程序
  85. ** input parameters: count
  86. ** output parameters: 无
  87. ** Returned value: 无
  88. *************************************************************************************/
  89. void delay_ms(uint32_t count)
  90. {
  91. uint32_t i,j;
  92. for(i=count;i>0;i--)
  93. for(j=2395;j>0;j--);
  94. }

hw_config头文件
  1. #ifndef __HW_CONFIG_H__
  2. #define __HW_CONFIG_H__
  3. void Set_System(void);
  4. void RCC_Configuration(void);
  5. void GPIO_Configuration(void);
  6. void BODCR_Configuration(void);
  7. void BODCR_CALLBACK(void);
  8. void delay_ms(uint32_t count);
  9. #endif

已测试 掉电复位好用
工程

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
wangkj 发表于 2012-1-10 16:00 | 显示全部楼层
请测验下,是否进入了NMI中断 (不可屏蔽中断)。
Cortex M0的芯片,可以将NMI的中断源设为某中断,
如果发生该中断,就会进入NMI的处理函数。

默认情况下,NMI的中断源是BOD, 这样发生了BOD中断,就会进入NMI、而不是BOD的处理函数。

所以,楼主需要将NMI中断源设置成其他的
SYSINT->NMISEL.NMISEL = PS2_IRQn;

http://www.nuvoton-m0.com/forum. ... =1811&fromuid=5
 楼主| lixiaoxu2meng 发表于 2012-1-10 16:57 | 显示全部楼层
2# wangkj
谢谢 我明天有时间试试 十分感谢
wangkj 发表于 2012-1-10 22:53 | 显示全部楼层
我想,其实,没必要用终端,用查询就行。
我正在设计的程序,就不准备用终端。睡眠+全查询。
kyzb001 发表于 2012-1-10 23:43 | 显示全部楼层
您需要登录后才可以回帖 登录 | 注册

本版积分规则

0

主题

1679

帖子

2

粉丝
快速回复 在线客服 返回列表 返回顶部