U2270B RFID mit Atmega32 CodeVision

Gast #2573676
Lesenswert?

Hallo Forum,

Ich fange gerade ein Projekt an wo ich in C (CodeVsion und ATMEGA32) ein 
Software schreibe die mir einem U2270B kommuniziert.

Ich habe gesehen dass die Daten die vom RFID- IC kommen, zuerst 9*1 ist 
und dann die Daten die ich benötige. Im Internet habe ich gelesen dass 
ich dafür einen Timer und einen ext.Int brauche.

Nun meine frage: Wie kann ich das Programmieren das ich mit dem Timer 
und dem Ext.Int den Start von der RFID mitbekomme bzw dann noch die 
Daten lese?

Vl könnte mir bitte das jemand kurz erklären

Danke!

lg
Gast #2574206
Lesenswert?

Ich habe jetzt mal das nachgeschrieben:
Timer0 läuft mit 125Khz

//Global
unsigned char tag[5];
static unsigned char data[8];
static volatile char flag;

// External Interrupt 1 service routine
interrupt [EXT_INT1] void ext_int1_isr(void)
{
static unsigned int sync;
static unsigned int bitcount;
static unsigned int insync = 0;
static unsigned int old_cnt;

if (TCNT0 - old_cnt > MANCHESTER_MIDDLE)
  {
    old_cnt = TCNT0;

    sync <<= 1;
    bitcount++;



    if (!rfid_out)
      sync |= 1;

    if ((sync & 0x3FF) == 0x1FF)
    {
      data[0] = 0xFF;
      bitcount = 1;
      insync = 1;
    }

    if (insync)
    {
      if ((bitcount % 8) == 0)
      {
        data[bitcount / 8] = sync & 0xFF;
            if (bitcount == 56)
        {
          flag = 1;
          insync = 0;
          GIMSK &= ~(1<<INT1);
        }
      }
    }
  }

}

///////////////////////////////////////////////////////////////

