Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
en:examples:communication:rfid [2012/05/16 13:20] – created raivo.sellen:examples:communication:rfid [2026/02/19 11:31] (current) – external edit 127.0.0.1
Line 1: Line 1:
-====== RFID moodulid ====== +<pagebreak> 
-<note important>Translation needed</note> +====== RFID modules ======
-RFID on tehnoloogia andmevahetuseks raadiolainete kaudu lugeja ja elektroonilise identiteedi vahel, mis on paigaldatud mõne objekti külge identifitseerimise ja jälgimise eesmärgil. RFID võimaldab iga objektiga siduda unikaalse ID-numbri. Passiivsed identiteedid, millel pole patareid, on võimalik lugeda möödumisel küllalt lähedalt lugejast.+
  
-===== Mifare SL031 RFID moodul ===== +//Required knowledge:  
-Mifare RFID moodul on kõrgsageduslik RFID lugeja, mis töötab sagedusel 13,56 MHz. +[HW] [[et:hardware:homelab:controller]][HW] [[et:hardware:homelab:combo]] 
-Samal sagedusel töötvad ka mitmed Eesti koolides ja ettevõtetes kasutatavad id-kaardid ning RFID-nööbid. +[AVR] [[et:avr:usart]],  
-Moodul SL031 ühendatakse kontrolleriplaadiga järgmiselt+[LIB] [[et:software:homelab:library:usart]] //
-VCC – toide + 3.3 V (sideplaadi Xbee liidesest või kontrolleriplaadi ühendusribast), seda tuleb kindlasti jälgida, et mooduli toiteks mitte suuremat toitepinget kasutada! Siiski mooduli andmeside viigud taluvad ka + 5 V pinget. +
-IN – energia säästmiseks saab RFID-mooduli saata uinunud olekusse. Selleks saadetakse talle käsk 0x50. RFID-moodul ärkab üles langeva frondi peale IN sisendis. +
-TXD – ühendada kontrolleri RXD viiguga (nt. PE0 USART0 kasutamisel suhtlemiseks) +
-RXD – ühendada kontrolleri TXD viiguga (nt. PE1) +
-OUT – see väljund näitab, et mõni ID on detekteeritav (kaart mooduli ligidalväljund all) või mitte (kaarti pole, väljund üleval) +
-GND – maaühendus+
  
-USART0 kasutamisel RFID mooduliga suhtlemiseks ei tohi RFID mooduli TXD/RXD viigud ISP programmeerimise ajal olla sideplaadiga ühendatud, sest siis tekib konflikt ja programmeerimine ei õnnestu.+===== Theory ===
  
-USART seaded SL031 puhul on vaikimise 115200-8-N-1-NArvutiga ühendamise puhul, kui RFID-mooduliga suhtlemiseks kasutatakse USART0 liidest, siis jumperid parempoolsel piikribapaaril tuleb tõsta Xbee pealt RS232_2 peale ja arvuti COM port ühendada sideplaadi RS232_2 pistikusse.+RFID is a technology for data exchange via radio waves between a reader and an electronic identity attached to an object for identification and tracking. RFID allows each object to be associated with a unique ID number. Passive tags without a battery can be read when passing close to the reader.
  
-Andmevahetuse formaat kontrolleri ja RFID-mooduli vahel koosneb mitmest baidist, mis on kindlas järjekorras. Esimene bait on alati sama (kontrollerist saatmise puhul 0xBA). Teine bait näitab, mitu baiti veel pärast seda saadetakse ja seda on näiteks võimalik kasutada andmevahetuse jälgimiseks, et teada, millal andmed on saadetud. Viimane bait on kontrollsumma, mille järgi saab veenduda vastuvõetud andmete veatus ülekandes. Moodulile saatmiseks on erinevaid käske, mis kirjutavad/loevad andmeid mälus, panevad selle näiteks toite säästmiseks magama jne.+===== Mifare SL031 RFID module ===== 
 +{{  :examples:communication:rfid_slm025.png|}}
  
