SlideShare a Scribd company logo


      

                     ‫ﺍﻟﺘﺠﺎﺭﺏ ﺍﻟﻌﻤﻠﻴﺔ‬

                  

                          




                          




                   Programming
      Embedded Systems Microcontroller

You Can Practice Microcontroller Programming Easily Now!
      WALID BALID, Tuesday, December 15, 2009
Practical Class 10                                                              Programming Microcontrollers

Exp.28:Serial Communications RS485                            RS485

                                                                                       
                               RS485

                                                                           RS485
          RS485  
                                                                               
A,B 
 VA>VB “1” VA<VB
               “1”“0”




                           
 RS485
B A
                 
                                                                                                   




                                                                        RS485
                                     RS485
         ST                              TI                      MAXIM                   LTC
        ST485                         SN75176                    MAX485                 LTC485
                                                                              :RS485
Faculty of Electrical and Electronic Eng.               213               Automatic Control & Automation Dept.
                                                                             

                           RS485
                SPECIFICATIONS                RS232                RS423          RS422                 RS485

      Mode of Operation                    SINGLE-ENDED         SINGLE-ENDED     Differential         Differential
      Total Number of Drivers and            1DRIVER              1DRIVER        1DRIVER              32DRIVER
      Receivers on One Line                  1RECVR               10RECVR        10RECVR              32RECVR
      Maximum Cable Length                     50 FT              4000 FT         4000 FT              4000 FT
                                                                                  10Mb/s               10Mb/s
      Maximum Data Rate                       20kb/s              100kb/s
                                                                                  100Kb/s              100Kb/s
      Maximum Driver Output Voltage            ±25V                 ±6V         -0.25V to +6V         -7V to +12V
      Driver Output Signal
                               Loaded       ±5V to ±15V            ±3.6V           ±2.0V                 ±1.5V
      Level (Loaded Min.)
      Driver Output Signal
                               Unloaded        ±25V                 ±6V             ±6V                   ±6V
      Level (Unloaded Max)
      Driver Load Impedance (Ohms)            3k to 7k             >=450            100                   54
      Max. Driver Current in
                               Power On        N/A                  N/A             N/A                 ±100uA
      High Z State
      Max. Driver Current in
                               Power Off    ±6mA @ ±2v            ±100uA          ±100uA                ±100uA
      High Z State
      Slew Rate (Max.)                        30V/µS             Adjustable         N/A                   N/A
      Receiver Input Voltage Range             ±15V                ±12V         -10V to +10V          -7V to +12V
      Receiver Input Sensitivity                ±3V               ±200mV          ±200mV               ±200mV
      Receiver Input Resistance (Ohms)        3k to 7k             4k min          4k min               >=12k

                                                                                                                  
                                                                       
              
                RS485




                                              

                
                                                       
                                                                                                                  
                              214                       
Practical Class 10                                                              Programming Microcontrollers

                                                                           RS485
  B  A  
                                                        




 

  15Meter 
                                                   Backbone with StubsDaisy Chain




               
   RS485
  
                                                                                          

      Faculty of Electrical and Electronic Eng.               215               Automatic Control & Automation Dept.
                                                                                 




 

                                                                       RS485
                                                                        
                                                 PASSIVE DUPLEX CONTROL (AUTOMATIC ) ü
                                                        ACTIVE DUPLEX CONTROL (RTS Pin ) ü
 RS485    RO, DI      Passive Duplex   ü
 DE/RE Driver
                                  
                                                                                                   
No data to send  §
              “1”
                                                                                       Idle




Master sends a request  §
     Start Bit       
Stop Bit
             Check sum 
                                                              Idle




                            216                        
Practical Class 10                                                                    Programming Microcontrollers


Slave sends a response  §
          add = 07   

                         




                                  

RS485 Driver Active Duplex ü
       RTS Control
                                                                                                    
         No data to send     §
RTS
         “1”   
                                                                                 




Master sends a request  §
     Start Bit       
Stop Bit
Check sum

                                                                                             Idle




Faculty of Electrical and Electronic Eng.                 217                  Automatic Control & Automation Dept.
                                                                                

