uid有时读取失败
This commit is contained in:
@ -32,9 +32,9 @@
|
|||||||
// IIC配置 //
|
// IIC配置 //
|
||||||
//*********************************************************************************//
|
//*********************************************************************************//
|
||||||
/*软件IIC设置*/ //xtell
|
/*软件IIC设置*/ //xtell
|
||||||
#define TCFG_SW_I2C0_CLK_PORT IO_PORTA_05 //软件IIC CLK脚选择 XTELL
|
#define TCFG_SW_I2C0_CLK_PORT IO_PORTB_04 //软件IIC CLK脚选择 XTELL
|
||||||
#define TCFG_SW_I2C0_DAT_PORT IO_PORTA_06 //软件IIC DAT脚选择
|
#define TCFG_SW_I2C0_DAT_PORT IO_PORTB_05 //软件IIC DAT脚选择
|
||||||
#define TCFG_SW_I2C0_DELAY_CNT 10 //IIC延时参数,影响通讯时钟频率
|
#define TCFG_SW_I2C0_DELAY_CNT 0 //IIC延时参数,影响通讯时钟频率
|
||||||
|
|
||||||
/*硬件IIC端口选择 -- 具体看手册,这里写的不准 -- lmx
|
/*硬件IIC端口选择 -- 具体看手册,这里写的不准 -- lmx
|
||||||
SCL SDA
|
SCL SDA
|
||||||
|
|||||||
@ -31,46 +31,6 @@ struct picc_v_struct PICC_V;
|
|||||||
struct picc_f_struct PICC_F;
|
struct picc_f_struct PICC_F;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief 等待FM176XX芯片内部中断标志。
|
|
||||||
* @param wait_irq_flag [in] 要等待的中断标志位 (例如 BIT_IDLE_IRQ, BIT_TIMER_IRQ)。
|
|
||||||
* @return 操作状态,SUCCESS表示成功等到目标标志,FAIL表示超时或出错。
|
|
||||||
* @details
|
|
||||||
* 该函数会轮询REG_INTREQ寄存器,直到指定的标志位被置位,
|
|
||||||
* 或者芯片自身的定时器超时。同时包含一个软件超时以防止死循环。
|
|
||||||
*/
|
|
||||||
static unsigned char Wait_IRQ(unsigned char wait_irq_flag)
|
|
||||||
{
|
|
||||||
unsigned char irq0_val, irq1_val;
|
|
||||||
unsigned int timeout = 200; // 软件超时计数,大约 200ms
|
|
||||||
|
|
||||||
// 清除所有中断标志位 (通过写1来清除)
|
|
||||||
SetReg(REG_IRQ0, 0xFF);
|
|
||||||
SetReg(REG_IRQ1, 0xFF);
|
|
||||||
|
|
||||||
do {
|
|
||||||
GetReg(REG_IRQ0, &irq0_val);
|
|
||||||
GetReg(REG_IRQ1, &irq1_val);
|
|
||||||
|
|
||||||
// 检查是否等到我们需要的标志 (Idle IRQ 在 IRQ0)
|
|
||||||
if (irq0_val & wait_irq_flag) {
|
|
||||||
return SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查是否是芯片硬件定时器超时 (Timer IRQs 在 IRQ1)
|
|
||||||
if (irq1_val & BIT_TIMER0IRQ) {
|
|
||||||
xlog("Wait_IRQ: Hardware Timer Timeout!\n");
|
|
||||||
return FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
rfid_delay_ms(1); // 短暂延时,避免CPU空转
|
|
||||||
timeout--;
|
|
||||||
} while (timeout > 0);
|
|
||||||
|
|
||||||
xlog("Wait_IRQ: Software Timeout!\n");
|
|
||||||
return FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/********************************************************************************************************
|
/********************************************************************************************************
|
||||||
* 公共接口函数
|
* 公共接口函数
|
||||||
********************************************************************************************************/
|
********************************************************************************************************/
|
||||||
@ -171,7 +131,7 @@ unsigned char SetCW(unsigned char mode)
|
|||||||
ModifyReg(REG_COMMAND, BIT_MODEMOFF, FUN_ENABLE);
|
ModifyReg(REG_COMMAND, BIT_MODEMOFF, FUN_ENABLE);
|
||||||
ModifyReg(REG_TXMODE, BIT_TPUSHON | BIT_TPULLON, FUN_DISABLE);
|
ModifyReg(REG_TXMODE, BIT_TPUSHON | BIT_TPULLON, FUN_DISABLE);
|
||||||
}
|
}
|
||||||
rfid_delay_ms(5);
|
rfid_delay_ms(10);
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -640,9 +600,7 @@ unsigned char ReaderV_Inventory(struct picc_v_struct *picc_v)
|
|||||||
{
|
{
|
||||||
unsigned char reg_data, i, result; // 新增 result 变量
|
unsigned char reg_data, i, result; // 新增 result 变量
|
||||||
SetCommand(CMD_IDLE);
|
SetCommand(CMD_IDLE);
|
||||||
|
|
||||||
// 设置15ms的硬件超时
|
|
||||||
SetTimer(15);
|
|
||||||
|
|
||||||
SetReg(REG_TXDATANUM, 0x08);
|
SetReg(REG_TXDATANUM, 0x08);
|
||||||
ModifyReg(REG_FIFOCONTROL, BIT_FIFOFLUSH, FUN_ENABLE);
|
ModifyReg(REG_FIFOCONTROL, BIT_FIFOFLUSH, FUN_ENABLE);
|
||||||
@ -654,16 +612,7 @@ unsigned char ReaderV_Inventory(struct picc_v_struct *picc_v)
|
|||||||
ModifyReg(REG_RXCRCCON, BIT_CRCEN, FUN_ENABLE);
|
ModifyReg(REG_RXCRCCON, BIT_CRCEN, FUN_ENABLE);
|
||||||
|
|
||||||
SetCommand(CMD_TRANSCEIVE);
|
SetCommand(CMD_TRANSCEIVE);
|
||||||
|
rfid_delay_ms(50);
|
||||||
// 使用新的等待函数,等待命令完成或硬件超时
|
|
||||||
result = Wait_IRQ(BIT_IDLE_IRQ);
|
|
||||||
SetTimer(0); // 关闭定时器
|
|
||||||
|
|
||||||
if (result != SUCCESS) {
|
|
||||||
xlog("Wait_IRQ failed after TRANSCEIVE.\n");
|
|
||||||
SetCommand(CMD_IDLE); // 尝试让芯片恢复IDLE状态
|
|
||||||
return FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
GetReg(REG_ERROR, ®_data);
|
GetReg(REG_ERROR, ®_data);
|
||||||
if ((reg_data & 0x0F) != 0){
|
if ((reg_data & 0x0F) != 0){
|
||||||
@ -682,7 +631,9 @@ unsigned char ReaderV_Inventory(struct picc_v_struct *picc_v)
|
|||||||
for (i = 0; i < 8; i++)
|
for (i = 0; i < 8; i++)
|
||||||
{
|
{
|
||||||
GetReg(REG_FIFODATA, &picc_v->UID[i]);
|
GetReg(REG_FIFODATA, &picc_v->UID[i]);
|
||||||
|
// xlog("%d ",picc_v->UID[i]);
|
||||||
}
|
}
|
||||||
|
// xlog("\r\n");
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -693,7 +644,7 @@ unsigned char ReaderV_Inventory(struct picc_v_struct *picc_v)
|
|||||||
*/
|
*/
|
||||||
unsigned char ReaderV_Select(struct picc_v_struct *picc_v)
|
unsigned char ReaderV_Select(struct picc_v_struct *picc_v)
|
||||||
{
|
{
|
||||||
unsigned char reg_data;
|
unsigned char reg_data, result;
|
||||||
SetCommand(CMD_IDLE);
|
SetCommand(CMD_IDLE);
|
||||||
SetReg(REG_TXDATANUM, 0x08);
|
SetReg(REG_TXDATANUM, 0x08);
|
||||||
ModifyReg(REG_FIFOCONTROL, BIT_FIFOFLUSH, FUN_ENABLE);
|
ModifyReg(REG_FIFOCONTROL, BIT_FIFOFLUSH, FUN_ENABLE);
|
||||||
|
|||||||
@ -201,7 +201,7 @@ void TYPE_V_EVENT(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 示例:写单个块
|
// 示例:写单个块
|
||||||
memcpy(PICC_V.BLOCK_DATA, "\x11\x22\x33\x44", 4);
|
memcpy(PICC_V.BLOCK_DATA, "\x00\x00\x00\x00", 4);
|
||||||
result = ReaderV_WriteSingleBlock(4, &PICC_V);
|
result = ReaderV_WriteSingleBlock(4, &PICC_V);
|
||||||
if (result != SUCCESS)
|
if (result != SUCCESS)
|
||||||
{
|
{
|
||||||
@ -272,8 +272,7 @@ void rfid_task_fuc(void)
|
|||||||
if(first_init == 0){
|
if(first_init == 0){
|
||||||
first_init = 1;
|
first_init = 1;
|
||||||
|
|
||||||
// rfid_hal_init();
|
FM176XX_HardInit();
|
||||||
// FM176XX_HardInit();
|
|
||||||
rfid_delay_ms(5); // 硬件初始化后增加一个短暂延时,确保芯片稳定
|
rfid_delay_ms(5); // 硬件初始化后增加一个短暂延时,确保芯片稳定
|
||||||
// 2. 复位 FM176XX 芯片
|
// 2. 复位 FM176XX 芯片
|
||||||
|
|
||||||
|
|||||||
@ -33,7 +33,11 @@
|
|||||||
|
|
||||||
|
|
||||||
unsigned char FM176XX_HardInit(void){
|
unsigned char FM176XX_HardInit(void){
|
||||||
|
#if TCFG_GSENOR_USER_IIC_TYPE == 1// 硬件iic
|
||||||
int ret = hw_iic_init(0);
|
int ret = hw_iic_init(0);
|
||||||
|
#else
|
||||||
|
int ret = soft_iic_init(0);
|
||||||
|
#endif
|
||||||
xlog("init iic result:%d\n", ret); //返回0成功
|
xlog("init iic result:%d\n", ret); //返回0成功
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,5 +179,6 @@ unsigned char FM176XX_SoftReset(void){
|
|||||||
|
|
||||||
|
|
||||||
void rfid_delay_ms(unsigned int ms){
|
void rfid_delay_ms(unsigned int ms){
|
||||||
|
// delay(ms);
|
||||||
os_time_dly(ms/10);
|
os_time_dly(ms/10);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -220,7 +220,7 @@ void le_user_app_event_handler(struct sys_event* event){
|
|||||||
// factory_info_t read_info;;
|
// factory_info_t read_info;;
|
||||||
// nvs_read_factory_info(&read_info);
|
// nvs_read_factory_info(&read_info);
|
||||||
extern void rfid_task_fuc(void);
|
extern void rfid_task_fuc(void);
|
||||||
create_process(&rfid_fuc_id,"rfid",NULL,rfid_task_fuc,4000);
|
create_process(&rfid_fuc_id,"rfid",NULL,rfid_task_fuc,2000);
|
||||||
break;
|
break;
|
||||||
case 0xff: //测试
|
case 0xff: //测试
|
||||||
int ret = hw_iic_init(0);
|
int ret = hw_iic_init(0);
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -5927,6 +5927,7 @@ objs/apps/earphone/remote_control/RFID/rfid_event.c.o
|
|||||||
-r=objs/apps/earphone/remote_control/RFID/rfid_event.c.o,ReaderF_Initial,l
|
-r=objs/apps/earphone/remote_control/RFID/rfid_event.c.o,ReaderF_Initial,l
|
||||||
-r=objs/apps/earphone/remote_control/RFID/rfid_event.c.o,ReaderF_Inventory,l
|
-r=objs/apps/earphone/remote_control/RFID/rfid_event.c.o,ReaderF_Inventory,l
|
||||||
-r=objs/apps/earphone/remote_control/RFID/rfid_event.c.o,rfid_task_fuc,pl
|
-r=objs/apps/earphone/remote_control/RFID/rfid_event.c.o,rfid_task_fuc,pl
|
||||||
|
-r=objs/apps/earphone/remote_control/RFID/rfid_event.c.o,FM176XX_HardInit,l
|
||||||
-r=objs/apps/earphone/remote_control/RFID/rfid_event.c.o,rfid_delay_ms,l
|
-r=objs/apps/earphone/remote_control/RFID/rfid_event.c.o,rfid_delay_ms,l
|
||||||
-r=objs/apps/earphone/remote_control/RFID/rfid_event.c.o,FM176XX_SoftReset,l
|
-r=objs/apps/earphone/remote_control/RFID/rfid_event.c.o,FM176XX_SoftReset,l
|
||||||
-r=objs/apps/earphone/remote_control/RFID/rfid_event.c.o,GetReg,l
|
-r=objs/apps/earphone/remote_control/RFID/rfid_event.c.o,GetReg,l
|
||||||
@ -5936,15 +5937,17 @@ objs/apps/earphone/remote_control/RFID/rfid_event.c.o
|
|||||||
-r=objs/apps/earphone/remote_control/RFID/rfid_event.c.o,PICC_F,l
|
-r=objs/apps/earphone/remote_control/RFID/rfid_event.c.o,PICC_F,l
|
||||||
objs/apps/earphone/remote_control/RFID/rfid_hal.c.o
|
objs/apps/earphone/remote_control/RFID/rfid_hal.c.o
|
||||||
-r=objs/apps/earphone/remote_control/RFID/rfid_hal.c.o,FM176XX_HardInit,pl
|
-r=objs/apps/earphone/remote_control/RFID/rfid_hal.c.o,FM176XX_HardInit,pl
|
||||||
-r=objs/apps/earphone/remote_control/RFID/rfid_hal.c.o,hw_iic_init,l
|
-r=objs/apps/earphone/remote_control/RFID/rfid_hal.c.o,gpio_set_pull_up,l
|
||||||
|
-r=objs/apps/earphone/remote_control/RFID/rfid_hal.c.o,gpio_set_direction,l
|
||||||
|
-r=objs/apps/earphone/remote_control/RFID/rfid_hal.c.o,gpio_set_output_value,l
|
||||||
-r=objs/apps/earphone/remote_control/RFID/rfid_hal.c.o,printf,l
|
-r=objs/apps/earphone/remote_control/RFID/rfid_hal.c.o,printf,l
|
||||||
-r=objs/apps/earphone/remote_control/RFID/rfid_hal.c.o,GetReg,pl
|
-r=objs/apps/earphone/remote_control/RFID/rfid_hal.c.o,GetReg,pl
|
||||||
-r=objs/apps/earphone/remote_control/RFID/rfid_hal.c.o,_gravity_sensor_get_ndata,l
|
|
||||||
-r=objs/apps/earphone/remote_control/RFID/rfid_hal.c.o,SetReg,pl
|
-r=objs/apps/earphone/remote_control/RFID/rfid_hal.c.o,SetReg,pl
|
||||||
-r=objs/apps/earphone/remote_control/RFID/rfid_hal.c.o,gravity_sensor_command,l
|
|
||||||
-r=objs/apps/earphone/remote_control/RFID/rfid_hal.c.o,FM176XX_SoftReset,pl
|
-r=objs/apps/earphone/remote_control/RFID/rfid_hal.c.o,FM176XX_SoftReset,pl
|
||||||
-r=objs/apps/earphone/remote_control/RFID/rfid_hal.c.o,rfid_delay_ms,pl
|
-r=objs/apps/earphone/remote_control/RFID/rfid_hal.c.o,rfid_delay_ms,pl
|
||||||
-r=objs/apps/earphone/remote_control/RFID/rfid_hal.c.o,os_time_dly,l
|
-r=objs/apps/earphone/remote_control/RFID/rfid_hal.c.o,os_time_dly,l
|
||||||
|
-r=objs/apps/earphone/remote_control/RFID/rfid_hal.c.o,gpio_set_pull_down,l
|
||||||
|
-r=objs/apps/earphone/remote_control/RFID/rfid_hal.c.o,gpio_read,l
|
||||||
cpu/br28/liba/cpu.a.llvm.19376.crc16.c
|
cpu/br28/liba/cpu.a.llvm.19376.crc16.c
|
||||||
-r=cpu/br28/liba/cpu.a.llvm.19376.crc16.c,__crc16_mutex_init,pl
|
-r=cpu/br28/liba/cpu.a.llvm.19376.crc16.c,__crc16_mutex_init,pl
|
||||||
-r=cpu/br28/liba/cpu.a.llvm.19376.crc16.c,os_mutex_create,l
|
-r=cpu/br28/liba/cpu.a.llvm.19376.crc16.c,os_mutex_create,l
|
||||||
|
|||||||
Reference in New Issue
Block a user