This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

UART Tx interrupt for 1-byte transmission in Tiva TM4C1294



Hi,

         I am using  Tiva TM4C1294XL evaluation kit. I have configured the UART to operate in interrupt mode both for Tx as well as Rx. I want to transmit all the bytes through interrupt mode. I have tried to acheive this  by configuring the UART  in EOT Mode. I would like to transmit my first byte in TX isr without putting it directly in the data buffer. As per the datasheet this can be done by setting the EOT bit in CTRL register to trigger a Transmit interrupt (which means a transmit interrupt can be generated by setting the EOT bit in the CTRL register without having to put any data in the data register.). I tried the solution mentioned in the datasheet but this does not generate a TX interrupt. Kindly suggest by looking at following code if I am missing out on some thing.

//*****************************************************************************
//
// uart_echo.c - Example for reading data from and writing data to the UART in
//               an interrupt driven fashion.
//
// Copyright (c) 2013-2015 Texas Instruments Incorporated.  All rights reserved.
// Software License Agreement
//
// Texas Instruments (TI) is supplying this software for use solely and
// exclusively on TI's microcontroller products. The software is owned by
// TI and/or its suppliers, and is protected under applicable copyright
// laws. You may not combine this software with "viral" open-source
// software in order to form a larger program.
//
// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
// DAMAGES, FOR ANY REASON WHATSOEVER.
//
// This is part of revision 2.1.1.71 of the EK-TM4C1294XL Firmware Package.
//
//*****************************************************************************

#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "driverlib/debug.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/pin_map.h"
#include "driverlib/rom.h"
#include "driverlib/rom_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
#include "inc/tm4c1294ncpdt.h"

//*****************************************************************************
//
//! \addtogroup example_list
//! <h1>UART Echo (uart_echo)</h1>
//!
//! This example application utilizes the UART to echo text.  The first UART
//! (connected to the USB debug virtual serial port on the evaluation board)
//! will be configured in 115,200 baud, 8-n-1 mode.  All characters received on
//! the UART are transmitted back to the UART.
//
//*****************************************************************************

//****************************************************************************
//
// System clock rate in Hz.
//
//****************************************************************************
uint32_t g_ui32SysClock;

//*****************************************************************************
//
// The error routine that is called if the driver library encounters an error.
//
//*****************************************************************************
#ifdef DEBUG
void
__error__(char *pcFilename, uint32_t ui32Line)
{
}
#endif

//*****************************************************************************
//
// The UART interrupt handler.
//
//*****************************************************************************
const uint8_t *TxBuffer ;
uint32_t TxCount;
unsigned char TrxBuffer[80] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-!@#$0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-!"; //80
unsigned int txcounter = 0;
unsigned int txlen;
unsigned char txcomplete = 0;
void UARTSend(const uint8_t *pui8Buffer, uint32_t ui32Count);

void UARTIntHandler(void)
{
    uint32_t ui32Status;
    uint8_t  int_type;
    TxCount = 16;

    //
    // Get the interrrupt status.
    //
    ui32Status = ROM_UARTIntStatus(UART0_BASE, true);

    int_type = (uint8_t)((ui32Status & 0x0F0) >> 4);
    //
    // Clear the asserted interrupts.
    //
    ROM_UARTIntClear(UART0_BASE, ui32Status);


    switch(int_type)
    {

    case 1 :

			// Loop while there are characters in the receive FIFO.
			//
			while(ROM_UARTCharsAvail(UART0_BASE))
			{
				//
				// Read the next character from the UART and write it back to the UART.
				//
				ROM_UARTCharPutNonBlocking(UART0_BASE,ROM_UARTCharGetNonBlocking(UART0_BASE));

				//
				// Blink the LED to show a character transfer is occuring.
				//
				GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, GPIO_PIN_0);

				//
				// Delay for 1 millisecond.  Each SysCtlDelay is about 3 clocks.
				//
				SysCtlDelay(g_ui32SysClock / (1000 * 3));

				//
				// Turn off the LED
				//
				GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, 0);
			}
			break;

    case 2:

    	UARTSend((uint8_t *)&TrxBuffer[txcounter++],1);
    	if(txcounter > txlen )
    	{
    		UARTIntDisable(UART0_BASE, UART_INT_TX);
    		txcomplete = 1;
    	}
    	 break;

    default:
    	break;


    }
}

