Project

General

Profile

Work with UART (ASM) » History » Version 7

« Previous - Version 7/9 (diff) - Next » - Current version
krufter_multiclet, 06/11/2013 05:34 PM


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 "

.include "HDL50001_pcf.inc" 

а) Transmit via UART

1. Allow alternative port functions.

Now, produce two development kits, in which using UART0 and UART3.
Observe assembler commands for allowance alternative port functions.
For UART0:

getl 0x00000F00
wrl @1, GPIOB_BPS

For UART3:

getl 0x00000F00
wrl @1, GPIOD_BPS

2. Configurate UART on transmission, set baudrate.

For setting UART on transmission write value in control register:
For UART0:

getl 0x00000002
wrl @1, UART0_CR

For UART3:

getl 0x00000002
wrl @1, UART3_CR

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

For UART0:

 getl 0x00000104
 wrl @1, UART0_BDR

For UART3:

 getl 0x00000104
 wrl @1, UART3_BDR

3. Check transmitter FIFO on full.

For UART0:

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

For UART3:

fifo_tx_full:
    rdl UART3_ST
    getl 0x00000200
    and @1, @2
    je @1, fifo_tx_full
    jne @2, send_byte
complete

4. Transmit byte via UART.

For UART0:

    getb 0xAB 
    wrb @1, UART0_DATA

For UART3:

    getb 0xAB 
    wrb @1, UART3_DATA

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

For UART0:


.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

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

б) Receive via UART

For reception byte via UART:

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

2. Configurate UART on reception, set baudrate.

For setting UART on reception write value in control register:
For UART0:

getl 0x00000001
wrl @1, UART0_CR

For UART3:

getl 0x00000001
wrl @1, UART3_CR

Setting baudrate as 2 in "transmit" section.

3. Check receiver FIFO for new data

For UART0:

fifo_rx_newb:
    rdl UART0_ST
    getl 0x00000001
    and @1, @2
    je @1, fifo_rx_newb
    jne @2, get_byte
complete

For UART3:

fifo_rx_newb:
    rdl UART3_ST
    getl 0x00000001
    and @1, @2
    je @1, fifo_rx_newb
    jne @2, get_byte
complete

4. Get byte

For UART0:

rdl UART0_DATA

For UART3:

rdl UART3_DATA