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 receiver problem



Hi all,

I am trying to read 16 byte data from UART to process but I have an issue which I dont understand.

Data which I want to receive is 11 11 FF 03 0f 00 00 00 00 3e 34 01 01 a7 34 12 .. 

First  11 11 is header and 34 12 is footer.

After first packet which I read, I have always got byte 0x11. I did not solve.

this is the simple code

	SysCtlPeripheralEnable(PERIPH_GPIO_BLUETOOTH_UART);
	GPIOPinConfigure(CONF_GPIO_BLUETOOTH_UART_RX);
	GPIOPinConfigure(CONF_GPIO_BLUETOOTH_UART_TX);
	GPIOPinTypeUART(BASE_GPIO_BLUETOOTH_UART, PIN_GPIO_BLUETOOTH_UART_RX|PIN_GPIO_BLUETOOTH_UART_TX);
	
	SysCtlPeripheralEnable(PERIPH_UART_BLUETOOTH);	
	IntDisable(INT_UART_BLUETOOTH);	
	UARTDisable(BASE_UART_BLUETOOTH);	
	UARTClockSourceSet(BASE_UART_BLUETOOTH, UART_CLOCK_PIOSC);
	UARTConfigSetExpClk(BASE_UART_BLUETOOTH, 16000000, BAUDRATE_BLUETOOTH, UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE);
	UARTFIFODisable(BASE_UART_BLUETOOTH);	
	UARTIntEnable(BASE_UART_BLUETOOTH, UART_INT_RX | UART_INT_RT);	
	UARTIntRegister(BASE_UART_BLUETOOTH, IntBluetooth);
	UARTEnable(BASE_UART_BLUETOOTH);

	while (UARTCharsAvail(BASE_UART_BLUETOOTH))
	{
		rcvd_byte = UARTCharGet(BASE_UART_BLUETOOTH);
	}

Thanks in advance

  • As I understand I have problem with overrun Error (OE)
    How can avoid from this situation ? (DMA or using ROM Api)

    Thanks in advance
  • By reading the character out immediately, namely event-driven (by interrupt) and not by polling (that's what you do in this while() loop). Who knows what else you do before you come again across this loop ? You have not shown this code.

    There are plenty of examples in the TivaWare examples on how to use interrupts, also for UARTs.

  • Hello Tiva_Tick53

    Are you sure there is an Overrun error? Did you enable the error interrupt flags and check if the Error bits are getting set?

  • Sorry that is my fault to add all.

    This is code and while I am trying run 

    uint8_t rcvd_byte;
    
    void 
    IntBluetooth(void)
    {
    	ui32Status = ROM_UARTIntStatus(BASE_UART_BLUETOOTH, true);
    	
    	ROM_UARTIntClear(BASE_UART_BLUETOOTH, ui32Status);
    
    	
    	while (ROM_UARTCharsAvail(BASE_UART_BLUETOOTH))
    	{
    		rcvd_byte = (uint8_t)ROM_UARTCharGetNonBlocking(BASE_UART_BLUETOOTH);
    		
    	}
    }
    
    int 
    main (void)
    {
    SysCtlClockSet(SYSCTL_SYSDIV_2_5| SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN);
    SysCtlPeripheralEnable(PERIPH_GPIO_BLUETOOTH_UART);
    GPIOPinConfigure(CONF_GPIO_BLUETOOTH_UART_RX);
    GPIOPinConfigure(CONF_GPIO_BLUETOOTH_UART_TX);
    GPIOPinTypeUART(BASE_GPIO_BLUETOOTH_UART, PIN_GPIO_BLUETOOTH_UART_RX|PIN_GPIO_BLUETOOTH_UART_TX);
    
    SysCtlPeripheralEnable(PERIPH_UART_BLUETOOTH);  
    IntDisable(INT_UART_BLUETOOTH); 
    UARTDisable(BASE_UART_BLUETOOTH);   
    UARTClockSourceSet(BASE_UART_BLUETOOTH, UART_CLOCK_PIOSC);
    UARTConfigSetExpClk(BASE_UART_BLUETOOTH, 16000000, BAUDRATE_BLUETOOTH, UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE);
    UARTFIFODisable(BASE_UART_BLUETOOTH);   
    UARTIntEnable(BASE_UART_BLUETOOTH, UART_INT_RX | UART_INT_RT);  
    UARTIntRegister(BASE_UART_BLUETOOTH, IntBluetooth);
    UARTEnable(BASE_UART_BLUETOOTH);
    
    }

  • Yes I am sure. I follow UART_DR_OE
  • Hello Tiva_Tick53

    UART_DR_OE is not the interrupt enable bit for the UART Overrun interrupt. It is the nibble of status for the byte received on the UART bus.

    Now if you are getting overrun error in status bit, then first of all enable the FIFO. This will give you time to process the data. Secondly, you can use the DMA to transfer the data without having to run the overhead of the interrupt calls.
  • Thank you for all answers. May increasing clock frequency be solution for overrun ?
  • Hello Tiva_Tick53

    What is the baud rate of the external module. You are running the TM4C123x device at 80MHz which is more than enough for something like 115200 bps (nominal values for most external connections).
  • My baudrate is 115200. Thanks for all
  • Hello Tiva_Tick53

    Then a system clock of 80MHz and UART baud rate of 115200 bps should be more than enough. As mentioned above use the FIFO mechanism available in the UART (and enabled during UARTConfigSetExpClk API call).