Project

General

Profile

Work with UART (ASM) » History » Version 4

krufter_multiclet, 06/11/2013 05:15 PM

1 1 krufter_multiclet
h1. Work with UART (ASM)
2 1 krufter_multiclet
3 1 krufter_multiclet
Observe transmit and receive messages via UART more details(on Assembler).
4 1 krufter_multiclet
In code examples constant list is used, which need required with directive " .include "
5 1 krufter_multiclet
6 1 krufter_multiclet
<pre>
7 1 krufter_multiclet
.include "HDL50001_pcf.inc"
8 1 krufter_multiclet
</pre>
9 1 krufter_multiclet
10 1 krufter_multiclet
11 2 krufter_multiclet
h2. а) Transmit via UART
12 1 krufter_multiclet
13 2 krufter_multiclet
h3. 1. Allow alternative port functions. 
14 1 krufter_multiclet
15 2 krufter_multiclet
Now, produce two development kits, in which using UART0(HW1-MCp04) and UART3(LDM-MCp04).
16 2 krufter_multiclet
Observe assembler commands for allowance alternative port functions.
17 2 krufter_multiclet
For UART0:
18 1 krufter_multiclet
<pre>
19 1 krufter_multiclet
getl 0x00000F00
20 1 krufter_multiclet
wrl @1, GPIOB_BPS
21 1 krufter_multiclet
</pre>
22 1 krufter_multiclet
23 2 krufter_multiclet
For UART3:
24 1 krufter_multiclet
<pre>
25 1 krufter_multiclet
getl 0x00000F00
26 1 krufter_multiclet
wrl @1, GPIOD_BPS
27 1 krufter_multiclet
</pre>
28 1 krufter_multiclet
29 3 krufter_multiclet
h3. 2. Configurate UART on transmission, set baudrate.
30 1 krufter_multiclet
31 3 krufter_multiclet
For setting UART on transmission write value in control register:
32 3 krufter_multiclet
For UART0:
33 1 krufter_multiclet
<pre>
34 1 krufter_multiclet
getl 0x00000002
35 1 krufter_multiclet
wrl @1, UART0_CR
36 1 krufter_multiclet
</pre>
37 1 krufter_multiclet
38 3 krufter_multiclet
For UART3:
39 1 krufter_multiclet
<pre>
40 1 krufter_multiclet
getl 0x00000002
41 1 krufter_multiclet
wrl @1, UART3_CR
42 1 krufter_multiclet
</pre>
43 1 krufter_multiclet
44 4 krufter_multiclet
For setting baudrate use division factor BRDIV = Fsys/(8*Fuart - 1)
45 4 krufter_multiclet
For speed 38400 kbit/s:
46 1 krufter_multiclet
47 4 krufter_multiclet
For UART0:
48 1 krufter_multiclet
<pre>
49 1 krufter_multiclet
 getl 0x00000104
50 1 krufter_multiclet
 wrl @1, UART0_BDR
51 1 krufter_multiclet
</pre>
52 1 krufter_multiclet
53 4 krufter_multiclet
For UART3:
54 1 krufter_multiclet
<pre>
55 1 krufter_multiclet
 getl 0x00000104
56 1 krufter_multiclet
 wrl @1, UART3_BDR
57 1 krufter_multiclet
</pre>
58 1 krufter_multiclet
59 1 krufter_multiclet
h3. 3. Проверка буфера передатчика на полноту.
60 1 krufter_multiclet
61 1 krufter_multiclet
Для UART0:
62 1 krufter_multiclet
<pre>
63 1 krufter_multiclet
fifo_tx_full:
64 1 krufter_multiclet
    rdl UART0_ST
65 1 krufter_multiclet
    getl 0x00000200
66 1 krufter_multiclet
    and @1, @2
67 1 krufter_multiclet
    je @1, fifo_tx_full
68 1 krufter_multiclet
    jne @2, send_byte
69 1 krufter_multiclet
complete
70 1 krufter_multiclet
</pre>
71 1 krufter_multiclet
72 1 krufter_multiclet
Для UART3:
73 1 krufter_multiclet
<pre>
74 1 krufter_multiclet
fifo_tx_full:
75 1 krufter_multiclet
    rdl UART3_ST
76 1 krufter_multiclet
    getl 0x00000200
77 1 krufter_multiclet
    and @1, @2
78 1 krufter_multiclet
    je @1, fifo_tx_full
79 1 krufter_multiclet
    jne @2, send_byte
80 1 krufter_multiclet
complete
81 1 krufter_multiclet
</pre>
82 1 krufter_multiclet
83 1 krufter_multiclet
84 1 krufter_multiclet
h3. 4. Передача байта по UART.
85 1 krufter_multiclet
86 1 krufter_multiclet
Для UART0:
87 1 krufter_multiclet
<pre>
88 1 krufter_multiclet
    getb 0xAB 
89 1 krufter_multiclet
    wrb @1, UART0_DATA
90 1 krufter_multiclet
</pre>
91 1 krufter_multiclet
92 1 krufter_multiclet
Для UART3:
93 1 krufter_multiclet
<pre>
94 1 krufter_multiclet
    getb 0xAB 
95 1 krufter_multiclet
    wrb @1, UART3_DATA
