我目前正在尝试使用nrf51开发工具包开发一个应用程序&我正在尝试使用计时器驱动程序,当我沉迷于驱动程序的C&H文件时,我遇到了一些错误:
static const nrf_drv_timer_config_t m_default_config[] = {// here it told me there is error #1
#if (TIMER0_ENABLED == 1)
NRF_DRV_TIMER_DEFAULT_CONFIG(0),
#endif
#if (TIMER1_ENABLED == 1)
NRF_DRV_TIMER_DEFAULT_CONFIG(1),
#endif
#if (TIMER2_ENABLED == 1)
NRF_DRV_TIMER_DEFAULT_CONFIG(2)
#endif
};
// here it told me there is error #2
ret_code_t nrf_drv_timer_init(nrf_drv_timer_t const * const p_instance,
nrf_drv_timer_config_t const * p_config,
nrf_timer_event_handler_t timer_event_handler)
{
ASSERT((p_instance->instance_id) < TIMER_INSTANCE_NUMBER);
ASSERT(TIMER_IS_BIT_WIDTH_VALID(p_instance->instance_id, p_config->bit_width));
if (m_cb[p_instance->instance_id].state != NRF_DRV_STATE_UNINITIALIZED)
{
return NRF_ERROR_INVALID_STATE; // timer already initialized
}
if (p_config == NULL)
{
p_config = &m_default_config[p_instance->instance_id];
}
#ifdef SOFTDEVICE_PRESENT
if (p_instance->p_reg == NRF_TIMER0)
{
return NRF_ERROR_INVALID_PARAM;
}
#endif
nrf_drv_common_irq_enable(p_instance->irq, p_config->interrupt_priority);
mp_contexts[p_instance->instance_id] = p_config->p_context;
if (timer_event_handler != NULL)
{
m_timer_event_handlers[p_instance->instance_id] = timer_event_handler;
}
else
{
return NRF_ERROR_INVALID_PARAM;
}
nrf_timer_mode_set(p_instance->p_reg, p_config->mode);
nrf_timer_bit_width_set(p_instance->p_reg, p_config->bit_width);
nrf_timer_frequency_set(p_instance->p_reg, p_config->frequency);
m_cb[p_instance->instance_id].state = NRF_DRV_STATE_INITIALIZED;
return NRF_SUCCESS;
}错误#1表示“空初始值设定项对于具有未指定界限的数组无效”错误#2表示它需要一个表达式
到目前为止,我没有在main.c代码中使用这些函数中的任何一个,我只是添加了将进一步使用的头文件。
发布于 2015-06-15 07:59:45
错误1:显然,两个TIMERx_ENABLED都不是1,因此数组将为空。因为它是const,所以没有机会在以后初始化它。这也会导致包含零个元素的数组,这是不允许的。最简单的方法可能是使用具有单个空条目的#else子句。然而,我怀疑你必须首先为你的系统配置这些东西。请阅读文档。
错误2:可能是后续错误,或者没有定义自定义类型之一-在没有更多信息的情况下很难说,或者报告错误的位置根本不是实际错误的位置,或者...最好的方法是修复第一个错误,然后重试错误2。
发布于 2016-10-24 17:44:31
如果您正在使用来自北欧的示例,那么对于新版本的北欧sdk,定义要么在nrf_drv_config.h中,要么在sdk_config.h中。
您必须通过将TIMER_ENABLED定义更改为1来启用计时器。然后对要使用的计时器执行相同的操作。
你可以按照别人的建议给自己下这些定义。
https://stackoverflow.com/questions/30835714
复制相似问题