From 59976aa5881592c335bf125ba268f4b3718664f2 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 18 Sep 2020 17:04:22 +0200 Subject: [PATCH] fix ht2 initial command timing --- armsrc/hitag2.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/armsrc/hitag2.c b/armsrc/hitag2.c index dc630e3fd..afe4704b8 100644 --- a/armsrc/hitag2.c +++ b/armsrc/hitag2.c @@ -130,6 +130,8 @@ static int hitag2_init(void) { #define HITAG_T_WAIT_2_MIN 90 /* T_wait2 should be at least 90 */ #define HITAG_T_WAIT_MAX 300 /* bit more than HITAG_T_WAIT_1 + HITAG_T_WAIT_2 */ #define HITAG_T_PROG 614 +#define HITAG_T_WAIT_POWERUP 313 /* transponder internal powerup time is 312.5 */ +#define HITAG_T_WAIT_START_AUTH_MAX 232 /* transponder waiting time to receive the START_AUTH command is 232.5, then it enters public mode */ #define HITAG_T_TAG_ONE_HALF_PERIOD 10 #define HITAG_T_TAG_TWO_HALF_PERIOD 25 @@ -1501,14 +1503,18 @@ void ReaderHitag(hitag_function htf, hitag_data *htd) { } if (turn_on) { + // Wait 50ms with field off to be sure the transponder gets reset + SpinDelay(50); FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_ADC | FPGA_LF_ADC_READER_FIELD); turn_on = false; + // Wait with field on to be in "Wait for START_AUTH" timeframe + lf_wait_periods(HITAG_T_WAIT_POWERUP + HITAG_T_WAIT_START_AUTH_MAX / 4); + command_start += HITAG_T_WAIT_POWERUP + HITAG_T_WAIT_START_AUTH_MAX / 4; + } else { + // Wait for t_wait_2 carrier periods after the last tag bit before transmitting, + lf_wait_periods(t_wait_2); + command_start += t_wait_2; } - - // Wait for t_wait_2 carrier periods after the last tag bit before transmitting, - lf_wait_periods(t_wait_2); - command_start += t_wait_2; - // Transmit the reader frame command_duration = hitag_reader_send_frame(tx, txlen); response_start = command_start + command_duration;