//*****************************************************************************
//
// Send a string to the UART.
//
//*****************************************************************************
void UARTSend(const uint8_t *pui8Buffer, uint32_t ui32Count)
{
    //
    // Loop while there are more characters to send.
    //
    while(ui32Count--)
    {
        //
        // Write the next character to the UART.
        //
        //ROM_UARTCharPutNonBlocking(UART0_BASE, *pui8Buffer++);

    	UARTCharPut(UART0_BASE, *pui8Buffer);
    }
}

//*****************************************************************************
//
// This example demonstrates how to send a string of data to the UART.
//
//*****************************************************************************

void Enable_Interrupt_Tx_Transmission(void)
{
	UARTDisable(UART0_BASE);
	while(ROM_UARTCharsAvail(UART0_BASE) && (ROM_UARTSpaceAvail(UART0_BASE)));
	txcomplete = 0;
	UARTTxIntModeSet(UART0_BASE, UART_TXINT_MODE_EOT);


	ROM_UARTConfigSetExpClk(UART0_BASE, g_ui32SysClock, 9600,
			   (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
				 UART_CONFIG_PAR_NONE));
	ROM_IntMasterEnable();
	ROM_IntEnable(INT_UART0);
	UARTIntEnable(UART0_BASE, UART_INT_TX|UART_INT_RX|UART_INT_RT);
	UART0_CTL_R |= 0x10;
	UARTEnable(UART0_BASE);

}

int main(void)
{
    //
    // Set the clocking to run directly from the crystal at 120MHz.
    //
    g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
                                             SYSCTL_OSC_MAIN |
                                             SYSCTL_USE_PLL |
                                             SYSCTL_CFG_VCO_480), 120000000);
    //
    // Enable the GPIO port that is used for the on-board LED.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);

    //
    // Enable the GPIO pins for the LED (PN0).
    //
    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_0);

    //
    // Enable the peripherals used by this example.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

    //
    // Enable processor interrupts.
    //
    ROM_IntMasterEnable();

    //
    // Set GPIO A0 and A1 as UART pins.
    //
    GPIOPinConfigure(GPIO_PA0_U0RX);
    GPIOPinConfigure(GPIO_PA1_U0TX);
    ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    ROM_IntMasterDisable();
    UARTDisable(UART0_BASE);
    //UARTFIFODisable(UART0_BASE);

    //UARTFIFOLevelSet(UART0_BASE, UART_FIFO_TX1_8, UART_FIFO_RX1_8); //Add

    UARTTxIntModeSet(UART0_BASE, UART_TXINT_MODE_EOT);
   // UARTModemControlSet(UART0_BASE,UART_TXINT_MODE_EOT);

    ROM_UARTConfigSetExpClk(UART0_BASE, g_ui32SysClock, 9600,
                               (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                                 UART_CONFIG_PAR_NONE));

    ROM_IntMasterEnable();

    ROM_IntEnable(INT_UART0);
    UARTIntEnable(UART0_BASE,UART_INT_TX|UART_INT_RX|UART_INT_RT);

    UARTEnable(UART0_BASE);
    //UARTFIFOEnable(UART0_BASE);

    //
    // Loop forever echoing data through the UART.
    //

    txlen = 10;

	Enable_Interrupt_Tx_Transmission();
	while(!(txcomplete));


	while(1)
    {

    }
}

     

  • Hello Rajesh

    The UART interrupt for transmit will fire only when the buffer data has been sent. it will not assert an interrupt just because the buffer is empty.

    You would need to prime the data buffer by writing a byte before the transmit interrupt can be asserted.

    Regards
    Amit