96 1 krufter_multiclet
</pre>
97 1 krufter_multiclet
98 1 krufter_multiclet
В результате можно получить простой пример по отправке байта по UART со скоростью 38400 Кбит/с:
99 1 krufter_multiclet
100 1 krufter_multiclet
Для UART0:
101 1 krufter_multiclet
<pre>
102 1 krufter_multiclet
103 1 krufter_multiclet
.include "HDL50001_pcf.inc"
104 1 krufter_multiclet
105 1 krufter_multiclet
.text
106 1 krufter_multiclet
107 1 krufter_multiclet
preset_UART0:
108 1 krufter_multiclet
    getl 0x00000F00
109 1 krufter_multiclet
    wrl @1, GPIOB_BPS
110 1 krufter_multiclet
    getl 0x00000104
111 1 krufter_multiclet
    wrl @1, UART0_BDR
112 1 krufter_multiclet
    getl 0x00000002
113 1 krufter_multiclet
    wrl @1, UART0_CR
114 1 krufter_multiclet
    jmp fifo_tx_full
115 1 krufter_multiclet
complete
116 1 krufter_multiclet
117 1 krufter_multiclet
fifo_tx_full:
118 1 krufter_multiclet
    rdl UART0_ST
119 1 krufter_multiclet
    getl 0x00000200
120 1 krufter_multiclet
    and @1, @2
121 1 krufter_multiclet
    je @1, fifo_tx_full
122 1 krufter_multiclet
    jne @2, paragraph
123 1 krufter_multiclet
complete
124 1 krufter_multiclet
125 1 krufter_multiclet
send_byte:
126 1 krufter_multiclet
    getb 0xAB 
127 1 krufter_multiclet
    wrb @1, UART0_DATA
128 1 krufter_multiclet
complete
129 1 krufter_multiclet
</pre>
130 1 krufter_multiclet
131 1 krufter_multiclet
Для UART3 всё будет аналогично. Ознакомиться с другими примерами работы с UART можно в Хранилище, интересующие вопросы по всем интерфейсам можно задать на форуме.
132 1 krufter_multiclet
133 1 krufter_multiclet
h2. б) Приём по UART
134 1 krufter_multiclet
135 1 krufter_multiclet
Для приёма байта по UART необходимо:
136 1 krufter_multiclet
137 1 krufter_multiclet
h3. 1. Разрешить алтернативные функции портов (аналогично пункту 1 в "передаче")
138 1 krufter_multiclet
139 1 krufter_multiclet
h3. 2. Настраиваем UART на приём, устанавливаем скорость работы.
140 1 krufter_multiclet
141 1 krufter_multiclet
Для настройки UART на передачу запишем следующее значение в регистр управления:
142 1 krufter_multiclet
Для UART0:
143 1 krufter_multiclet
<pre>
144 1 krufter_multiclet
getl 0x00000001
145 1 krufter_multiclet
wrl @1, UART0_CR
146 1 krufter_multiclet
</pre>
147 1 krufter_multiclet
148 1 krufter_multiclet
Для UART3:
149 1 krufter_multiclet
<pre>
150 1 krufter_multiclet
getl 0x00000001
151 1 krufter_multiclet
wrl @1, UART3_CR
152 1 krufter_multiclet
</pre>
153 1 krufter_multiclet
154 1 krufter_multiclet
Настройка скорости работы аналогично пункту 2 в "передаче".
155 1 krufter_multiclet
156 1 krufter_multiclet
h3. 3. Проверить наличие новых данных в буфере приёма
157 1 krufter_multiclet
158 1 krufter_multiclet
Для UART0:
159 1 krufter_multiclet
<pre>
160 1 krufter_multiclet
fifo_rx_newb:
161 1 krufter_multiclet
    rdl UART0_ST
162 1 krufter_multiclet
    getl 0x00000001
163 1 krufter_multiclet
    and @1, @2
164 1 krufter_multiclet
    je @1, fifo_rx_newb
165 1 krufter_multiclet
    jne @2, get_byte
166 1 krufter_multiclet
complete
167 1 krufter_multiclet
</pre>
168 1 krufter_multiclet
169 1 krufter_multiclet
Для UART3:
170 1 krufter_multiclet
<pre>
171 1 krufter_multiclet
fifo_rx_newb:
172 1 krufter_multiclet
    rdl UART3_ST
173 1 krufter_multiclet
    getl 0x00000001
174 1 krufter_multiclet
    and @1, @2
175 1 krufter_multiclet
    je @1, fifo_rx_newb
176 1 krufter_multiclet
    jne @2, get_byte
177 1 krufter_multiclet
complete
178 1 krufter_multiclet
</pre>
179 1 krufter_multiclet
180 1 krufter_multiclet
h3. 4. Принять байт
181 1 krufter_multiclet
182 1 krufter_multiclet
Для UART0:
183 1 krufter_multiclet
<pre>
184 1 krufter_multiclet
rdl UART0_DATA
185 1 krufter_multiclet
</pre>
186 1 krufter_multiclet
187 1 krufter_multiclet
Для UART3:
188 1 krufter_multiclet
<pre>
189 1 krufter_multiclet
rdl UART3_DATA
190 1 krufter_multiclet
</pre>