Weitere ähnliche Inhalte Ähnlich wie Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture10 (20) Kürzlich hochgeladen (20) Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture101.
ﺍﻟﺘﺠﺎﺭﺏ ﺍﻟﻌﻤﻠﻴﺔ
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 StubsDaisy 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 ×
ü
ü
:RS485MODBUS
MODEBUS
Multi Master/Slave
Master Device MODEBUS
Slave Device
Slave DeviceMaster DeviceQueryMODEBUS
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~252Slave Address •
Function code •
Byte Count •
Start Address •
255 byte maxData Stream •
Cyclic Redundancy CheckCRC •
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.
70Byte9600bps
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
MasterSlaveResponceMODEBUS
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-DuplexHalf-DuplexRS485
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.0USB
USB 1.01.5 Mbits/s Low Speed §
USB 1.112 Mbits/s Full Speed §
.USB 2.0480 Mbits/s High Speed §
.USB 3.04800 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 & GNDUSB
VCC1
D-2
D+3
GND4
'1' D+&D- USB
D- '0' D+ '1'
:(Non Return to Zero Invert) NRZI
NRZIUSB
'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
USBUSB Function
USB Function Endpoint
EndpointUSB Function
InOut
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
PipePipe
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
128Address .3
Endpoint .4
5Cyclic Redundancy CheckCRC .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
11Frame number
Data Packet
Data0 .1
Data1 .2
16bitCRC1024bit
Handshake Packet
Acknowledge
Not acknowledge
Stall
234
24. Practical Class 10 Programming Microcontrollers
USB
USB USB
USBHardware .1
. .2
USB
USB
UARTUSB
USB
FT232
FTDIUSB<>UART
HardwareUSB
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
ComUSB
:D2XX.DLL
DLL
FT232BM
ü
VCP& D2XX.DLLFTDI ü
USB1.1, USB2.0 ü
ü
300kb~2Mb ü
384FIFO ü
128FIFO ü
VID, PID ü
ü
USBUSB
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 EngineSIE
USBUSB §
CRC §
Start Of Packet, End Of Packet, Resume, Reset §
NRZI §
PID §
USB1.1USB Transceiver
D+ USB2.0,
FT232BM
6MHz48MHz
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.