Slave sends a response 
 add = 07



                                                                                   




                                                                 RS232
             Advantages                                   Disadvantages
       ü System-to-System       ×
              Chip-2-Chip
 1200 ü                            .Chip-2-Sensor 
                                    100kb/s     RS485<>TTL ×
       ü       
  ü                          

                   :RS485MODBUS
         MODEBUS  
Multi Master/Slave
               
                                                                                             
Master Device   MODEBUS        
                                                                               Slave Device

 Slave DeviceMaster DeviceQueryMODEBUS

      Slave             Function                     Start         Start
                                    Byte Count                                    Data               CRC
     Address              Code                     Address Hi    Address Lo

                           218                       
Practical Class 10                                                                  Programming Microcontrollers


       Slave          Function            Byte         Start               Data                     CRC
      Address           Code             Count        Address             Stream             CRC Low     CRC Hi
       1 byte          1 byte            1 byte        2 byte           0 ~ 252 byte              1~2 byte


                                                  1~252Slave Address •
                                                           Function code •
                                                                Byte Count •
                                                        Start Address •
                            255 byte maxData Stream •
                                          Cyclic Redundancy CheckCRC •
   Inter-frame-time             
                                                                                    t3.5




 




 
  Data
                                                         t1.5




             
  
                                                                                                
                                        Inter-character time-out (t1.5) = 750μs
                                          Inter-frame delay (t3.5) = 1.750ms

      Faculty of Electrical and Electronic Eng.                   219               Automatic Control & Automation Dept.
                                                                                   

70Byte9600bps

                                Slave address

                                            

                                         70        ×8         = 560

                                               × 1000 =           .

   58ms             

                                                                               .t3.5= 1.75ms

                                                 


                                                    Start Master


                                                    Set Control Pin


                                                        Waitms 10


                                                   Send Data Frame



                                                  Reset Control Pin



                                                       Waitms 100


                                                              End
                            220                         
Practical Class 10                                                                  Programming Microcontrollers

                                                      
                                                Start Slave

                                                                      NO

                                                 UART INT

                                                        Yes



                                                  Byte1 is                                    Disable UART
                                                 Slave ADD                                      Wait 90ms

                                                                                              NO
                                                        Yes


                                             Get the data at the                                 90ms
                                                                                                Passed?
                                              UART Interface
                                             (MSB First, LSB Last )                                 Yes


                                                                                              Enable UART


                     NO
                                                Check Count
                                                 Check CRC


                                                                             Programming
                                                       YES
                                                                                  OK
   Ignore Data
                                              Set Data Value


                                                       End

               MasterSlaveResponceMODEBUS
    Slave           
                
                       

                           Slave            Function          Byte           CRC
                          Address             Code           Count    CRC Low     CRC Hi
                           1 byte            1 byte          1 byte        1~2 byte

Slave
                                                                                        CRC


Faculty of Electrical and Electronic Eng.                       221           Automatic Control & Automation Dept.
                                                              

                                              RS485|

  Full-DuplexHalf-DuplexRS485
                                                           

                                                       




 

                                                        




 

    RS485
                                         




                  222                    
Practical Class 10                                                               Programming Microcontrollers

                                            UART<>RS458
                                                    Max485




 

                                                                                             
                                                                      
      Config Print0 = Porte.2 , Mode = Set                           .RS485

  “DE”“1”Config                Print0

                       “0”“DE”

  “DE”
                                                                             

      Faculty of Electrical and Electronic Eng.                223              Automatic Control & Automation Dept.
                                                                        

                                Microcontroller is Master, PC is Slave
$regfile = "m128def.dat"
$crystal = 8000000                                                                  
$baud = 9600
'------------------
Config Print0 = Porte.2 , Mode = Set                                          
Config Pine.2 = Output
                                                                                DE
Config Pine.4 = Input                                                                                   
Key1 Alias Pine.4
Porte.4 = 1
'------------------                                                              
Dim Msg As String * 100
'------------------
Do
   Debounce Key1 , 0 , Sendall , Sub
Loop
End
'------------------
Sendall:
   Print "This is RS485 Test Program"
   Print "RS458 Protocol Done Based-on MAX485"
   Print "University of Aleppo - Syria"
   Print "Faculty of Alectrical & Electronic Engineering"                                
   Print "Control Department"
   Print "Fourth Year Students"
   Print "Computer Aided Design Session"
   Print "Unfutunality This Was The Last Session Lab"
   Print "2nd Semester"
   Print "See You Next Semester Guys ;)"
   Print "Kindest Regards"
   Print "Walid BALID"
   Print ":) :) :) :) :) :) :) :) :) :) :) :)"
   Wait 1
