Work with UART (ASM) » History » Version 7
Version 6 (krufter_multiclet, 06/11/2013 05:26 PM) → Version 7/9 (krufter_multiclet, 06/11/2013 05:34 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: Для приёма байта по 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. Get byte Принять байт
For Для UART0:
<pre>
rdl UART0_DATA
</pre>
For Для UART3:
<pre>
rdl UART3_DATA
</pre>
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: Для приёма байта по 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. Get byte Принять байт
For Для UART0:
<pre>
rdl UART0_DATA
</pre>
For Для UART3:
<pre>
rdl UART3_DATA
</pre>