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.

EK-TM4C1294XL: UART problem

Part Number: EK-TM4C1294XL

I am testing UART communication

UART4 works well for both recieve and transmit. but..

Strangely, UART0 is set the same as UART4, but receive interrupt can not be executed. 

I do not understand this behavior.

Attach the source code below.

thanks

-karls

//==============================================================================
// UART Initialize
//==============================================================================
void UART_INIT(void)
{

SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART4);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

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

GPIOPinConfigure(GPIO_PA2_U4RX);
GPIOPinConfigure(GPIO_PA3_U4TX);
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_2 | GPIO_PIN_3);

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

UARTConfigSetExpClk(UART4_BASE, ui32SysClock, 115200,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE));

UARTFIFOLevelSet(UART0_BASE, UART_FIFO_TX1_8, UART_FIFO_RX1_8);
//UARTTxIntModeSet(UART0_BASE, UART_TXINT_MODE_FIFO);
UARTFIFOEnable(UART0_BASE);
UARTFIFODisable(UART0_BASE);

//UARTFIFOLevelSet(UART4_BASE, UART_FIFO_TX1_8, UART_FIFO_RX1_8);
//UARTFIFOEnable(UART4_BASE);
UARTFIFODisable(UART4_BASE);

IntEnable(INT_UART0);
//UARTIntDisable(UART0_BASE, UART_INT_RX | UART_INT_TX);
UARTIntEnable(UART0_BASE, UART_INT_RX);

IntEnable(INT_UART4);
//UARTIntDisable(UART4_BASE, UART_INT_RX | UART_INT_TX);
UARTIntEnable(UART4_BASE, UART_INT_RX);

}

//==============================================================================
// UART 4 interrupt
//==============================================================================
void UART4_IntHandler(void)
{

uint32_t ui32Status;

ui32Status = UARTIntStatus(UART4_BASE, true);
UARTIntClear(UART4_BASE, ui32Status);

if(ui32Status & UART_INT_RX)
{

while(UARTCharsAvail(UART4_BASE))
{

COMM[COMM_232].RxD_TIMEOUT_CNT = 0;

COMM[COMM_232].RxD_BUF[COMM[COMM_232].RxD_BUF_PTR] = UARTCharGetNonBlocking(UART4_BASE);
if(++COMM[COMM_232].RxD_BUF_PTR >= 100) COMM[COMM_232].RxD_BUF_PTR = 0;

}

}
else if(ui32Status & UART_INT_TX)
{

if(COMM[COMM_232].TxD_BUF_PTR > COMM[COMM_232].TxD_END_PTR)
{

COMM[COMM_232].TxD_BUF_PTR = 0;
UARTIntDisable(UART4_BASE, UART_INT_TX);
UARTIntEnable(UART4_BASE, UART_INT_RX);

}

else
{

while(UARTSpaceAvail(UART4_BASE))

{

UARTCharPutNonBlocking(UART4_BASE, COMM[COMM_232].TxD_BUF[COMM[COMM_232].TxD_BUF_PTR++]);

}

}

}

}


//==============================================================================
// UART 0 interrupt
//==============================================================================
void UART0_IntHandler(void)
{

uint32_t ui32Status;

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

// Clear the asserted interrupt
UARTIntClear(UART0_BASE, ui32Status);

if(ui32Status & UART_INT_RX)
{

while(UARTCharsAvail(UART0_BASE))
{

COMM[COMM_485].RxD_TIMEOUT_CNT = 0;
COMM[COMM_485].RxD_BUF[COMM[COMM_485].RxD_BUF_PTR] = UARTCharGetNonBlocking(UART0_BASE);
if(++COMM[COMM_485].RxD_BUF_PTR >= 100) COMM[COMM_485].RxD_BUF_PTR = 0;

}

}

else if(ui32Status & UART_INT_TX)
{

if(COMM[COMM_485].TxD_BUF_PTR > COMM[COMM_485].TxD_END_PTR)

{

COMM[COMM_485].TxD_BUF_PTR = 0;
UARTIntDisable(UART0_BASE, UART_INT_TX);
UARTIntEnable(UART0_BASE, UART_INT_RX);

}

else
{

while(UARTSpaceAvail(UART0_BASE))

{

UARTCharPutNonBlocking(UART0_BASE, COMM[COMM_485].TxD_BUF[COMM[COMM_485].TxD_BUF_PTR++]);

}

}

}

}