Return

                                                                                                       

                                                                                                       

                                                                                                       

                                                                                                       

                                                                                                       

                                                                                                       

                                                                                                       

                   224                       
Practical Class 10                                                                        Programming Microcontrollers

                                             Microcontroller is Slave, PC is Master
$regfile = "m128def.dat"
$crystal = 8000000                                                                      
$baud = 9600
'-------------------------                                             DE
Config Porte.2 = Output
Config Print = Porte.2 , Mode = Reset                                                        
Open "comd.3:9600,8,n,1" For Output As #1                                  UART
Open "comd.2:9600,8,n,1" For Input As #2                                                     
Config Serialin = Buffered , Size = 250                                  
Enable Interrupts
'-------------------------                                                           
Dim Msg As String * 250
'------------------------
Do                                                                            
   If Ischarwaiting() = 1 Then
      Input Msg
                                                                          UART
      Print #1 , Msg                                                    
   End If
Loop                                                                                UART
End

                                                                                                                      
                                                                                                                      
                                                                                                                      
                                                                                                                      
                                                                                                                      
                                                                                                                      
                                                                                                                      
                                                                                                                      
                                                                                                                      
                                                                                                                      
                                                                                                                      
                                                                                                                      
                                                                                                                      
                                                                                                                      
                                                                                                                      
                                                                                                                      
                                                                                                                      
                                                                                                                      
                                                                                                                      
Faculty of Electrical and Electronic Eng.                     225                 Automatic Control & Automation Dept.
                                                                           

                                      RS232<>RS458
                                                 RS232<>RS458




                               RS232<>RS458




                

                                                                                                          

                                                                                                          

                                                                                                          

                        226                     
Practical Class 10                                                        Programming Microcontrollers

               RS232<>UART<>RS458
        RS232<>UART<>RS458      
   Max232 UART Max485
                               UART




 
                       RS232<>UART<>RS458




      Faculty of Electrical and Electronic Eng.          227              Automatic Control & Automation Dept.
                                                                                     

Exp.29:Serial Communications USB                                    USB

                                                                                              
                                 USB

                                                                                                 
                                        USB   
 USB

                                                                         USB
                                                                  480Mb/s ü
                 . Plug & Play  ü
                                   ü
                                              127 ü

                                                                                       :USB

  USB 1.0 & USB 1.1 & USB 2.0& USB 3.0USB

                                 USB 1.01.5 Mbits/s Low Speed §
                                        USB 1.112 Mbits/s Full Speed §
                                     .USB 2.0480 Mbits/s High Speed §
                                  .USB 3.04800 Mbits/s  §


                                                                                

                                                                                                   USB
                                            ”Host Controlled”  USB
                                                  )   
                                                     
                                            USB

                              228                         
Practical Class 10                                                               Programming Microcontrollers

”On-The-Go”
                                                           

                        USB
                                                           ü
                       ü

 HUB USB
  




                               
                                                                                                             
                                                                                          Plug& Play
 Plug & Play USB
  USB

                                                                     

                                 VID, PID 

 USB
                                              


 Faculty of Electrical and Electronic Eng.                229               Automatic Control & Automation Dept.
                                                                             

                                                              USB 
                                                                     USB
                                                           A §
                                                                  B §

                               
                                                                                      

                           D- & D++5v & GNDUSB

                                                                               VCC1
                                                                                 D-2
                                                                                D+3
            
                                                                                  GND4

  '1'       D+&D-  USB  
 D-  '0' D+ '1'
                                    

                                                       :(Non Return to Zero Invert) NRZI
NRZIUSB
                                                                                  

'0' '1''0'
                                                                 '1'



                  

 '1'
                         


                        230                       
Practical Class 10                                                                 Programming Microcontrollers




                            
                                                                                            
    USB
                                                         D- D+
                                 D- .1
                                 D+ .2
                                  .3




                                                                  
                                                                                            USB
   USB
                                                              USB

                  USB Device USB 
  USB Function Host Controller IC USB
                                          USB

           USBUSB Function

           USB Function  Endpoint  
  EndpointUSB Function
                                   InOut
      Faculty of Electrical and Electronic Eng.                 231                Automatic Control & Automation Dept.
                                                                                    

 USB  
                                EP2 In

 USB Function  
                                                                                    




   
 USB1  EP1 In


                                     [Addr : 2] [Endpoint : EP1] [In]
                                                                    USB1



