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.

Tiva Launchpad : Triggering an interrupt on receive with UART, without using TivaWare



I am trying to make it so that an interrupt is triggered when data is received through the UART on the TivaLaunchpad without using TivaWare.

- I've set breakpoints in the interrupt handler to verify an interrupt was triggered, the software never stopped at this breakpoint. (Code below)

- I've tried implementing busy-wait to receive just to make sure there was nothing wrong with the rest of my code (e.g. UART setup...). Breakpoints in the busy wait loop stopped at the right line and confirmed I was receiving the right info

- The problem happens to be with how I set up the interrupts for UART

- This is the UART setup code. The 'third paragraph' in the UART_Init() method sets it up for interrupts. This is the part I've most probably got wrong.

````
void UART_Init(void) {

    //Enable UART and GPIO cloks for UART 0
    SYSCTL->RCGCUART |= (1<<0);
    SYSCTL->RCGCGPIO |= (1<<0);
    
    //Disable the UART
    UART0->CTL &= ~(1<<0);
    //Set the baud rate
    UART0->IBRD = 104;
    UART0->FBRD = 11;
    //Configure LCRH register
    UART0->LCRH = 0x00000070;
    
    //Configure for interrupts
    UART0->ICR |= (1<<4);
    UART0->IM |= (1<<4);
    //Priority of 4 for UART0_Handler (IRQ = 5)
    NVIC_SetPriority(UART0_IRQn,5);
    //Enable interrupts for UART 0
    NVIC_EnableIRQ(UART0_IRQn);

    //Reenable UART0
    UART0->CTL = (1<<0)|(1<<8)|(1<<9);
    
    //GPIOA
    GPIOA->DEN |= (1<<0)|(1<<1);
    GPIOA->AFSEL |= (1<<1)|(1<<0);
    GPIOA->PCTL = (1<<0)|(1<<4);
    GPIOA->AMSEL &= ~((1<<0)|(1<<1));

}

````

- This is the ISR for this interrupt:
````
int a;
void UART0_Handler(void) {
    
    UART0->ICR |= (1<<4);
//Line of random code to set a breakpoint to verify it is being executed
    a = 4;
    
}
````

- This is the main function :

I enable the `testCharacter = UART_InChar();` line to activate busy-wait.
````
int main(void)
{

    setup();
    
    while(1) {
//Activate line to enable busy-wait
        //testCharacter = UART_InChar();
}
}
````

- And the busy-wait routine:
````
unsigned char UART_InChar(void) {
    while((UART0->FR&0x0010) != 0);
    return (unsigned char)(UART0->DR&0xFF);
}
````