//==============================================================================
// 50 us timer interrupt
//==============================================================================
void Timer1_A_IntHandler(void)
{

TimerIntClear(TIMER1_BASE, TIMER_TIMA_TIMEOUT);

//--------------------
// MODBUS 통신 (UART0)
//--------------------
if(COMM[COMM_485].RxD_FLAG == CLEAR)
{

if(++COMM[COMM_485].RxD_TIMEOUT_CNT > 200);
{

COMM[COMM_485].RxD_TIMEOUT_CNT = CLEAR;
if(COMM[COMM_485].RxD_BUF_PTR < 8) COMM[COMM_485].RxD_BUF_PTR = 0;

else
{

UARTIntDisable(UART0_BASE, UART_INT_RX);
COMM[COMM_485].RxD_FLAG = SET;

}

}


}


if(COMM[COMM_485].TxD_FLAG == SET)

{

if(++COMM[COMM_485].RESTIME > 100)
{

COMM[COMM_485].RESTIME = CLEAR;
COMM[COMM_485].TxD_FLAG = CLEAR;
HWREG(UART0_BASE + UART_O_CTL) |= UART_CTL_EOT;
UARTIntEnable(UART0_BASE, UART_INT_TX);

}

}

//--------------------
// MODBUS 통신 (UART4)
//--------------------
if(COMM[COMM_232].RxD_FLAG == CLEAR)
{

if(++COMM[COMM_232].RxD_TIMEOUT_CNT > 200)
{

COMM[COMM_232].RxD_TIMEOUT_CNT = CLEAR;
if(COMM[COMM_232].RxD_BUF_PTR < 8) COMM[COMM_232].RxD_BUF_PTR = 0;
else
{

UARTIntDisable(UART4_BASE, UART_INT_RX);
COMM[COMM_232].RxD_FLAG = SET;

}

}

}


if(COMM[COMM_232].TxD_FLAG == SET)
{

if(++COMM[COMM_232].RESTIME > 100)

{

COMM[COMM_232].RESTIME = CLEAR;
COMM[COMM_232].TxD_FLAG = CLEAR;
HWREG(UART4_BASE + UART_O_CTL) |= UART_CTL_EOT;
UARTIntEnable(UART4_BASE, UART_INT_TX);

}

}

}

//==============================================================================
// Main
//==============================================================================
int main(void)
{

ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
SYSCTL_OSC_MAIN |
SYSCTL_USE_PLL |
SYSCTL_CFG_VCO_480), 20000000);

UART_INIT();