PipePipe

EP0 In & EP0 Out  Pipe0  Pipe  
                                                                                     

                                                                                            
 Pipe
                                                                                      
                                                      Control Transfers §

                              232                        
Practical Class 10                                                               Programming Microcontrollers

                                                  Interrupt Transfers §
                                 Isochronous Transfers §
                                                    Bulk Transfers §

                                                                            USB
         Frame     USB  
 1ms  USB1.1, USB2.0
                                      125µs

Transaction 
                                                                                                   

                                                                         
              Token Packet
                                                                                        

         In Token
 Synchronization .1
                                                                                           
 Packet Identity PID .2
                           
 128Address .3
                          Endpoint .4
                               5Cyclic Redundancy CheckCRC .5

 Out Token
                                                                                       In Token

Control Transfer : Setup Token
                                                                                            In Token


Faculty of Electrical and Electronic Eng.               233                Automatic Control & Automation Dept.
                                                                           

1ms±500ns: Start of frame Token
                                     11Frame number




                                                             Data Packet
                                                                        Data0 .1
                                                                        Data1 .2
     16bitCRC1024bit




                           

                                                       Handshake Packet
              Acknowledge

Not acknowledge
             

Stall
                                                                                     

                                                                                                          

                                                                                                          

                                                                                                          

                                                                                                          


                     234                        
Practical Class 10                                                               Programming Microcontrollers

                                                    USB
 USB  USB 
       
                                       USBHardware .1
                                                      . .2
              
 
                                               
         USB

 USB
UARTUSB

          USB

      FT232         
                                                                   FTDIUSB<>UART

HardwareUSB

USB
                                                                   

            D2XX driver & VCP driver


                                                             
                                                                   .COM




                                   
 Faculty of Electrical and Electronic Eng.               235               Automatic Control & Automation Dept.
                                                                              

                                       D2XX driver & VCP driver

            D2XX.DLL Driver                              VCP Driver                                      
                                                             
         3MB 300 KB/s                           
                               

 Com USB :(Virtual Com Port) VCP
                                                                              ComUSB

   :D2XX.DLL
                                                                        DLL


                   

                                                                                      FT232BM
        ü
                                         VCP& D2XX.DLLFTDI ü
                                                                    USB1.1, USB2.0 ü
                                                 ü
                                                       300kb~2Mb ü
                                                     384FIFO  ü

                                                      128FIFO  ü
                                                   VID, PID ü
 ü

USBUSB
  USB            
                                                                   USB


                          236                      
Practical Class 10                                                              Programming Microcontrollers

                                                                                     




                                                  




     
  11 
                                                                                                 

                
PWREN#
                                                                                    
Faculty of Electrical and Electronic Eng.             237                 Automatic Control & Automation Dept.
                                                                              

 3ms Sleep mode  
Sleep=”1”
                                              

Wake up

                                                 

 USB
                                                     Serial Interface EngineSIE
                         USBUSB §
                                                                            CRC §
                               Start Of Packet, End Of Packet, Resume, Reset  §
                                             NRZI §
                                                              PID §

USB1.1USB Transceiver
  D+              USB2.0,
                                                                         

                                                                          FT232BM 
   6MHz48MHz
  EEPROM PID, VID  
                                                                                         
                                      


                                                                                                             
                                                                                                             
                                                                                                             
                                                                                                             

                       238                         
Practical Class 10                                                             Programming Microcontrollers

                                               RS232<>UART<>USB




 

                                                                                                                

                            RS232<>UART<>USB




 
                                                                                                                
                                                                                                                
                                                                                                                
                                                                                                                




      Faculty of Electrical and Electronic Eng.                239             Automatic Control & Automation Dept.

More Related Content