-Näiteprogramm saadab iga sekundi järel käsu RFID moodulile, et teada, kas sellel on mõni ID kaart avastataval ligiduselKui onsiis kuvab kaardi unikaalset ID-d tabloolAndmevahetuse iga bait on 16-süsteemis arv/koodmis tuleb ekraanil kuvamiseks teisendada ASCII tähemärkideks.+The Mifare RFID module is a high-frequency RFID reader operating at 13.56 MHz. 
 +At the same frequencymany ID cards and RFID tokens used in Estonian schools and companies also work. 
 +The SL031 module connects to the controller board as follows: 
 +  * VCC supply + 3.3 V (from the Xbee interface of the communication board or the controller board header). Be sure not to use higher supply voltage. The module data pins tolerate + 5 V. 
 +  * IN - to save power, the RFID module can be put to sleep by sending command 0x50. The module wakes up on a falling edge on IN. 
 +  * TXD connect to controller RXD (e.g.PE0 for USART0) 
 +  * RXD - connect to controller TXD (e.g., PE1) 
 +  * OUT - indicates whether an ID is detectable (card near the module, output low) or not (no card, output high) 
 +  * GND - ground
  
-===== Mifare SL031 näitekood =====+ 
 + 
 +When using USART0 to communicate with the RFID module, the RFID TXD/RXD pins must not be connected to the communication board during ISP programming, otherwise a conflict occurs and programming fails. 
 + 
 +Default USART settings for SL031 are 115200-8-N-1-N. When connecting to a computer, if USART0 is used to communicate with the RFID module, the jumpers on the right header pair must be moved from Xbee to RS232_2 and the computer COM port connected to the RS232_2 connector on the communication board. 
 + 
 +The data exchange format between the controller and the RFID module consists of several bytes in a fixed order. The first byte is always the same (0xBA when sent by the controller). The second byte indicates how many bytes follow and can be used to track when all data has been sent. The last byte is a checksum that allows verifying correct reception. Different commands are available to write/read memory, put the module to sleep, etc. 
 + 
 +The example program sends a command to the RFID module every second to check for a nearby ID card. If found, it displays the unique card ID on the display. Each byte in the exchange is in hex and must be converted to ASCII characters for display. 
 + 
 +===== Mifare SL031 example code =====
  
 <code c> <code c>
Line 30: Line 42:
 #include <homelab/module/lcd_gfx.h> #include <homelab/module/lcd_gfx.h>
  
-usart port = USART(1); //Mifare RFID ühenduseks+usart port = USART(1); //Mifare RFID connection
  
-// Käsk moodulile kaardi valimine+// Command to module select card
 // preamble, len, command, data, checksum // preamble, len, command, data, checksum
 char SL031CMD_SelectCard[] = {0xBA,0x02,0x01,0xB9}; char SL031CMD_SelectCard[] = {0xBA,0x02,0x01,0xB9};
Line 52: Line 64:
                      USART_BAUDRATE_ASYNC(115200));                      USART_BAUDRATE_ASYNC(115200));
  
-    // LCD ekraani algseadistamine+    // LCD initialization
     lcd_gfx_init();     lcd_gfx_init();
  
-    // Taustavalgustuse tööle lülitamine+    // Turn on backlight
     lcd_gfx_backlight(true);     lcd_gfx_backlight(true);
  
-    // Ekraanile teksti kirjutamine+    // Write text to screen
     lcd_gfx_goto_char_xy(3, 0);     lcd_gfx_goto_char_xy(3, 0);
     lcd_gfx_write_string("RFID Demo");     lcd_gfx_write_string("RFID Demo");
