Interrupt Problem EM4095 RFID Reader

#1898983
Lesenswert?

Hallo!

Ich bin gerade dabei einige Tests mit einem RFID-Modul durchzuführen.
Die Schaltung und der Quellcode sind ähnlich wie beim RFID Tür Modul 
(http://www.mikrocontroller.net/articles/RFID_T%C3%BCrmodul), nur 
verwende ich einen Atmega88 und mein DEMOD_OUT liegt am INT1-Pin.

Initialisieren des INT1 Interrupts
1
void Rfid::Init(void)
2
{
3
    #if (HWVERSION == 1)
4
    SHDDDR |= 1<<SHDPINX;
5
    #endif
6
    
7
    TCCR0B = 1<<CS01 | 1<<CS00; //Timer/Counter0 prescaler 64
8
    EICRA |= 1<<ISC10; //Any logical change on INT1 generates an interrupt request
9
    EIMSK |= 1<<INT1; //External interrupt request 1 enable (demod_out from RFID chip)
10
}

Interrupt INT1:
1
ISR(INT1_vect)
2
{
3
  static uint8_t old_cnt;
4
  static uint16_t sync;
5
  static uint8_t insync;
6
  static uint8_t bitcount;    
7
  
8
  if ((uint8_t)(TCNT0 - old_cnt) > MANCHESTER_MIDDLE)
9
  {
10
    old_cnt = TCNT0;
11
    
12
    sync <<= 1;
13
    
14
    bitcount++;
15
  
16
    uart.PutC(bitcount);
17
    
18
    if (bit_is_clear(PIND, PD2))
19
      sync |= 1;
20
    
21
    if (insync)
22
    {
23
      if ((bitcount % 8) == 0)
24
        rfid.InjectByte(sync);
25
      
26
      if (bitcount == 64)
27
      {
28
        insync = 0;
29
      }
30
    }
31
    else
32
      if ((sync & 0x3FF) == 0x1FF)
33
      {
34
        insync = 1;
35
        bitcount = 9;
36
        rfid.TagStart();
37
        rfid.InjectByte(sync);
38
      }
39
  }
40
}

Mein Problem ist, dass das hinaufzählen der bitcount variable nicht 
richtig funktioniert. So werden die aktuellen Werte im Terminal 
angezeigt:

001 002 003 004 005 006 192 002 003 004 005 006 007 008 009 010 011 012 
013 014 015 001 002 003 004 005 006 007 008 009 010 011 012 013 014 192 
002

Was stimmt hier mit meiner ISR nicht?

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren