Project

General

Profile

Work with UART (ASM) » History » Version 8

Version 7 (krufter_multiclet, 06/11/2013 05:34 PM) → Version 8/9 (krufter_multiclet, 06/11/2013 05:35 PM)

h1. Work with UART (ASM)

Observe transmit and receive messages via UART more details(on Assembler).
In code examples constant list is used, which need required with directive " .include "

<pre>
.include "HDL50001_pcf.inc"
</pre>

h2. а) Transmit via UART

h3. 1. Allow alternative port functions.

Now, produce two development kits, in which using UART0(HW1-MCp04) and UART3(LDM-MCp04).
Observe assembler commands for allowance alternative port functions.
For UART0:
<pre>
getl 0x00000F00
wrl @1, GPIOB_BPS
</pre>

For UART3:
<pre>
getl 0x00000F00
wrl @1, GPIOD_BPS
</pre>

h3. 2. Configurate UART on transmission, set baudrate.

For setting UART on transmission write value in control register:
For UART0:
<pre>
getl 0x00000002
wrl @1, UART0_CR
</pre>

For UART3:
<pre>
getl 0x00000002
wrl @1, UART3_CR
</pre>

For setting baudrate use division factor BRDIV = Fsys/(8*Fuart - 1)
For speed 38400 kbit/s:

For UART0:
<pre>
getl 0x00000104
wrl @1, UART0_BDR
</pre>

For UART3:
<pre>
getl 0x00000104
wrl @1, UART3_BDR
</pre>

h3. 3. Check transmitter FIFO on full.

For UART0:
<pre>
fifo_tx_full:
rdl UART0_ST
getl 0x00000200
and @1, @2
je @1, fifo_tx_full
jne @2, send_byte
complete
</pre>

For UART3:
<pre>
fifo_tx_full:
rdl UART3_ST
getl 0x00000200
and @1, @2
je @1, fifo_tx_full
jne @2, send_byte
complete
</pre>

h3. 4. Transmit byte via UART.

For UART0:
<pre>
getb 0xAB
wrb @1, UART0_DATA
</pre>

For UART3:
<pre>
getb 0xAB
wrb @1, UART3_DATA
</pre>

As a result you can get simple example - transmission byte via UART with baudrate 38400 kbit/s:

For UART0:
<pre>

.include "HDL50001_pcf.inc"

.text

preset_UART0:
getl 0x00000F00
wrl @1, GPIOB_BPS
getl 0x00000104
wrl @1, UART0_BDR
getl 0x00000002
wrl @1, UART0_CR
jmp fifo_tx_full
complete

fifo_tx_full:
rdl UART0_ST
getl 0x00000200
and @1, @2
je @1, fifo_tx_full
jne @2, paragraph
complete

send_byte:
getb 0xAB
wrb @1, UART0_DATA
complete
</pre>

For UART3 example is analogie. All UART examples are available in Repository, any questions about interfaces you can discuss at Community.

h2. б) Receive via UART

For reception byte via UART:

h3. 1. Allow alternative port functions (as 1 in "transmit" section)

h3. 2. Configurate UART on reception, set baudrate.

For setting UART on reception write value in control register:
For UART0:
<pre>
getl 0x00000001
wrl @1, UART0_CR
</pre>

For UART3:
<pre>
getl 0x00000001
wrl @1, UART3_CR
</pre>

Setting baudrate as 2 in "transmit" section.

h3. 3. Check receiver FIFO for new data

For UART0:
<pre>
fifo_rx_newb:
rdl UART0_ST
getl 0x00000001
and @1, @2
je @1, fifo_rx_newb
jne @2, get_byte
complete
</pre>

For UART3:
<pre>
fifo_rx_newb:
rdl UART3_ST
getl 0x00000001
and @1, @2
je @1, fifo_rx_newb
jne @2, get_byte
complete
</pre>

h3. 4. Receive Get byte

For UART0:
<pre>
rdl UART0_DATA
</pre>

For UART3:
<pre>
rdl UART3_DATA
</pre>