ARM4
ARM4
1
Universal Asynchronous Receiver and
Transmitter (UART)
DCD (Data Carrier
Detect) 1
6
2
7
3
8
4
9
5
4
Universal Asynchronous Receiver and
Transmitter (UART)
5
Universal Asynchronous Receiver and
Transmitter (UART)
The USART clock source (usart_ker_ck) can be
selected
from several sources:
peripheral clock (APB clock PCK)
SYSCLK
High Speed Internal 16-MHz oscillator (HSI16)
Low Speed External Oscillator (LSE)
6
Universal Asynchronous Receiver and
Transmitter (UART)
nCTS and nRTS pins are used for RS-232 hardware flow
control.
Note that the NSS and nCTS signals share the same
pin:
NSS is the slave selection input applied to the device in
synchronous slave mode
7
Universal Asynchronous Receiver and
Transmitter (UART)
The clock output (CK) is dual purpose:
When the USART is used in Synchronous
Master/Slave mode, the clock provided to the slave
device is output/input on the CK pin
SYSCLK
When the USART is used in Smartcard mode, the
clock
provided to the card is output on the CK pin.
8
UART or USART
Universal Synchronous/Asynchronous
Receiver/Transmitter (USART)
USART1, USART2, USART3
Universal Asynchronous Receiver/Transmitter
(UART)
UART4, UART5
9
UART or USART
10
UART or USART
11
UART or USART
12
UART or USART
13
Universal Asynchronous Receiver and
Transmitter (UART)
Universal
UART is programmable.
Asynchronous
Sender provides no clock signal to receivers
14
Connecting to PC
FT232R converts the UART port to a standard
USB interface
15
Data Frame
16
Data Frame
17
Data Frame
18
Data Frame
19
Baud Rate
20
Baud Rate
21
Baud Rate
Historically used in telecommunication to
represent the number of pulses physically
transferred per second
In digital communication, baud rate is the
number of bits physically transferred per
second
Example:
Baud rate is 9600
each frame: a start bit, 8 data bits, a stop bit, and
no parity bit.
Transmission rate of actual data
9600/8 = 1200 bytes/second
22 9600/(1 + 8 + 1) = 960 bytes/second
Baud Rate
𝑓 𝑃𝐶𝐿𝐾
𝐵𝑎𝑢𝑑 𝑅𝑎𝑡𝑒=
8 ×(2 −𝑂𝑉𝐸𝑅 8)× 𝑈𝑆𝐴𝑅𝑇𝐷𝐼𝑉
23
Baud Rate
Suppose the processor clock is 16MHz, and
the system is oversampled by 16 (),
1
=0 .10417 × 10
−3 1 start bit, 1 stop bit, 8 data bits,
9600 LSB first, no parity, baud rate =
26
9600
Sending Data
void USART_Write(USART_TypeDef * USARTx, uint8_t * buffer, int
nBytes) {
int i;
void USART1_IRQHandler(void) {
USART_IRQHandler(USART1, USART1_Buffer_Rx, &Rx1_Counter);
}
void USART2_IRQHandler(void) {
USART_IRQHandler(USART2, USART2_Buffer_Rx, &Rx2_Counter);
}
28
UART Interrupt:
Receiving Data
29
UART Interrupt:
Receiving Data
30
UART DMA:
Receiving & Sending
31
UART DMA:
Receiving & Sending
32
Voltage Levels
Number of
Max
Standar Max devices
Voltage signal distanc
d speed supported per
e
port
RS-232 Single end ( 100 feet 115Kbit/ 1 master, 1 receiver
logic 1: +5 to +15V, s
logic 0: -5 to -15 V)
RS-422 Differential 4000 10Mbit/ 1 master, 10
(-6V to +6V) feet s receivers
RS-485 Differential 4000 10Mbit/ 32 masters, 32
(-7V to +12V) feet s receivers
Standards:
• How far can signal transfer?
• How fast can it transfer data?
• How many devices supported per port?
• How many masters allowed?
33
Bluetooth
34
Registers
35
Registers
36
Registers
37
Registers
38
Control Register 1 (CR1)
39
Control Register 1 (CR1)
Field Bit Description
M1 D28 M[1:0] = 00: 1 Start bit, 8 data bits, n stop bits
M[1:0] = 01: 1 Start bit, 9 data bits, n stop bits
M[1:0] = 10: 1 Start bit, 7 data bits, n stop bits
OVER8 D15 Oversampling mode
0 = Oversampling by 16
1 = Oversampling by 8
M0 D12 Word length
This bit, with bit 28 (M1), determines the word length
PCE D10 Parity Control Enable bit. This will insert a parity bit right after the MSB bit.
0 = no parity bit
1 = parity bit
PS D9 Parity select (used only if PCE is one.)
0 = even parity bit
1 = odd parity bit
TXEIE D7 TXE interrupt enable
0 = disabled
1 = A USART interrupt is generated whenever the TXE flag of USART_SR
is set.
TCIE D6 Transmission complete interrupt enable
0 = disabled
40 1 = A USART interrupt is generated whenever the TC flag of USART_SR is
set.
Control Register 2 (CR2)
41
Control Register 2 (CR2)
Field Bit Description
STOP D12-13 These bits are used for programming the stop bits.
00: 1 stop bit
01: 0.5 stop bit
10: 2 stop bits
11: 1.5 stop bits
CLKEN D11 This bit allows the user to enable the CK pin.
0: CK pin disabled
1: CK pin enabled
42
Interrupt and status register
(USART_ISR)
43
Interrupt and status register
(USART_ISR)
Field Bit Description
TXE D7 Transmit data register Empty
0 = Data is not transferred to the shift register yet.
1 = The Data Register is empty and ready for the next
byte.
TC D6 Transmit Complete flag (The flag is set by hardware. To
clear the flag, you can write a zero to it. If you read the
USART_SR and then write to the USART_DR register, the
flag will be automatically cleared.)
0 = Transmission is in progress (shift register is
occupied)
1 = Transmission complete (both shift register and Data
Register are empty)
RXNE D5 Receive Data Register not empty flag. This indicates a
byte has been received and is sitting in USART Data
Register and ready to be picked up.
0 = No data is available in USART Data Register.
44 1 = Data is available in USART Data Register and ready
to be picked up.
USART: Character transmission
procedure
45
USART: Single byte communication
46
USART: Single byte communication
47
USART: Character reception procedure
48
USART: Character reception procedure
49
Example
50
Example
51
Example
52
Example
53
Example
54
Example
55
Example
56