unsigned char em4095_read_tag(unsigned char *d)
{
  unsigned char timeout = 50;
    unsigned char temp[8];
    unsigned char i;

  do
  {
    if (TIFR)
    {
      timeout--;
      TIFR |= 1<<TOV0; //Clear Overflow Flag
    }

  } while ((!flag) && (timeout > 0));


  if (!flag)
    return 0;


  flag = 0;

    for (i=0;i!=8;i++)
        {temp[i]=data[i];}

    memcpy(temp, data, 8);
    memset(data, 0, 8);

  GIMSK |= 1<<INT1;

  if (((temp[0] << 8 | temp[1]) & 0xFF80) != 0xFF80) //Check startbits
    return 0;

  if ((temp[7] & 0x01)) //Check stopbit
    return 0;

  if (!check_parity(temp[1] & 0x7C))
    return 0;

  if (!check_parity((temp[1] & 0x03) | (temp[2] & 0xE0)))
    return 0;

  if (!check_parity(temp[2] & 0x1F))
    return 0;

  if (!check_parity(temp[3] & 0xF8))
    return 0;

  if (!check_parity((temp[3] & 0x07) | (temp[4] & 0xC0)))
    return 0;

  if (!check_parity(temp[4] & 0x3E))
    return 0;

  if (!check_parity((temp[4] & 0x01) | (temp[5] & 0xF0)))
    return 0;

  if (!check_parity((temp[5] & 0x0F) | (temp[6] & 0x80)))
    return 0;

  if (!check_parity(temp[6] & 0x7C))
    return 0;

  if (!check_parity((temp[6] & 0x03) | (temp[7] & 0xE0)))
    return 0;

  if (!check_parity((temp[1] & 0x40) ^ (temp[1] & 0x02) ^ (temp[2] & 
0x10) ^ (temp[3] & 0x80) ^ (temp[3] & 0x04) ^
                    (temp[4] & 0x20) ^ (temp[4] & 0x01) ^ (temp[5] & 
0x08) ^ (temp[6] & 0x40) ^ (temp[6] & 0x02) ^
                    (temp[7] & 0x10)))
    return 0;

  if (!check_parity((temp[1] & 0x20) ^ (temp[1] & 0x01) ^ (temp[2] & 
0x08) ^ (temp[3] & 0x40) ^ (temp[3] & 0x02) ^
                    (temp[4] & 0x10) ^ (temp[5] & 0x80) ^ (temp[5] & 
0x04) ^ (temp[6] & 0x20) ^ (temp[6] & 0x01) ^
                    (temp[7] & 0x08)))
    return 0;

  if (!check_parity((temp[1] & 0x10) ^ (temp[2] & 0x80) ^ (temp[2] & 
0x04) ^ (temp[3] & 0x20) ^ (temp[3] & 0x01) ^
                    (temp[4] & 0x08) ^ (temp[5] & 0x40) ^ (temp[5] & 
0x02) ^ (temp[6] & 0x10) ^ (temp[7] & 0x80) ^
                    (temp[7] & 0x04)))
    return 0;

  if (!check_parity((temp[1] & 0x08) ^ (temp[2] & 0x40) ^ (temp[2] & 
0x02) ^ (temp[3] & 0x10) ^ (temp[4] & 0x80) ^
                    (temp[4] & 0x04) ^ (temp[5] & 0x20) ^ (temp[5] & 
0x01) ^ (temp[6] & 0x08) ^ (temp[7] & 0x40) ^
                    (temp[7] & 0x02)))
    return 0;

//11111111 11000110 00101111 10001100 01010011 00010000 00100101 
00110110
//          DDDD DD DD DDDD  DDDD DDD D DDDD D DDD DDDD  DDDD DD DD DDDD
//          0000 00 00 1111  1111 222 2 2222 3 333 3333  4444 44 44


  d[0] = (temp[1] & 0x78) << 1 | (temp[1] & 0x03) << 2 | (temp[2] & 
0xC0) >> 6;
  d[1] = (temp[2] & 0x1E) << 3 | (temp[3] & 0xF0) >> 4;
  d[2] = (temp[3] & 0x07) << 5 | (temp[4] & 0x80) >> 3 | (temp[4] & 
0x3C) >> 2;
  d[3] = (temp[4] & 0x01) << 7 | (temp[5] & 0xE0) >> 1 | (temp[5] & 
0x0F);
  d[4] = (temp[6] & 0x78) << 1 | (temp[6] & 0x03) << 2 | (temp[7] & 
0xC0) >> 6;


  return 1;

}

///////////////////////////////////////////////////////////////


static unsigned char check_parity(unsigned char param)
{
  unsigned char bitl;
  unsigned char par = 0;

  for (bitl=0; bitl<16; bitl++)
    par ^= (param >> bitl) & 0x01;

  if (par)
    return 0;
  else
    return 1;
}

///////////////////////////////////////////////////////////////

//main

  if (em4095_read_tag(tag))
            {
            isp_mosi=1;
        putchar(tag[0]);
      putchar(tag[1]);
      putchar(tag[2]);
      putchar(tag[3]);
      putchar(tag[4]);
          isp_mosi=0;
            printf("\r\n");
            delay_ms(1000);
            }


Aber egal was ich mache es kommt immer nur 0,0,0,0,0

muss ich etwas ändern wenn ich den U2270b nehme die Soft ist für 
em4095??

Bitte um HILFE!
Gast #2575461
Lesenswert?

Soweit ich gesehen habe kann man den U2270 gleich lesen wie den em4095.
Ich habe jetzt das ganze auf einem Tiny2313 aufgebut. (Board von Pollin 
RFID)

Die Software von : Beitrag "Pollin RFID Entwicklungsboard" 
(firmware.zip)

Aber es will nicht funktionieren, Hardware ist ok denn mit der Soft von 
Pollin Seite funktioniert es super

Danke!
Angehängte Dateien:

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