Line 66: Line 78:
     while (1) //infinite loop     while (1) //infinite loop
     {     {
-        // Saada käsk RFID moodulile+        // Send command to RFID module
         usart_send_string(port, SL031CMD_SelectCard);         usart_send_string(port, SL031CMD_SelectCard);
                  
-        // kuni vastuse andmebaidid kohal+        // Wait until response bytes arrive
         while (a < bnr)         while (a < bnr)
  {  {
- // loeb USART-ist andmeid ja salvestab+ // read from USART and store
  if (usart_try_read_char(port, &resp[a]))  if (usart_try_read_char(port, &resp[a]))
  {  {
-      // järgmine bait+      // next byte
                      a++;                      a++;
-                     // II bait näitab, mitu baiti veel tulemas on+                     // second byte shows how many bytes follow
                      if (a == 2) bnr = resp[1] + 2;                      if (a == 2) bnr = resp[1] + 2;
  }  }
  }  }
  
- // kui ID puudub - "no tag" vastus+ // if no ID - "no tag" response
  if (resp[3] == 0x01)  if (resp[3] == 0x01)
  {  {
- // kirjuta seda+ // write it
  lcd_gfx_goto_char_xy(4, 2);  lcd_gfx_goto_char_xy(4, 2);
-     lcd_gfx_write_string("puudub   ");+     lcd_gfx_write_string("missing   ");
  }  }
- // ID on olemas ja loetav+ // ID exists and is readable
  else  else
  {  {
- // vaata ainult ID baite+ // view only ID bytes
  for (a=4; a<(bnr-2); a++)  for (a=4; a<(bnr-2); a++)
  {  {
- // teisendab loetud andmed stringiks+ // convert read data to string
  hex_to_ascii(str, resp[a]);  hex_to_ascii(str, resp[a]);
- // kirjuta ekraanile+ // write to display
  lcd_gfx_goto_char_xy((a-2)*2, 2);  lcd_gfx_goto_char_xy((a-2)*2, 2);
      lcd_gfx_write_string(str);      lcd_gfx_write_string(str);
  }  }
  }  }
- // loendurid algusesse+ // reset counters
  a = 0;  a = 0;
  bnr = 4;  bnr = 4;
- // viide uuendamiseks+ // refresh delay
  hw_delay_ms(1000);  hw_delay_ms(1000);
     }     }
 } }
  
-// Teisendab hex kujul arvu ASCII märkideks ja salvestab stringi+// Convert a hex byte to ASCII and store in string
 void hex_to_ascii(char *mass, char byte) void hex_to_ascii(char *mass, char byte)
 { {
  unsigned int high = 0;  unsigned int high = 0;
  
- // leiab esimese numbrikoha hex arvust+ // find first hex digit
  while (byte > 0x0F)  while (byte > 0x0F)
  {  {
Line 121: Line 133:
  byte -= 0x10;  byte -= 0x10;
  }  }
- // esimene numbrikoht, hex teisendada ASCII-ks+ // first digit, hex to ASCII
  mass[0] = high + 0x30;  mass[0] = high + 0x30;
- // kui tähemärk+ // if letter
  if (mass[0] >= 0x3A) mass[0] += 0x07;  if (mass[0] >= 0x3A) mass[0] += 0x07;
- // teine numbrikoht, hex teisendada ASCII-ks+ // second digit, hex to ASCII
  mass[1] = byte + 0x30;  mass[1] = byte + 0x30;
  if (mass[1] >= 0x3A) mass[1] += 0x07;  if (mass[1] >= 0x3A) mass[1] += 0x07;
- // stringi terminaator+ // string terminator
  mass[2] = 0x00;  mass[2] = 0x00;
 } }
 </code> </code>
  
-===== Parallax RFID moodul =====+===== Parallax RFID module =====
  
-Parallaxi RFID moodul on madalsageduslik RFID lugeja, mis töötab sagedusel ~170 kHz.+The Parallax RFID module is a low-frequency RFID reader that operates at ~170 kHz.
  
 {{:examples:sensor:rfid.jpg|}} {{:examples:sensor:rfid.jpg|}}
  
  
-===== Parallax RFID näitekood =====+===== Parallax RFID example code =====
  
-Järgnev kood kasutab RFID lugejat ja LCD ekraani.+The following code uses an RFID reader and LCD display.
  
 <code c> <code c>
Line 330: Line 342:
 </code> </code>
  
-  * {{examples:digi:rfid.zip|AVR Studio projekt}}+  * {{examples:digi:rfid.zip|AVR Studio project}} 
en/examples/communication/rfid.1337163652.txt.gz · Last modified: (external edit)
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0