930电子网

 找回密码
 立即注册
艾克姆科技推出最新产品STC32G12K128开发板
查看: 15504|回复: 3

keil4 自建工程timer错误

[复制链接]

1

主题

3

帖子

27

积分

新手上路

Rank: 1

积分
27
发表于 2016-12-13 14:48:35 | 显示全部楼层 |阅读模式
工程是用keil4建的,GPIO和UART都没问题 。但是在用timer的时候报错

本帖子中包含更多资源

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

x
回复

使用道具 举报

1

主题

3

帖子

27

积分

新手上路

Rank: 1

积分
27
 楼主| 发表于 2016-12-13 14:51:47 | 显示全部楼层
main所有代码
  1. #include <stdint.h>
  2. #include "nrf_delay.h"
  3. #include "nrf_gpio.h"
  4. #include "app_uart.h"
  5. #include "app_error.h"
  6. #include "boards.h"
  7. #include "nrf_drv_timer.h"
  8. #include "bsp.h"
  9. #include "nrf.h"
  10. #define UART_RX_BUF_SIZE 256
  11. #define UART_TX_BUF_SIZE 256

  12. const  nrf_drv_timer_t TIMER_LED = NRF_DRV_TIMER_INSTANCE(0);
  13. const  uint8_t leds_list[LEDS_NUMBER] = LEDS_LIST;

  14. void uart_error_handle(app_uart_evt_t * p_event)
  15. {
  16.     if (p_event->evt_type == APP_UART_COMMUNICATION_ERROR)
  17.     {
  18.         APP_ERROR_HANDLER(p_event->data.error_communication);
  19.     }
  20.     else if (p_event->evt_type == APP_UART_FIFO_ERROR)
  21.     {
  22.         APP_ERROR_HANDLER(p_event->data.error_code);
  23.     }
  24. }
  25. void timer_led_event_handler(nrf_timer_event_t event_type, void* p_context)
  26. {
  27.     static uint32_t i;
  28.     uint32_t led_to_invert = (1 << leds_list[(i++) % LEDS_NUMBER]);
  29.    
  30.     switch(event_type)
  31.     {
  32.         case NRF_TIMER_EVENT_COMPARE0:
  33.             //LEDS_INVERT(led_to_invert);
  34.                     nrf_gpio_pins_toggle(LEDS_MASK);
  35.             break;
  36.         
  37.         default:
  38.             //Do nothing.
  39.             break;
  40.     }   
  41. }
  42. int main()
  43. {
  44.         uint8_t err_code;
  45.         uint8_t rx;
  46.         uint32_t time_ms = 500; //Time(in miliseconds) between consecutive compare events.
  47.     uint32_t time_ticks;
  48.         const app_uart_comm_params_t comm_params =
  49.     {
  50.           RX_PIN_NUMBER,//òy&#189;&#197;&#191;éè&#206;òa&#197;&#228;&#214;&#195;
  51.           TX_PIN_NUMBER,
  52.           RTS_PIN_NUMBER,
  53.           CTS_PIN_NUMBER,
  54.           APP_UART_FLOW_CONTROL_DISABLED,    //&#206;Tá÷&#191;&#216;&#214;&#198;
  55.           false,
  56.           UART_BAUDRATE_BAUDRATE_Baud115200  //2¨ì&#216;&#194;ê115200bps
  57.     };
  58.     APP_UART_FIFO_INIT(&comm_params,
  59.                          UART_RX_BUF_SIZE,
  60.                          UART_TX_BUF_SIZE,
  61.                          uart_error_handle,
  62.                          APP_IRQ_PRIORITY_LOW,
  63.                          err_code);
  64.     APP_ERROR_CHECK(err_code);
  65.        
  66.         err_code = nrf_drv_timer_init(&TIMER_LED, NULL, timer_led_event_handler);
  67.     APP_ERROR_CHECK(err_code);
  68.         time_ticks = nrf_drv_timer_ms_to_ticks(&TIMER_LED, time_ms);
  69.     nrf_drv_timer_extended_compare(&TIMER_LED, NRF_TIMER_CC_CHANNEL0, time_ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true);   
  70.     nrf_drv_timer_enable(&TIMER_LED);
  71.        
  72. //        nrf_gpio_cfg_output(LED_1);//&#197;&#228;&#214;&#195;òy&#189;&#197;&#206;aê&#228;3&#246;
  73. //        nrf_gpio_pin_set(LED_1);
  74.         nrf_gpio_range_cfg_output(LED_START,LED_STOP);
  75.         nrf_gpio_pins_set(LEDS_MASK);
  76.         nrf_gpio_range_cfg_input(BUTTON_START,BUTTON_STOP,NRF_GPIO_PIN_PULLUP);
  77.        

  78.         while(1)
  79.         {
  80.                        
  81.                 while(app_uart_get(&rx) != NRF_SUCCESS)
  82.                 {
  83.                         if(nrf_gpio_pin_read(BUTTON_1) == 0)//&#182;áè&#161;òy&#189;&#197;               
  84.                         {
  85.                                 nrf_gpio_pin_clear(LED_1);
  86.                                 printf("LED1_ON\n");
  87.                                 while(nrf_gpio_pin_read(BUTTON_1) == 0);
  88.                                 nrf_gpio_pin_set(LED_1);
  89.                                 printf("LED1_OFF\n");
  90.                         }
  91.                 }
  92.                 switch(rx)
  93.                 {
  94.                         case '1':nrf_gpio_pin_clear(LED_1);break;
  95.                         case '2':nrf_gpio_pin_clear(LED_2);break;
  96.                         case '3':nrf_gpio_pin_clear(LED_3);break;
  97.                         case '4':nrf_gpio_pin_clear(LED_4);break;
  98.                         default: printf("ERRO\n");break;
  99.                 }               
  100. //                if(nrf_gpio_pin_read(BUTTON_2) == 0)//&#182;áè&#161;òy&#189;&#197;               
  101. //               
  102. //                        nrf_gpio_pin_clear(LED_2);
  103. //               
  104. //                else       
  105. //                        nrf_gpio_pin_set(LED_2);
  106. //                                if(nrf_gpio_pin_read(BUTTON_3) == 0)//&#182;áè&#161;òy&#189;&#197;               
  107. //                        nrf_gpio_pin_clear(LED_3);
  108. //                else       
  109. //                        nrf_gpio_pin_set(LED_3);
  110. //                                if(nrf_gpio_pin_read(BUTTON_4) == 0)//&#182;áè&#161;òy&#189;&#197;               
  111. //                        nrf_gpio_pin_clear(LED_4);
  112. //                else       
  113. //                        nrf_gpio_pin_set(LED_4);
  114.         }
  115.        
  116. }
复制代码
回复 支持 反对

使用道具 举报

27

主题

72

帖子

384

积分

版主

Rank: 7Rank: 7Rank: 7

积分
384
发表于 2016-12-13 20:06:58 | 显示全部楼层
原因是没有定义相关的宏。
在程序的“nrf_drv_config.h”文件中已经定义好了NRF_DRV_TIMER_INSTANCE需要的宏定义,只是你的程序中没有使能。
操作方法如下:
打开“nrf_drv_config.h”文件,将TIMER0_ENABLED设置为1

本帖子中包含更多资源

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

x
回复 支持 反对

使用道具 举报

1

主题

3

帖子

27

积分

新手上路

Rank: 1

积分
27
 楼主| 发表于 2016-12-14 09:23:30 | 显示全部楼层
飞宇 发表于 2016-12-13 20:06
原因是没有定义相关的宏。
在程序的“nrf_drv_config.h”文件中已经定义好了NRF_DRV_TIMER_INSTANCE需要的 ...

谢谢 完美解决
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|官方淘宝店|930电子网 ( 皖ICP备16000695号-2 )

GMT+8, 2024-5-20 00:28 , Processed in 0.064249 second(s), 22 queries .

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