PDF
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture6
PDF
Embedded System Microcontroller Interactive Course using BASCOM-AVR -Lecture7
PDF
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture9
PDF
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture...
PDF
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture12
PDF
Ar fx3 pro radio modems
PDF
Elm327 Use Manual - How to use elm327 obd 2 scanner
PPT
Nortech Door Controllers - crc220 network installation
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture6
Embedded System Microcontroller Interactive Course using BASCOM-AVR -Lecture7
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture9
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture...
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture12
Ar fx3 pro radio modems
Elm327 Use Manual - How to use elm327 obd 2 scanner
Nortech Door Controllers - crc220 network installation

What's hot (19)

PDF
PDF
PDF
Folheto BCL 21 e 22
PDF
Bdcom s2508 b hardware installation manual
PDF
PDF
9520 pulse generator datasheet
PDF
The Analysis of Dead Time on Switching Loss in High and Low Side MOSFETs of Z...
PDF
Switcher
PDF
Concept Kit:PWM Buck Converter Transients Model
PDF
ZIP
Technical s7889
PDF
20110224 saf cfip_brochure_en
PDF
DRV401AIDWPG4
PDF
BlueOptics Bo65jtxrx610d 10gbase-bx-cwdm xfp transceiver 10km singlemode lc d...
PDF
LM380 Audio Power Amplifier
PDF
Speed checker for highway
PDF
DS25CP102 (English)
PDF
Essential Guide Interfaces I/O 2010
PDF
01113 b
Folheto BCL 21 e 22
Bdcom s2508 b hardware installation manual
9520 pulse generator datasheet
The Analysis of Dead Time on Switching Loss in High and Low Side MOSFETs of Z...
Switcher
Concept Kit:PWM Buck Converter Transients Model
Technical s7889
20110224 saf cfip_brochure_en
DRV401AIDWPG4
BlueOptics Bo65jtxrx610d 10gbase-bx-cwdm xfp transceiver 10km singlemode lc d...
LM380 Audio Power Amplifier
Speed checker for highway
DS25CP102 (English)
Essential Guide Interfaces I/O 2010
01113 b
Ad

Viewers also liked (9)

PPT
PDF
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture3
PDF
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture4
PDF
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture11
PDF
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture8
PPT
PDF
Embedded System Microcontroller Interactive Course using BASCOM-AVR -Lecture5
PPTX
Edge Seminar
PDF
3G Radio Network Planning
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture3
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture4
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture11
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture8
Embedded System Microcontroller Interactive Course using BASCOM-AVR -Lecture5
Edge Seminar
3G Radio Network Planning
Ad

Similar to Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture10 (20)

PDF
Rs232 to rs485 converter
PDF
RS232 to RS485 converter | GIC India
PDF
PDF
S7 200 cable
PPTX
Galvanic isolation & Triad Semiconductor Mixed-Signal ASIC Solutions
PDF
AD5663.pdf
PDF
Ds ltc100
PDF
22 series relays
PDF
IMG-2102T Industrial Modbus Gateway
PPT
menjelaskan tentang hubungan kabel Rs232-485
PDF
Sfp(ft 9001 g-m-lc02)-datasheet_ver_1.1
PPT
Rs232 485 fundamental
PDF
1310nm optical transmitter_-_ocdbs-t
PDF
Advanced motion controls dprahis 030a400
PDF
ComNet FDX60M1A Data Sheet
PDF
Advanced motion controls dzralte 040l080
PDF
RS235,422,485.pdf
PDF
PDF
Advanced motion controls dprahie 030a400
PDF
RUGGEDCOM RMC20 media converter
Rs232 to rs485 converter
RS232 to RS485 converter | GIC India
S7 200 cable
Galvanic isolation & Triad Semiconductor Mixed-Signal ASIC Solutions
AD5663.pdf
Ds ltc100
22 series relays
IMG-2102T Industrial Modbus Gateway
menjelaskan tentang hubungan kabel Rs232-485
Sfp(ft 9001 g-m-lc02)-datasheet_ver_1.1
Rs232 485 fundamental
1310nm optical transmitter_-_ocdbs-t
Advanced motion controls dprahis 030a400
ComNet FDX60M1A Data Sheet
Advanced motion controls dzralte 040l080
RS235,422,485.pdf
Advanced motion controls dprahie 030a400
RUGGEDCOM RMC20 media converter

Recently uploaded (20)

