Application Report AN01280 August 2010 Using a 9 bit Software UART with Stellaris Microcontrollers ABSTRACT Extend the functionality of the standard hardware UART available on Stellaris microcontrollers by using the 9 bit UART add on This practical software solution provides a way to distinguish between an address or data character Contents 1 2 3 4 5 6 7 8 1 Introduction 9 Bit UART Initialization 9 Bit UART Function 9 Bit UART Limitations Application Information API Functional Description Conclusion References 1 1 2 5 5 5 5 5 Introduction The Universal Asynchronous Receiver Transmitter UART is a widely used serial communications peripheral used in many applications for connection to legacy devices and is present on all Stellaris microcontrollers Some systems require the additional functionality of a 9 bit UART with automatic address detection The 9 bit software UART uses a ninth bit to differentiate between a data or address character The auto address detection allows the user to program a specific address that is used to determine if the received data is supposed to be processed or discarded The 9 bit UART was written using the standard UART DriverLib API The 9 bit UART uses the same function structure as the standard UART but adds the NB prefix specifically for 9 bit UART calls This application note describes the 9 bit UART software add on in detail 2 9 Bit UART Initialization There are five initialization steps for the 9 bit UART 1 Enable UART and GPIO peripherals 2 Configure the GPIO pins for UART function 3 Set up the UART hardware 4 Enable the UART Rx interrupt 5 Customize the user programmable address 2 1 GPIO The GPIO setup is not included in the 9 bit UART API functions and must be done explicitly by the user The following steps are necessary to enable the UART and GPIO peripherals 1 Enable the appropriate GPIO port for the UART0 or UART1 Tx and Rx pins 2 Configure the UART0 or UART1 GPIO pins for UART operation a Configure the GPIO pins for standard push pull operation b Set the pins to be peripheral controlled 3 If your part has pin muxing set the pin mux for your device AN01280 August 2010 Using a 9 bit Software UART with Stellaris Microcontrollers Copyright 2010 Texas Instruments Inc 1 9 Bit UART Function Note 2 2 www ti com See the corresponding microcontroller data sheet for your device to find the correct UART GPIO port and pins UART The 9 bit UART API supports the use of only one UART port You can use either UART0 or UART1 but not both ports Note For 9 bit UART operation you must only use the DriverLib function calls that have the designated NB prefix There are two functions used to configure and initialize the 9 bit UART NB UARTConfigSetExpClk Sets up baud rate number of data bits and number of stop bits NB UARTEnable Enables the UART hardware and the UART receive interrupt 2 3 UART Interrupt For proper operation of the 9 bit UART enable the UART Rx interrupt using the NB UARTEnable function which enables the UART hardware interrupts on the nested vector interrupt controller NVIC and also enables the receive interrupt on the UART hardware You must enable the processor interrupts and explicitly add the NB UARTIntHandler interrupt handler to the interrupt vector table The UART interrupt can be configured to call a user function If the NB USER INT HANDLER macro is defined then the NB UserIntHandler function will be called in the UART interrupt handler Note 2 4 The NB UserIntHandler is called in an interrupt context Do not do time consuming operations in this function Programmable Address Use the following functions to set the 9 bit UART s single programmable address NB UARTAddressSet Sets the address for the UART hardware NB UARTAddressGet Returns the current address of the UART hardware This address is used by the UART to decide when to acknowledge or discard data You must properly set the device address prior to using the 9 bit UART Unlike some hardware implementations of the 9 bit UART the character used as the address is allowed to be received as a data For details on receiving a character see the Receive section for more information 3 9 Bit UART Function The 9 bit UART includes two sets of transmit functions one set of functions is used to transmit data and the other set is to transmit an address The received data is handled by the receive ISR and a software buffer For 9 bit UART operation you must only use the DriverLib function calls that have the designated NB prefix Note 3 1 See the API Functional Description in the accompanying source code package for this application note for more information on these functions Transmit The 9 bit UART API includes the following functions for sending addresses and data NB UARTBusy 2 Using a 9 bit Software UART with Stellaris Microcontrollers Copyright 2010 Texas Instruments Inc AN01280 August 2010 9 Bit UART Function www ti com Checks if the UART is busy sending or receiving another character NB UARTAddrPut Puts an address character in the transmit register if there is space available If there is no space available it blocks the write of the address character until space is available NB UARTAddrPutNonBlocking Puts an address character in the transmit register if there is space available If there is no space available it returns an error code NB UARTDataPut Puts a data character in the transmit register if there is space available If there is no space available it blocks the write of the data character until space is available NB UARTDataPutNonBlocking Puts a data character in the transmit register if there is space available If there is no space available it returns an error code Note The 9 bit UART does not use a transmit FIFO A single hardware register is used to transmit the data out of the UART The parity setting is used to differentiate between the send data and send address functions The send data function sets the parity to Stick Zero to make the ninth bit of the UART transfer a 0 and the send address function sets the parity to Stick One to make the ninth bit of the UART transfer a 1 After setting the parity the 9 bit UART functions use standard DriverLib function calls to send the character through the UART hardware The logic diagrams below show how the data and address transfers are performed Figure 1 shows an address transmission set parity bit to a 1 and Figure 2 shows a data transmission parity bit is a 0 These diagrams have the UART configured with one stop bit Figure 1 Sample Address Transfer AN01280
View Full Document
Unlocking...