- Using Keil uVision 4
- I've searched for solutions online, but only found questions related to TivaWare, which I'm not familiar with and prefer avoiding.
  • Karim Nseir said:
    ... only found questions related to TivaWare, which I'm not familiar with and prefer avoiding.

    Yet - does not that "avoidance" force much extra: Time, Effort, & Detail upon your "helpers?"

    Your "Direct Register" code style requires each/every Register you list to be "visited" - and deeply examined - by first you - and then "ALL here who care to assist!"      Really - due to your "preference" (unjustified btw) you have forced a much higher work-load upon "others" - (even "helpful" others) - have you not?

    Completing projects in a timely fashion is vital for Tech firms' Marketing Success.     As a result - most such firms - "Prefer avoiding DRM code style."

    You may note (many) vendor comments urging the use of the API - for the reasons herein noted...       Code examples - w/in the API - accomplish your mission - and thus prove VERY MUCH PREFERRED!

  • Karim Nseir said:
    I am trying to make it so that an interrupt is triggered when data is received through the UART on the TivaLaunchpad without using TivaWare.

    I'm with cb1, there is no utility in this self imposed restriction.

    Robert

  • Might such restriction be (other) than "self-imposed?" (i.e. instructor who has little recognition or appreciation for the necessity for students to be (somewhat) efficient!)      

    Nothing prevents the joint use of the API (and) Register review - that fact (conveniently) avoided by those who would condemn their charges to, "unemployment."

    It must be noted that NEVER do posters - with such "strong" preferences - make any attempt to explain and/or justify such preference...

  • I have my reasons, and nothing's forcing you or anyone else to help.

    Or make a very off-topic comment...

  • KMN said:
    I am trying to make ... on the TivaLaunchpad without using TivaWare.

    Endorsing my other colleagues: DON'T try to do it. It is pointless.

    You say your are not familiar with TivaWare, but becoming familiar to it will require just a few hours, and trying to bypass it will require LOTS of hours and still make you project prone to lots of hard-to-fix errors.

    Suggestion:

    - Download and install TivaWare

    - Find the /docs folder on your installed files, and open the Driverlib User Guide - it is a file that's almost 5Mb large.

    Go to the UART chapter, and find the functions required to configure the UART and its interrupts.

    It will be easier than any alternative!

    Bruno

  • KMN said:
    Or make a very off-topic comment...

    Might you be so good as to explain "what" you find to be, "off topic?"       You may note that my guidance has been echoed by (now) two others - appears the topic has been well addressed!

  • Simple: I asked if someone could help point out the error in my code, to trigger interrupts on receive on the UART.
    I never asked for recommendations or opinions on whether TivaWare was a good alternative.

    Also, you seem to be giving me a (again unsolicited) lesson in morality here "Your "Direct Register" code style requires each/every Register you list to be "visited" - and deeply examined - by first you - and then "ALL here who care to assist!" Really - due to your "preference" (unjustified btw) you have forced a much higher work-load upon "others" - (even "helpful" others) - have you not?"
    That I never asked for.

    This is a forum, people can choose to help if they want to, or not. Your opinion is irrelevant and your aggressively unappreciated.
  • Thanks Bruno, I think you're right, I just thought that using this technique would give me more in-depth knowledge, and that I would learn to program more cortex MCUs (other than just TI)

    I'll give TivaWare a shot though.
  • KMN said:
    I just thought that using this technique would give me more in-depth knowledge, and that I would learn to program more cortex MCUs (other than just TI)

    The peripherals on other Cortex micros have little in common with those on TI Cortex micros.

    Robert

  • KMN, you're welcome!

    Have in mind that other cortex MCU's will also provide similar libraries. Think of this: it is not extremely important to learn that a certain function is UARTCharPut(), but rather, what's useful is to know that "there is a certain function to place a byte into the UART transmission port or wait until there is space available".

    It will be faster to find the equivalent driver API on a new platform than to figure out a bunch of registers. Just to make your decision even easier, think about a new project on a totally different platform, like the MSP430... again, you only need to find out which function sends stuff out the UART, and barely look at the register's chapter of the new datasheet!

    As for the "battle" with our other colleague, allow me to throw some cold ice here and settle the nerves down - there is not denial that cb1 was giving you a valid and experienced opinion. His style of writing is just that - a style - and there has been no outrage in there! Let's all remember that text can be read with whatever emphasis the reader so desire, and such was not necessarily the tone meant by the writer.

    Peace!

    Bruno
  • While poster Bruno's kindness in writing was/is appreciated - that writing style - even if opinion - stems from, "great Tech Biz success."

    Each poster here - when requesting assistance - is best advised to, "Sell their request." Forcing "poster preference" - upon each/every responder - severely limits such asssistance.    (this is fact - can be easily proven via past posting reviews)

    Thus - the intent - rather than being "aggressive" was direct - and cast for the requesting poster's benefit.    (it is noted that, "No response arrived - nor was expected" - due to the "overly restrictive nature" of the initial posting.)      And - the justification for such "over-restriction" was never attempted - thus "sympathy" drove to zero...

    Not always are "poster issues/questions" the most well-thought/considered ones.   Is it not then (almost) the "duty" of those w/more forum, "blood, sweat, tears" to suggest the application of, "Hard Rudder" - which steers poster to a superior course - and faster/easier & enhanced outcome?       If that is "my sin" - I believe that I can "live w/that..."

    Note too that this thread may be, "read by others" - and the "gentle" direction (away) from "DRM" and toward the API is likely to propagate...