Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
16 years ago

Using a uart without HAL

Hi, we're just starting out with Nios II. We have a lot of experience with embedded processors, particularly the NXP ARM7 and the Atmel AVR.

We are trying to write code to receive the serial lighting protocol DMX512 on a UART. This is basically a break followed by 512 bytes of data, at 250Kbaud. The device only has to receive a few bytes of the data relevant to itself, e.g. bytes 100-103. We have C code to do this on other embedded processors which accesses the hardware registers directly.

However on the Nios II, settings I make directly to the UART registers are overwritten, I presume by HAL routines. For example the UART interrupt enable flags are constantly overwritten to a different value from the one I want.

Can anyone advise me how to disable the HAL routines so I can access the UART directly?

Tim Mitchell

2 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Sorry to reply to my own post, I've just found out from another programmer that the HAL code does not take effect unless you use fopen() or other C stream commands. So my problem must be elsewhere.

    I am slightly confused by the section in the "Embedded Peripherals" documentation which appears to suggest that you should not access the UART registers directly "if the HAL driver is active for the device".
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi,

    The HAL functions works with UART register, so if in one side you use them to read or write, and on another side you access directly the UART register, this may result in conflict, particularly with interrupts.

    To access directly the registers of UART, you don't have to disable anything about HAL, just use the macro defined in the file altera_avalon_uart_regs.h. (cf Nios II Software Developer’s Handbook, Chapter 7, part Accessing Hardware, for the use of IORD and IOWR macros).

    So, to write or read data, you simply have to do the following :

    IOWR_ALTERA_AVALON_UART_TXDATA(UART_BASE, data);

    data = IORD_ALTERA_AVALON_UART_RXDATA(UART_BASE);

    Jérôme