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.

TM4C123 UARTCharPut and Interrupt Problem

Hello everyone,

I'm using

TIVA-C (TM4C123G) Launchpad,

Code Composer Studio Version: 6.1.1.00022

Hercules terminal)

I was trying to get interrupt TX and RX. After that, I want to 

For example  when terminal sends to me a data like this ''10 20 30 40'' , I want to reply ''50''.

Firstly I am trying to when terminal sends to me '1' , my code replies ' 2 '. 

But, here a problem, I am not see anything on terminal window without 'Enter Text'.

Here's my code,

#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"

// Used by UART interrupt handlers

unsigned char ptr[10]; // Array for storing incoming UART characters

unsigned char ReceiveData; // Incoming UART character

unsigned long i=0; // UART character pointer.

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
{
// Grab a character


ReceiveData = (unsigned char) UARTCharGetNonBlocking(UART0_BASE);

// Hold it
// ptr[i] = ReceiveData;


if (ReceiveData=='1') UARTCharPutNonBlocking(UART0_BASE,'2');

UARTCharPut(UART0_BASE, '2');

// Proceed to next character
// i++;
//// hold and send data
//UARTCharPutNonBlocking(UART0_BASE, UARTCharGetNonBlocking(UART0_BASE)); //echo character

}

}

int main(void) {

SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
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);

UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
IntMasterEnable(); //enable processor interrupts
IntEnable(INT_UART0); //enable the UART interrupt
UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_TX); //only enable RX and TX interrupts

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 (ReceiveData=='1'){ UARTCharPutNonBlocking(UART0_BASE,'2'); UARTCharPut(UART0_BASE, '2');}
}

  • Hello Eleanor

    Simplify. For any character you receive if you print on the screen in the interrupt handler then does it work?

    Regards
    Amit
  • Thanks Amit for answer,

    I rewrite code as follows,
    But when I send 8 bit '1' code replies nothing.
    Code is beginning to reply '2' when nineth '1' comes.
    Moreover, I was trying to send '10 20 ' and reply '30'
    I didn't solve these problems.

    Hope to receive some help.

    Thanks.

    #include <stdio.h>
    #include <stdint.h>
    #include <stdbool.h>
    #include "inc/hw_ints.h"
    #include "inc/hw_memmap.h"
    #include "inc/hw_types.h"
    #include "driverlib/gpio.h"
    #include "driverlib/interrupt.h"
    #include "driverlib/pin_map.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/uart.h"
    //#include "driverlib/uartstdio.h"

    void UARTSending(uint32_t nBase, char *nData){
    while(*nData!='\0')
    {
    if(UARTSpaceAvail(nBase))
    {
    while(!UARTCharPutNonBlocking(nBase,*nData));
    nData++;
    }

    }

    }

    void Int_Handler(void){

    unsigned char ReceiveData;
    //unsigned char Hold[8];
    //unsigned char SendData;
    //uint32_t i=0;
    uint32_t IntStatus;
    IntStatus=UARTIntStatus(UART0_BASE,true);
    UARTIntClear(UART0_BASE, IntStatus);
    ReceiveData=UARTCharGetNonBlocking(UART0_BASE);
    if((uint32_t)ReceiveData!=-1)
    {
    if(
    ReceiveData=='1')

    while(!UARTCharPutNonBlocking(UART0_BASE,'2'));
    }

    }

    int main (void){

    SysCtlClockSet( SYSCTL_USE_PLL| SYSCTL_OSC_MAIN| SYSCTL_XTAL_16MHZ |SYSCTL_SYSDIV_4);

    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);

    IntDisable(INT_UART0);
    UARTDisable(UART0_BASE);
    //UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);errorrr
    UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet() , 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
    UARTFIFODisable(UART0_BASE);
    UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_TX);
    //UARTIntRegister(UART0_BASE, Int_Handler);
    UARTEnable(UART0_BASE);
    IntEnable(INT_UART0);

    while(1){
    //UARTSending(UART0_BASE, "Enter Data:");
    SysCtlDelay((SysCtlClockGet ()/3000)*500); //5ms

    }
    }
  • I don't have time to critique your code right now but I can suggest a useful resource

    C Programmer's Guide to Serial Communications by Joe Campbell

    It's old and DOS oriented but it explains the concepts involved in asynchronous serial communications more thoroughly than any other resource I've seen. The DOS roots of the book are actually an advantage for embedded programmers working on Micros.

    Robert

  • Hello Eleanor,

    That would because the UARTEnable function enables the FIFO. So now the Receive Interrupt is based on FIFO level. If you put UARTFIFODisable after UARTEnable, then the behavior would change to per character interrupt.

    Regards
    Amit
  • Thanks Amit, I understood problem.
  • Hello Eleanor,

    So is it working as you expected it to?

    Regards
    Amit