PDF
Sports Quiz easy sports quiz sports quiz
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
PPH.pptx obstetrics and gynecology in nursing
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Classroom Observation Tools for Teachers
PDF
Computing-Curriculum for Schools in Ghana
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
01-Introduction-to-Information-Management.pdf
PDF
Insiders guide to clinical Medicine.pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
Cell Types and Its function , kingdom of life
PPTX
Lesson notes of climatology university.
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Pre independence Education in Inndia.pdf
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Sports Quiz easy sports quiz sports quiz
Final Presentation General Medicine 03-08-2024.pptx
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPH.pptx obstetrics and gynecology in nursing
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Classroom Observation Tools for Teachers
Computing-Curriculum for Schools in Ghana
Anesthesia in Laparoscopic Surgery in India
Microbial disease of the cardiovascular and lymphatic systems
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
01-Introduction-to-Information-Management.pdf
Insiders guide to clinical Medicine.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Cell Types and Its function , kingdom of life
Lesson notes of climatology university.
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Pre independence Education in Inndia.pdf
3rd Neelam Sanjeevareddy Memorial Lecture.pdf

Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture10

  • 1.    ‫ﺍﻟﺘﺠﺎﺭﺏ ﺍﻟﻌﻤﻠﻴﺔ‬     Programming Embedded Systems Microcontroller You Can Practice Microcontroller Programming Easily Now! WALID BALID, Tuesday, December 15, 2009
  • 2. Practical Class 10 Programming Microcontrollers Exp.28:Serial Communications RS485 RS485     RS485  RS485           RS485     A,B   VA>VB “1” VA<VB  “1”“0”    RS485 B A                      RS485 RS485 ST TI MAXIM LTC ST485 SN75176 MAX485 LTC485 :RS485 Faculty of Electrical and Electronic Eng. 213 Automatic Control & Automation Dept.
  • 3.       RS485 SPECIFICATIONS RS232 RS423 RS422 RS485 Mode of Operation SINGLE-ENDED SINGLE-ENDED Differential Differential Total Number of Drivers and 1DRIVER 1DRIVER 1DRIVER 32DRIVER Receivers on One Line 1RECVR 10RECVR 10RECVR 32RECVR Maximum Cable Length 50 FT 4000 FT 4000 FT 4000 FT 10Mb/s 10Mb/s Maximum Data Rate 20kb/s 100kb/s 100Kb/s 100Kb/s Maximum Driver Output Voltage ±25V ±6V -0.25V to +6V -7V to +12V Driver Output Signal Loaded ±5V to ±15V ±3.6V ±2.0V ±1.5V Level (Loaded Min.) Driver Output Signal Unloaded ±25V ±6V ±6V ±6V Level (Unloaded Max) Driver Load Impedance (Ohms) 3k to 7k >=450 100 54 Max. Driver Current in Power On N/A N/A N/A ±100uA High Z State Max. Driver Current in Power Off ±6mA @ ±2v ±100uA ±100uA ±100uA High Z State Slew Rate (Max.) 30V/µS Adjustable N/A N/A Receiver Input Voltage Range ±15V ±12V -10V to +10V -7V to +12V Receiver Input Sensitivity ±3V ±200mV ±200mV ±200mV Receiver Input Resistance (Ohms) 3k to 7k 4k min 4k min >=12k                   RS485                         214 
  • 4. Practical Class 10 Programming Microcontrollers  RS485 B  A       15Meter   Backbone with StubsDaisy Chain    RS485    Faculty of Electrical and Electronic Eng. 215 Automatic Control & Automation Dept.
  • 5.         RS485   PASSIVE DUPLEX CONTROL (AUTOMATIC ) ü ACTIVE DUPLEX CONTROL (RTS Pin ) ü RS485    RO, DI      Passive Duplex   ü  DE/RE Driver      No data to send  §              “1” Idle Master sends a request  §      Start Bit        Stop Bit              Check sum  Idle  216 
  • 6. Practical Class 10 Programming Microcontrollers Slave sends a response  §           add = 07        RS485 Driver Active Duplex ü   RTS Control            No data to send     § RTS          “1”     Master sends a request  §      Start Bit        Stop Bit Check sum  Idle Faculty of Electrical and Electronic Eng. 217 Automatic Control & Automation Dept.
  • 7.      Slave sends a response   add = 07       RS232  Advantages  Disadvantages        ü System-to-System       ×    Chip-2-Chip  1200 ü .Chip-2-Sensor   100kb/s RS485<>TTL ×   ü         ü  :RS485MODBUS          MODEBUS   Multi Master/Slave                   Master Device   MODEBUS          Slave Device  Slave DeviceMaster DeviceQueryMODEBUS Slave Function Start Start Byte Count Data CRC Address Code Address Hi Address Lo  218 
  • 8. Practical Class 10 Programming Microcontrollers Slave Function Byte Start Data CRC Address Code Count Address Stream CRC Low CRC Hi 1 byte 1 byte 1 byte 2 byte 0 ~ 252 byte 1~2 byte 1~252Slave Address • Function code • Byte Count • Start Address • 255 byte maxData Stream •  Cyclic Redundancy CheckCRC •  Inter-frame-time              t3.5     Data  t1.5      Inter-character time-out (t1.5) = 750μs Inter-frame delay (t3.5) = 1.750ms Faculty of Electrical and Electronic Eng. 219 Automatic Control & Automation Dept.
  • 9.      70Byte9600bps   Slave address   70 ×8 = 560 × 1000 = .    58ms                .t3.5= 1.75ms   Start Master Set Control Pin Waitms 10 Send Data Frame Reset Control Pin Waitms 100 End  220 
  • 10. Practical Class 10 Programming Microcontrollers   Start Slave NO UART INT Yes Byte1 is Disable UART Slave ADD Wait 90ms NO Yes Get the data at the 90ms Passed? UART Interface (MSB First, LSB Last ) Yes Enable UART NO Check Count Check CRC Programming YES OK Ignore Data Set Data Value End  MasterSlaveResponceMODEBUS     Slave                               Slave Function Byte CRC Address Code Count CRC Low CRC Hi 1 byte 1 byte 1 byte 1~2 byte Slave  CRC Faculty of Electrical and Electronic Eng. 221 Automatic Control & Automation Dept.
  • 11.       RS485| Full-DuplexHalf-DuplexRS485             RS485     222 
  • 12. Practical Class 10 Programming Microcontrollers  UART<>RS458 Max485           Config Print0 = Porte.2 , Mode = Set .RS485 “DE”“1”Config Print0  “0”“DE” “DE”   Faculty of Electrical and Electronic Eng. 223 Automatic Control & Automation Dept.
  • 13.       Microcontroller is Master, PC is Slave $regfile = "m128def.dat" $crystal = 8000000   $baud = 9600 '------------------ Config Print0 = Porte.2 , Mode = Set  Config Pine.2 = Output  DE Config Pine.4 = Input   Key1 Alias Pine.4 Porte.4 = 1 '------------------   Dim Msg As String * 100 '------------------ Do Debounce Key1 , 0 , Sendall , Sub Loop End '------------------ Sendall: Print "This is RS485 Test Program" Print "RS458 Protocol Done Based-on MAX485" Print "University of Aleppo - Syria" Print "Faculty of Alectrical & Electronic Engineering"   Print "Control Department" Print "Fourth Year Students" Print "Computer Aided Design Session" Print "Unfutunality This Was The Last Session Lab" Print "2nd Semester" Print "See You Next Semester Guys ;)" Print "Kindest Regards" Print "Walid BALID" Print ":) :) :) :) :) :) :) :) :) :) :) :)" Wait 1 Return                224 
  • 14. Practical Class 10 Programming Microcontrollers  Microcontroller is Slave, PC is Master $regfile = "m128def.dat" $crystal = 8000000   $baud = 9600 '-------------------------  DE Config Porte.2 = Output Config Print = Porte.2 , Mode = Reset   Open "comd.3:9600,8,n,1" For Output As #1  UART Open "comd.2:9600,8,n,1" For Input As #2   Config Serialin = Buffered , Size = 250   Enable Interrupts '-------------------------   Dim Msg As String * 250 '------------------------ Do   If Ischarwaiting() = 1 Then Input Msg UART Print #1 , Msg  End If Loop  UART End                                       Faculty of Electrical and Electronic Eng. 225 Automatic Control & Automation Dept.
  • 15.       RS232<>RS458 RS232<>RS458 RS232<>RS458          226 
  • 16. Practical Class 10 Programming Microcontrollers  RS232<>UART<>RS458       RS232<>UART<>RS458        Max232 UART Max485 UART    RS232<>UART<>RS458 Faculty of Electrical and Electronic Eng. 227 Automatic Control & Automation Dept.
  • 17.      Exp.29:Serial Communications USB USB     USB            USB     USB  USB  480Mb/s ü  . Plug & Play  ü   ü  127 ü   :USB  USB 1.0 & USB 1.1 & USB 2.0& USB 3.0USB  USB 1.01.5 Mbits/s Low Speed § USB 1.112 Mbits/s Full Speed § .USB 2.0480 Mbits/s High Speed §  .USB 3.04800 Mbits/s  §        USB  ”Host Controlled”  USB        )                USB  228 
  • 18. Practical Class 10 Programming Microcontrollers ”On-The-Go”    USB   ü  ü  HUB USB       Plug& Play  Plug & Play USB   USB      VID, PID   USB   Faculty of Electrical and Electronic Eng. 229 Automatic Control & Automation Dept.
  • 19.       USB   USB  A §  B §     D- & D++5v & GNDUSB  VCC1   D-2   D+3     GND4   '1'       D+&D-  USB    D-  '0' D+ '1'    :(Non Return to Zero Invert) NRZI NRZIUSB   '0' '1''0'  '1'    '1'    230 
  • 20. Practical Class 10 Programming Microcontrollers       USB  D- D+ D- .1 D+ .2  .3      USB  USB  USB                 USB Device USB  USB Function Host Controller IC USB  USB  USBUSB Function          USB Function  Endpoint   EndpointUSB Function  InOut Faculty of Electrical and Electronic Eng. 231 Automatic Control & Automation Dept.
  • 21.       USB    EP2 In  USB Function        USB1  EP1 In [Addr : 2] [Endpoint : EP1] [In]  USB1 PipePipe  EP0 In & EP0 Out  Pipe0  Pipe        Pipe   Control Transfers §  232 
  • 22. Practical Class 10 Programming Microcontrollers Interrupt Transfers § Isochronous Transfers § Bulk Transfers §  USB          Frame     USB    1ms  USB1.1, USB2.0  125µs Transaction                    Token Packet   In Token  Synchronization .1    Packet Identity PID .2    128Address .3  Endpoint .4  5Cyclic Redundancy CheckCRC .5  Out Token  In Token Control Transfer : Setup Token  In Token Faculty of Electrical and Electronic Eng. 233 Automatic Control & Automation Dept.
  • 23.      1ms±500ns: Start of frame Token 11Frame number  Data Packet Data0 .1 Data1 .2 16bitCRC1024bit   Handshake Packet Acknowledge Not acknowledge  Stall            234 
  • 24. Practical Class 10 Programming Microcontrollers  USB  USB  USB     USBHardware .1  . .2                    USB  USB UARTUSB   USB       FT232           FTDIUSB<>UART HardwareUSB  USB    D2XX driver & VCP driver     .COM   Faculty of Electrical and Electronic Eng. 235 Automatic Control & Automation Dept.
  • 25.       D2XX driver & VCP driver D2XX.DLL Driver VCP Driver         3MB 300 KB/s          Com USB :(Virtual Com Port) VCP  ComUSB    :D2XX.DLL  DLL    FT232BM  ü VCP& D2XX.DLLFTDI ü USB1.1, USB2.0 ü  ü 300kb~2Mb ü 384FIFO  ü 128FIFO  ü VID, PID ü  ü USBUSB   USB              USB  236 
  • 26. Practical Class 10 Programming Microcontrollers         11                     PWREN#   Faculty of Electrical and Electronic Eng. 237 Automatic Control & Automation Dept.
  • 27.       3ms Sleep mode   Sleep=”1”   Wake up     USB  Serial Interface EngineSIE USBUSB § CRC § Start Of Packet, End Of Packet, Resume, Reset  § NRZI § PID § USB1.1USB Transceiver   D+              USB2.0,    FT232BM   6MHz48MHz   EEPROM PID, VID                238 
  • 28. Practical Class 10 Programming Microcontrollers  RS232<>UART<>USB      RS232<>UART<>USB           Faculty of Electrical and Electronic Eng. 239 Automatic Control & Automation Dept.