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.

[TM4C1294NCPDT] UART interupt code example doesn't work with Tivaware???

Other Parts Discussed in Thread: EK-TM4C1294XL

Hi everyone, i'm a newbie here. I'm now learning about ARM on EK-TM4C1294XL kit with CCS ver 6.1 and TivaWare_C_Series-2.1.0.12573.

I have tried build code example about using UART with interupt, but it doesn't work. The trouble is some of warnnings show up, though i can still debug the code. So, when i send some character through uart, the kit cant echo it back. Can someone help me fix it. Thank you.

// This is the example code for uart using interupt. I haven't modified it.
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
#include "inc/hw_ints.h"
#include "driverlib/interrupt.h"

uint32_t ui32SysClkFreq;

void UARTIntHandler(void)
{
	uint32_t ui32Status;

	ui32Status = UARTIntStatus(UART0_BASE, true); //get interrupt status

	UARTIntClear(UART0_BASE, ui32Status); //clear the asserted interrupts

	while(UARTCharsAvail(UART0_BASE)) //loop while there are chars
	{
		UARTCharPutNonBlocking(UART0_BASE, UARTCharGetNonBlocking(UART0_BASE)); //echo character
		GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0|GPIO_PIN_1, 0xFF); 			// LEDs on
		SysCtlDelay(ui32SysClkFreq / (3 * 10)); 							    // delay .1 sec
		GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0|GPIO_PIN_1, 0); 				// LEDs off
	}
}

int main(void)
{
	ui32SysClkFreq = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
			SYSCTL_OSC_MAIN | SYSCTL_USE_PLL |
			SYSCTL_CFG_VCO_480), 120000000);

	SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

	GPIOPinConfigure(GPIO_PA0_U0RX);
	GPIOPinConfigure(GPIO_PA1_U0TX);
	GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);
	GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_0|GPIO_PIN_1);

	UARTConfigSetExpClk(UART0_BASE, ui32SysClkFreq, 115200,
			(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));

	IntMasterEnable();
	IntEnable(INT_UART0);
	UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);

	UARTCharPut(UART0_BASE, 'E');
	UARTCharPut(UART0_BASE, 'n');
	UARTCharPut(UART0_BASE, 't');
	UARTCharPut(UART0_BASE, 'e');
	UARTCharPut(UART0_BASE, 'r');
	UARTCharPut(UART0_BASE, ' ');
	UARTCharPut(UART0_BASE, 'T');
	UARTCharPut(UART0_BASE, 'e');
	UARTCharPut(UART0_BASE, 'x');
	UARTCharPut(UART0_BASE, 't');
	UARTCharPut(UART0_BASE, ':');
	UARTCharPut(UART0_BASE, ' ');

	while (1)
	{
		//		if (UARTCharsAvail(UART0_BASE)) UARTCharPut(UART0_BASE, UARTCharGet(UART0_BASE));
	}
}

  • Hello Tu

    Why are you using the Keil driverlib file in CCS?

    Regards
    Amit
  • I don't think so. I don't think that  driverlib is only for Keil or CCS, because I was followed the guide of TI CLP_Workbook. Am i wrong at something? Could you explain little more specify??? Thank you.

  • Thank you for your reply.
  • Hi,

    Several problems with your code:

    a) you did not configured the UART to respond to transmissions - actually it is configured to respond only to receiving and time-out. Sending is done without interrupt.

    b) if you like to check interrupts in actual code, send from the PC - use putty application to do that.

    c) from your posted pictures it seems you have some path problems - to remove them just import the uart_echo example and see all settings in CCS - it is mandatory to do that to learn how and where to modify the settings for other projects.

    Petrei

  • Dear Petrei,

    Thank you for your quick reply, and i'm sorry for my bad English, may be it 's the reason make you confused or misunderstood me. Let me explain about my trouble again.

    a) The code is a example of TI, so i don't think it have any mistake. When UART receive a character, it will trigger the interrupt to call the function UARTIntHandler to send back what it received. Here are the link of Workbook that i take this example code. I do it step by step carefully.

    You can find the example code in UART part.

    b) I rarely use putty so i used an other application name "Hercules" to send from PC to the board. The trouble is the board doesn't send back anything. I had tried complie the code in Keil C and it work perfectly!!!, though i have to paste the code in an existed example Keil 's project(i cant complie a new project, it said that it cant recognize some header of driverlib???)
    c) I was following all the step guide by TI Workbook. I think i have some mistakes with the driverlib 's path and i have no idea what it is.
    Please help me handle this. Thank you,

  • Hi,

    OK, you succeeded with Keil because yo used an already made project. To do the same with CCS, you must use an already made project in CCS - this is easily done if you import a project - go to Project | Import CCS Projects... and then go to Tiva/your board and select uart-echo project.

    Open startup_ccs.c file and check the interrupt vectors to be updated with the name of your interrupt routine in main file. Then build the project. 

    Then examine all settings in Project | Properties.

    Petrei

  • Okay, thank you for your advices.