解决nrf52832 radio配置反复切换,radio不能读标签的问题

切换配置时,radio还在等待读卡的状态,官方读取程序如下:


/**@brief Function for reading packet.
 */
uint32_t read_packet(uint8_t *received, uint32_t *getRssisample)
{
    uint32_t result = 0;

    NRF_RADIO->EVENTS_READY = 0U;
    // Enable radio and wait for ready
    NRF_RADIO->TASKS_RXEN = 1U;

    while (NRF_RADIO->EVENTS_READY == 0U)
    {
        // wait
    }
    NRF_RADIO->EVENTS_END = 0U;
    // Start listening and wait for address received event
    
    
    NRF_RADIO->TASKS_START = 1U;
    

    // Wait for end of packet or buttons state changed
    while (NRF_RADIO->EVENTS_END == 0U) //会一直在这里等待接收标签数据
    {
        
        if (rfidConfiged == 1) {
            rfidConfiged = 0;
            break;
        }
        
        // wait
    }

    if (NRF_RADIO->CRCSTATUS == 1U)
    {
        //getRssisample = NRF_RADIO->RSSISAMPLE;
        
        if (rfidMode == 1) {
            memcpy(received, (((char *)packet) + 2), 10);
        } else {
            memcpy(received, packet, 10);
        }
        *getRssisample = NRF_RADIO->RSSISAMPLE;
        result = 1;
    }
    NRF_RADIO->EVENTS_DISABLED = 0U;
    
    // Disable radio
    NRF_RADIO->TASKS_DISABLE = 1U;

    while (NRF_RADIO->EVENTS_DISABLED == 0U)
    {
        // wait
    }
    return result;
}

如果radio仍处于读卡状态,这时切换配置,会卡死在while (NRF_RADIO->EVENTS_END == 0U) 这个循环里,就算有相应配置的标签也读不到。

解决方法:停止读卡,切换配置,重新读卡。代码如下:


void radio_change()
{
	NRF_RADIO->EVENTS_DISABLED = 0;           //停止读卡
	NRF_RADIO->TASKS_DISABLE = 1u;
	while(NRF_RADIO->EVENTS_DISABLED == 0u){
	}
	
	radio_configure();                         //配置radio
	NRF_RADIO->PACKETPTR = (uint32_t)packet;
	
	NRF_RADIO->EVENTS_READY = 0U;              //重新读卡
	// Enable radio and wait for ready
	NRF_RADIO->TASKS_RXEN = 1U;

	while (NRF_RADIO->EVENTS_READY == 0U)
	{
	}
	NRF_RADIO->EVENTS_END = 0U;
	// Start listening and wait for address received event
	NRF_RADIO->TASKS_START = 1U;
}

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值