while(1)
{

}

}

  • Firm/I do not use your MCU - yet should you be using an "LPad or Eval board" - does not UART_0 tie to that board's ICDI MCU - and might that cause the issue you note? (should UART_0 NOT tie to the ICDI - my theory loses support.)

    From a quick code review - your treatment of UART_0 very nicely agrees w/UART_4 - and that "parallelism" should yield success.
    It is rarely reported that UART_0 suffers "issues" - most always all (other) UARTs prove far more challenging...
  • cb1

    I am well aware of the comments.( does not UART_0 tie to that board's ICDI MCU - and might that cause the issue you note? )

    I use UART4 with a USB 2 serial converter,
    UART0 in question is using board's ICDI.

    To explain the more detailed situation,
    In case of UART4 that operates normally, it receives 8 bytes normally from PC.
    However, in UART0 (interrupts enter), only 1 bytes can be received.

    I don't understand this and confused.
  • Karls,
    First PLEASE PLEASE edit your post, and paste the code using the </> on the Rich Formatting options. It is too difficult to read someone else's code with no proper formatting.
    Second: the only place I see you sending bytes are already inside the UART interrupt. You need to start that transmission somewhere else.
    Next: if you will use the system to receive bytes, also enable RT interrupt, otherwise there is a big chance that you will not receive the last few incoming bytes until the next time the external device sends you something.
    Regards
    Bruno
  • Friend Bruno - clearly your directive to, "Paste the code via vendor's approved method" proves useful.

    However - poster notes "Success w/UART_4" and my (reasonable) review of his code showed great "parallelism" between that (succeeding, UART_4) code and his (failing, UART_0) code.     So - unless you've "missed that evidence" - how can you explain the variation in performance - between UARTs?     That's the (more) central issue - is it not?

    (now to your "new logo" - 2 staff members have (almost) recovered from "twitch eye & sinus drainage" - and we've prep'ed special sticky notes - to prevent "further view & recurrence of eye distress."     (has Portugal not yet instituted "standard art practices" for 3rd graders?)

  • cb1_mobile said:
    So - unless you've "missed that evidence" - how can you explain the variation in performance - between UARTs?

    I actually don't trust that evidence. UART0 should have failed as well, so I'm assuming it hasn't just because the PC sent something which triggered the RX... but I won't give it a deeper analysis for the time being.

    I don't like that logo either! I was organizing my stuff before going on holidays, and upon seeing so many launchpads, decided to put them together and photograph. The image triggered me a sentence: "Someone suggested me to increase the stack, and so I did". And for I had nothing better to do with the picture, I'll leave it as the "avatar" for the time being!

  • Every Ophthalmologist (in the west) thanks you - and I "withdraw" (for now) my critique of "Portugal's elementary grade art teachings...")

    Our "difference" in diagnostic methods may prove interesting - you "distrust poster's evidence" - while I "welcome & credit it" - and believe greatly in the power of "patterns yielding repetition."

    You appear to be "beating" the (usual) Euro exodus by a month - fare well (and do pray for staff's "visual healing.")

  • 
    
    Thanks for your good advice(paste the code using the </> on the Rich Formatting options)

    Bruno Saraiva said:
    Second: the only place I see you sending bytes are already inside the UART interrupt. You need to start that transmission somewhere else.

    I do not have the source code attached above, but I definitely started transmitting from elsewhere and started sending interrupts.
    (It was confirmed that a transmission interrupt was generated.)

    I do not know what the cause is, but I have succeeded in sending and receiving data from uart0 through modbus.
    But I was again confused.(This is not a problem with UART0 and UART4 at this time,  but focuses only on UART0.)
    The problem is that 7 bytes should be sent when sending, but 18 bytes are sent in my case.
    This seems to be something wrong.

    I will attach the source code again below.



    //==============================================================================
    //	UART Initialize
    //==============================================================================
    void	UART_INIT(void)
    {
    	SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    
    	//--------------------
    	// UART PIN 기능 설정
    	//--------------------
    	GPIOPinConfigure(GPIO_PA0_U0RX);
    	GPIOPinConfigure(GPIO_PA1_U0TX);
    	GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    
    	UARTConfigSetExpClk(UART0_BASE, ui32SysClock, 115200, 
    						(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
    						 UART_CONFIG_PAR_NONE));
    
    	
    	//------------------------
    	//	UART interrupt enable
    	//------------------------
    	IntEnable(INT_UART0);
    	UARTIntEnable(UART0_BASE, UART_INT_RX);
    }
    
    
    //==============================================================================
    //		UART 0 interrupt
    //==============================================================================
    void	UART0_IntHandler(void)
    {
    	uint32_t ui32Status;
    	
    	//	Get the interrupt status
    	ui32Status = UARTIntStatus(UART0_BASE, true);
    
    	//	Clear the asserted interrupt
    	UARTIntClear(UART0_BASE, ui32Status);
    	
    	if(ui32Status & UART_INT_RX)
        {
    		while(UARTCharsAvail(UART0_BASE))
    		{
    			COMM[UART0].RxD_BUF[COMM[UART0].RxD_BUF_PTR] = UARTCharGetNonBlocking(UART0_BASE);
    			COMM[UART0].RxD_TIMEOUT_CNT = 0;			
    	        
    			if(++COMM[UART0].RxD_BUF_PTR >= 200) COMM[UART0].RxD_BUF_PTR = 0;
    		}
        }
    	
        else if(ui32Status & UART_INT_TX)
        {
    		if(COMM[UART0].TxD_BUF_PTR > COMM[UART0].TxD_END_PTR)
    		{
    			COMM[UART0].TxD_BUF_PTR = 0;                           // step 2 : when i break here, COMM[UART0].TxD_BUF_PTR = 18...(7 should be normal, 
                                                                                                                                        I don't understand this part)
    			UARTIntDisable(UART0_BASE, UART_INT_TX);
    			UARTIntEnable(UART0_BASE, UART_INT_RX);
    			GPIOPinWrite(GPIO_PORTH_BASE, GPIO_PIN_0, RESET);
    		}
    		else
    		{
    			while(UARTSpaceAvail(UART0_BASE))
    			{
    				UARTCharPutNonBlocking(UART0_BASE, COMM[UART0].TxD_BUF[COMM[UART0].TxD_BUF_PTR++]);
    			}
    		}
        }
    }
    
    
    //==============================================================================
    //		Send message
    //==============================================================================
    void	SEND_MSG(u08 tx_ptr)                 //It is not visible in the source code, but this function is called when reception is complete.
    {
    	u16 crc_word;
    
    	crc_word = CRC_16(COMM[UART0].TxD_BUF, tx_ptr);
    	COMM[UART0].TxD_BUF[tx_ptr++] = crc_word & 0xFF;
    	COMM[UART0].TxD_BUF[tx_ptr]   = crc_word >> 8;
    
    	COMM[UART0].TxD_END_PTR = tx_ptr;
    
    	COMM[UART0].TxD_BUF_PTR = 0;                // step 1 : when break point here, COMM[UART0].TxD_BUF[o] ~ [6] = 0x01, 0x03, 0x02, 0x00, 0x14, 0xb8, 0x75 and 
                                                                                  COMM[UART0].TxD_END_PTR = 6
    	UARTCharPut(UART0_BASE, COMM[UART0].TxD_BUF[COMM[UART0].TxD_BUF_PTR++]); // as i told, tx tansmit start here
    }
    
    //==============================================================================
    //  Main
    //==============================================================================
    int 
    main(void)
    {
    	// Run from the PLL at 20 MHz.
            ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | 
        					SYSCTL_OSC_MAIN | 
        					SYSCTL_USE_PLL | 
        					SYSCTL_CFG_VCO_480), 20000000);
            IntMasterEnable();
    
    	while(1)
    	{
    		WaitUntilInt();
    	}
    }

    Is the interrupt handler wrong?  help me plz