GS MCU04 UART Communication
GS MCU04 UART Communication
Universal Asynchronous
Receiver/Transmitter
1
Methods of Data Transfer
Main 2 Ways of Data Transfer
Parallel
Simultaneous data transfer via often 8 or more lines
(wire conductors)
Fast data transfer, but bulky and complex structure
Serial
Data is transferred consecutively via a single line
Slower data transfer, but simple in structure
2
Synchronous & Asynchronous Data Transfer Rate
Synchronous Asynchronous • Unit in bps (bits per second)
a block of data at a time a single byte at a time
• Called baud rate also
USART UART
(Universal Asynchronous (U Synchronous Asynchro- • As far as the conductor wire is concerned, the baud
Receiver Transmitter) nous RT) rate and bps are the same
Configuration
Protocol • Simplest connection
• A set of rules (by sender and receiver) on: ex) between PC and MCU
• How the data is packed • Three pins are required !!!
• How many bits constitute a character
• When the data begins and ends TxD, RxD, and GND
Start and Stop Bits
• Asynchronous serial data communication is
widely used for character-oriented
transmissions
• Each character is placed in between start and stop
bits, this is called framing
• Start bit: always one bit with always 0 (Low)
• Stop bit(s): one or two bits with 1 (High)
USB TX TX
PC To MCU
RX RX
UART
3
Case 1: Control by Message
Setting Device Configuration of MCU,
The design can be made with the Waijung
Blockset.
Main Circuit
3. Double Click
4. Setting
1. Click
5. Click
4
Simulink Library
Main Circuit
1. Double Click
1. Click
Main Circuit
3.Click
5
Simulink Library
Main Circuit
1. Click
1.Double click
SUB-Circuit 1
SUB-Circuit 1
6
Simulink Library
SUB-Circuit 1
1. Double Click
Set “1”
Set “2”
Set “3”
SUB-Circuit 1
2. Set “==”
3. Set “1”
4.Click
7
SUB-Circuit 1 SUB-Circuit 1
2. Connection
1.Double click
2.Setting
Main Circuit
3. Connection
3.Click
8
Connect the Board to your computer,
and then click build button
Power
9
Connect the STM32F407VG to PC
via UART Comm Board
1. Setting
USB TX TX
PC To MCU
UART RX RX
3. Click 2. Click
UART Comm
Board
10
1. Right Click
2. Select Properties
Check
3. Click
11
Type
s=serial(‘com3’)
Type
Port information a.BaudRate=11520
Open Port
12
Send data to STM32F4 with the following
format (LED ON %d\r\n).
For example, we send ‘1’,
then you can see PD12 LED light bright.
13
Case 2: Message Transmission
MATLAB send a message to the MCU Board and 1. Click Simulink Library
2. Click 6. Click
14
2. Click & Drag
1. Click
4. Setting
3. Double Click
5. Click
1. Click 4. Model Design
5. Double Click
6. Setting
3. Double Click
7. Click
2. Click to build model
1. Connection
Type
s=serial(‘com6’)
Type
a=BaudRate-115200
s=serial(‘com6’)
s.BaudRate=115200
s.Timeout=1
fopen(s)
fprintf(s,'%f*%f\r',[10.1 0.5])
fprintf(s,'%f+%f\r',[10.1 0.5]) fscanf(s)
fscanf(s)
fprintf(s,'%f-%f\r',[10.1 0.5])
fscanf(s) fprintf(s,'%f/%f\r',[10.1 0.5])
fscanf(s)