Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:examples:communication:rs232 [2010/02/08 12:12] – Links to et:software:library:usart changed to et:software:homelab:library:usart mikk.leinien:examples:communication:rs232 [2020/07/20 09:00] (current) – external edit 127.0.0.1
Line 1: Line 1:
 +<pagebreak>
 ====== RS-232 ====== ====== RS-232 ======
  
-//Vajalikud teadmised: [HW] [[et:hardware:controller|Kontroller]], [AVR] [[et:avr:usart|USART]], [LIB] [[et:software:homelab:library:usart|USART teek]], [LIB] [[et:software:library:module:lcd_alphanumeric|Alfabeetilise LCD teek]]//+//Necessary knowledge: [HW] [[en:hardware:homelab:controller]], [AVR] [[en:avr:usart]], [LIB] [[en:software:homelab:library:usart]], [LIB] [[en:software:homelab:library:module:lcd_alphanumeric]]//
  
-===== Teooria =====+===== Theory =====
  
-[{{  :examples:communication:comm_rs232_cable.jpg?220|RS-232 kaabelVasakpoolne pistik on "isane", parempoolne "emane"}}]+[{{  :examples:communication:comm_rs232_cable.jpg?220|Cable RS-232. Left plug is „male” and the right one is „female” plug."}}]
  
-RS-232 on füüsilise andmesideliidese standard, mida kasutatakse binaarandmete edastamiseksStandard on kasutusel peamiselt arvutite jadaportidesmida kutsutakse kõnekeeles ka "COM" portideksTänapäeval on RS-232 suures osas asendunud USB liidesegakuid oma lihtsuse tõttu kasutatakse hobirakendustes RS-232 edukalt edasieriti veel siis, kui on olemas USB RS-232 muundurid. RS-232 standard määrab ära pistikud, elektrilised parameetrid ja signaalide tähendusekuid mitte protokolli.+RS-232 is a standard of physical data interfacewhich is used for delivering binary dataThe standard is used mainly in serial ports of computerswhich are also called “COM” ports in everyday languageNowadays is the RS-232 largely replaced by USB interfacebut due to its simplicity it is still used very successfully in hobby applicationsespecially if there are USB – RS-232 convertersThe RS-232 standard determines the plugselectrical parameters and meanings of the signals but not the protocol
  
-RS-232 liidest kasutatakse peamiselt koos __UART-nimelise__ ? riistvaralise andmesidemooduliga, millel on protokoll standardiseeritudkuid mis jällegi ei määra ära pistikuid jmsSeega RS-232 ja UART täiendavad teineteistKuna UART on enamasti üks moodul mikrokontrollerismillel on digitaalsed sisendid-väljundid, mis ei vasta RS-232 elektrilistele parameetritelesiis omavahel viiakse need kokku spetsiaalsete nivoomuunduritegaÜks tuntumaid RS-232 TTL/CMOS nivoomuundureid on näiteks MAX232.+The RS-232 interface is used mainly with UART hardware data transmission module which protocol is standardizedbut it does not determine the plugs or other thingsSo the RS-232 enhances the UART. Since the UART is usually one module of periphery of the microcontrollerwhich digital input-output does not correspond to the electrical parameters of the RS-232, they are connected together with a special leveling-converterOne best known leveling-converters between RS-232 and TLL/CMOS is MAX232.   
  
-UART on lahtitõlgituna "universaalne asünkroonne vastuvõtja/saatja" (inglise keeles //universal asynchronous receiver/transmitter//). USART on peaaegu sama __asi__? kui UART, kuid selle erinevusegaet andmeid edastatakse koos taktsignaaliga. UART-i võib nimetada ka jadaliideseksJadaliides on andmete ülekandmise mehhanismkus iga bitt edastatakse ükshaavalNäiteks sellekset edastada 1 bait, edastatakse kindla ajaintervalliga bittiEhk siis füüsiliselt toimub jadaliidese liinil, mis on 1 mikrokontrolleri viikkindla ajavahemiku järel selle viigu pingeväärtuse muutus kõrgeks või madalaksJadaliidesega on üldjuhul ühendatud 2 seadet, millest üks edastab infot (viigu väärtust muutesja teine võtab seda vastu (viigu väärtust registreerides). Edastava viigu lühend on TX, vastuvõtval RX. Info liigub ühel liinil alati ühes suunasAndmete teistpidi saatmiseks kasutatakse teist liiniAndmed võivad kahel liinil samaaegselt liikuda ehk tegu on täisdupleks-siiniga.+UART means universal asynchronous receiver/transmitter. USART is almost the samewith the difference that the data is sent with clock signalThe UART may be called also a serial interfaceThe serial interface is a data transferring mechanismwhere each bit is transmitted one by oneFor exampleto transmit 1 bait, 8 bits are transmitted with certain intervalThis means that on the serial interface linewhich is one pin of the microcontroller, the value of voltage is changed after certain time, once low and then high. Usually there are two devices connected to the serial interfaceOne is transmitting the information (by changing the value of the pinand the other is receiving it (by registering the value of the pin). Transmitting pin is TX, and receiving pin is RX. The info is moving always to one direction on one lineFor sending data to the other direction an other line is usedIf data is moved on two lines at the same time, it is called full duplex bus 
  
-[{{  :examples:communication:comm_uart_frame.png?319|UART kaaderkus on startbitt, 0-7 andmebitid, P paarsuse bitt (olemasolulja stoppbitt (või 2)}}]+[{{  :examples:communication:comm_uart_frame.png?319|the frame of UART, where is start-bit , 0-7 are data-bits, P is parity-bit (if existingand is stop-bit (or 2).}}]
  
-Andmete edastamine toimub UART liideses kaadri (inglise keeles //frame//) kaupamilles on andmebitte olenevalt seadistusest kuni 9. Enamlevinud andmehulk on siiski bitti, ehk 1 bait. Peale andmebittide edastatakse kaadriga ka lisabitte, mille abil toimub andmete saabumise ja lõppemise hetke äratundmine vastuvõtja poolel. Esimest neist nimetatakse startbitiksmis on alati 0, teist aga stoppbitiks (või bittideks), mis on alati 1. Enne stoppbitti võib tulla ka paarsuse bitt, mida kasutakse andmete korrektsuse kontrolliksPaarsuse bitt näitab, kas andmebittide hulgas on paaris või paaritu arv ühtesidSeekumba näitu see omabsõltub UART liidese häälestusestPaaruse bitti tänapäeval enam üldjuhul ei kasutata ja selle saab häälestuses ka ära keelataNii nagu saab paarsuse bitti seadistadasaab ka andmebittide ja stoppbittide arvu.+Transmitting data is done by frames of the UART interfacein which is 5-data bits (depending on the configuration). Most common is bits (1 bait)In addition to the data bits also extra bits are transmitted with the framewhich are used to recognize the moments of arrival and ending of the data on the receiver’s side. The first is called start-bit and it is always 0. The second is called stop-bit (or bits), which is always 1. Before the stop-bit also parity bit may comeIt is use to control regularity. The parity-bit shows whether in the amount of the data-bits is odd or even number of ones. Which reading it has depends on the configuration of the UART interface. The parity-bit is usually not used anymore and it can be banned in configurationLike the parity-bit can be configuredalso can the amount of data-bits and stop-bits. 
 +       
 +In addition to the frame structurethere is one more important parameter – it is //baud rate//, with which the number of transmitted symbols in one second is determined. Baud shows the number of symbols. When we are dealing with UART then 1 baud is 1 bit and that is why we talked about bits when we were talking about frameBasically it does not matter which baud rate is used for data transmitting, but there is a certain amount of commonly used baud rates, which should be usedFor example: 9600 bps19200bps, 38400 bps, 57600 bps, 115200 bps;  
 +  
 +Furthermore, it is worth to know that the RS-232 standard includes in addition to the data-signals  (RX, TX) also data flow control pins DTR, DCD, DSR, RI, RTS and CTS, which are used for controlling the communication between the devices. For example they can be used to notify whether it is ready to receive data or not.  Since the RS-232 interface’s original goal is to connect the computers to a modem, some signals are (were) useful rather for showing the state of the telephone lines 
  
-Peale kaadri struktuuri on veel üks tähtis parameeter - see on boodikiirus (//baud rate//), millega määratakse edastatavate sümbolite arv ühes sekundis. Bood näitab nimelt sümbolite arvu. UART puhul on 1 bood aga 1 bitt ja seepärast kaadri juures bittidest saigi räägitud. Põhimõtteliselt võib andmete edastamiseks kasutada ükskõik millist boodikiirust, kuid on olemas hulk üldkasutavaid boodikiirusi, mida tasub kasutada. Näiteks: 9600 bps, 19200 bps, 38400 bps, 57600 bps, 115200 bps.+===== Practice =====
  
-Lisainformatsioonina võiks teada, et RS-232 standard sisaldab peale andmesignaalide (RX, TX) veel vookontrolli viike DTR, DCD, DSR, RI, RTS ja CTS, mida kasutatakse seadmetevahelise suhtluse juhtimiseksNäiteks võib seade nende kaudu teada anda, kas ta on valmis andmeid vastu võtma või mitteKuna RS-232 liidese originaalne eesmärk oli ühendada arvuteid modemigasiis mõned signaalid on (pigem olid) kasutusel telefoniliini seisundi näitamiseks. +The Controller module board is equipped with one RS-232 type male plugThrough that can controller be connected to computer or to an other controllerFor connecting to a computer a usual not inverted cable must be usedwhich one end is male and other one is femaleFor connection to an other controller a cable must be used where RX and TX and current control signals are perpendicularly inverted and both plugs are femaleThe inverted cable is also called zero modem cable The following is an example program of using UART serial interface When the program is started, it transmits a welcome through a RS-232 interface and displays messageswhich are received. LCD and USART libraries are used  
- +
-===== Praktika ===== +
- +
-Kodulabori kontrollerimoodulil on RS-232 isa-tüüpi pesa. Selle kaudu saab kontrolleri arvutiga või teise kontrolleriga ühendada. Arvutiga ühendamiseks tuleb kasutada tavalist pööramata kaablit, mille üks pistik on ema-tüüpi, teine isa-tüüpi. Teise kontrolleriga ühendamiseks tuleb kasutada kaablit, kus RX ja TX ning vookontrolli signaalid on risti keeratud ja mõlemad pistikud on ema-tüüpiPööratud kaablit nimetatakse ka nullmodemi kaabliksJärgnevalt on toodud UART jadaliidese kasutamise näiteprogrammProgramm saadab käivitades RS-232 liidese kaudu tervituse ja kuvab sõnumeidmis saabuvadKasutatud on LCD ja USART teeke.+
  
 <code c> <code c>
 // //
-// Kodulabori kontrollerimooduli arvutiga RS-232 kaudu liidestamine+// Connecting the Controller module of the HomeLab to a computer through RS-232. 
-// Näide kasutab digitaalset sisend-väljundmoodulit koos LCD ekraaniga+// The example is using digital input-output module with LCD. 
-// Arvuti terminalis sisestatud tekst kuvatakse LCD-l.+// The text inserted in the terminal of the computer is displayed on the LCD.
 // //
 #include <homelab/usart.h> #include <homelab/usart.h>
Line 35: Line 36:
  
 // //
-// USART liidese määramine+// Determining USART interface.
 // //
 usart port = USART(0); usart port = USART(0);
  
 // //
-// Põhiprogramm+// Main program
 // //
 int main(void) int main(void)
Line 47: Line 48:
  unsigned char row = 1;  unsigned char row = 1;
  
- // USART liidese seadistamine+ // The set-up of the USART interface.
  usart_init_async(port,  usart_init_async(port,
  USART_DATABITS_8,  USART_DATABITS_8,
Line 54: Line 55:
  USART_BAUDRATE_ASYNC(9600));  USART_BAUDRATE_ASYNC(9600));
  
- // LCD ekraani seadistamine+ // The set-up of the  LCD.
  lcd_alpha_init(LCD_ALPHA_DISP_ON_BLINK);  lcd_alpha_init(LCD_ALPHA_DISP_ON_BLINK);
  
- // Ekraanil tervituse ütlemine + // Displaying welcome message on the screen. 
- lcd_alpha_puts("Ootan teadet");+ lcd_alpha_write_string("Waiting for the message");
  
- // Kursori teise rea algusesse viimine + // Putting the cursor in the beginning of the second row. 
- lcd_alpha_gotoxy(0, row);+ lcd_alpha_goto_xy(0, row);
  
- // Arvutile tere ütlemine + // Saying hello to the computer. 
- usart_send_text(port, "Terekirjuta midagi!\r\n");+ usart_send_string(port, "Hellowrite something!\r\n");
  
- // Lõputu tsükkel+ // Endless loop
  while (true)  while (true)
  {  {
- // Jadaliidesest märgi lugemine+ // Reading the sign from the serial interface.
  if (usart_try_read_char(port, &c))  if (usart_try_read_char(port, &c))
  {   {
- // Kas tegu on reavahetuse märgiga?+ // Are we dealing with the sign of changing the row?
  if (c == '\r')  if (c == '\r')
  {  {
- // Rea vahetamine+ // Changing the row.
  row = 1 - row;  row = 1 - row;
  
- // Rea tühjendamine eelmisest teatest + // Emptying the row from the previous message. 
- lcd_alpha_clr_line(row);+ lcd_alpha_clear_line(row);
  }  }
  else  else
  {  {
- // Märgi otse ekraanile väljastamine + // Issuing the sign directly to the screen. 
- lcd_alpha_putc(c);+ lcd_alpha_write_char(c);
  }  }
  }  }
Line 91: Line 92:
 </code> </code>
  
 +[{{  :examples:communication:comm_hyperterminal.png?250|The window of the HyperTerminal}}]
 +
 +With Windows XP OS comes a program called HyperTerminal. It is opened from the //Start// menu by selecting //Accessories// →// Communications// → //HyperTerminal//. Select 9600 bps, 1 start-bit and 1 stop-bit without parity- and stream-control for configuration. When the HyperTerminal is opened during the time when the microcontroller is starting, there will be a welcoming message on the display.  The letters inserted through the window are displayed in the alphanumerical LCD. By pressing //Enter// button the row is changed on the LCD.
en/examples/communication/rs232.1265631146.txt.gz · Last modified: 2020/07/20 09:00 (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