Because of the Thanksgiving holiday in the U.S., TI E2E™ design support forum responses may be delayed from November 25 through December 2. Thank you for your patience.

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 unable to receive full transmitted string LM3S5632

Other Parts Discussed in Thread: LM3S5632, LM3S8962, EK-LM3S8962

Hi ,

I am working on a project in which i had interfaced GSM module with LM3S5632 board through UART. I am using another PC which is acting like a server  and another is as client (CortexM3 + GSM ).

Using above setup i am sending a string of 20 characters ,but receiver is unable to receive full 20 character.

Later i tried to check whether UART is working properly or not ,i took 2 LM3S5632 based board & treated one as transmitter & another one as receiver & then tried various combinations of string ,but again i found receiver board is unable to receive the full string .

Please find below the UART testing results.

Also Please find the attached zip file for UART testing code.

Kindly help me out.[

View:http://e2e.ti.com/cfs-file.ashx/__key/communityserver-discussions-components-files/908/8765.TEST-CODES.rar]

Array send from transmitter

Array received at receiver end(observed on hyper terminal)

Array accepted by UART,Remaining data discarded

a ,b ,c ,d ,e ,f ,g ,h ,i ,j ,k ,l,

m ,n ,o ,p ,q ,r ,s ,t ,u ,v ,

w ,x ,y ,z

 

a ,b ,c ,d ,e ,f ,g ,h ,i ,j ,k ,l,

m ,n ,o ,p ,q ,r ,s ,t ,u ,v ,

w ,x ,y ,z

 

a ,b ,c ,d ,e ,f ,g ,h ,

i ,j ,k ,l ,m ,n ,o ,p

1,2,3,4,5,6,7,8,9,0,1,2,3,4,

5,6,7,8,9,0

1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0

1,2,3,4,5,6,7,8,9,0,

1,2,3,4,5,6

1,a,2,b,3,c,4,d,5,e,6,f,7,g,8,h,9,i,0

1,a,2,b,3,c,4,d,5,e,6,f,7,g,8,h,9,i,0,

 

1,a,2,b,3,c,4,d,5,

e,6,f,7,g,8,h

  • Hi, for some reason I can't unzip your code but as you are only getting 16 characters received and the UART has a hardware 16 byte buffer, I suspect you are not servicing the uart fast enough (or letting the interrupt fill a buffer for you). Hope this helps. Richard

  • Hi Richard,

    Thanks for your quick reply.

    Kindly advice ,if i can increase the buffer size to transmit & receive more than 16 bytes.

    Also please find attached code for transmit & receive.

    Please have a look & let me know the mistakes

    3755.uartstdio.c
    //*****************************************************************************
    //
    // uartstdio.c - Utility driver to provide simple UART console functions.
    //
    // Copyright (c) 2007-2009 Luminary Micro, Inc.  All rights reserved.
    // Software License Agreement
    // 
    // Luminary Micro, Inc. (LMI) is supplying this software for use solely and
    // exclusively on LMI's microcontroller products.
    // 
    // The software is owned by LMI and/or its suppliers, and is protected under
    // applicable copyright laws.  All rights are reserved.  You may not combine
    // this software with "viral" open-source software in order to form a larger
    // program.  Any use in violation of the foregoing restrictions may subject
    // the user to criminal sanctions under applicable laws, as well as to civil
    // liability for the breach of the terms and conditions of this license.
    // 
    // THIS SOFTWARE IS PROVIDED "AS IS".  NO WARRANTIES, WHETHER EXPRESS, IMPLIED
    // OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
    // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
    // LMI SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
    // CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
    // 
    // This is part of revision 4781 of the Stellaris Firmware Development Package.
    //
    //*****************************************************************************
    
    #include <stdarg.h>
    #include "inc/hw_ints.h"
    #include "inc/hw_memmap.h"
    #include "inc/hw_types.h"
    #include "inc/hw_uart.h"
    #include "driverlib/debug.h"
    #include "driverlib/interrupt.h"
    #include "driverlib/rom.h"
    #include "driverlib/rom_map.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/uart.h"
    #include "utils/uartstdio.h"
    
    //*****************************************************************************
    //
    //! \addtogroup uartstdio_api
    //! @{
    //
    //*****************************************************************************
    
    //*****************************************************************************
    //
    // If buffered mode is defined, set aside RX and TX buffers and read/write
    // pointers to control them.
    //
    //*****************************************************************************
    #ifdef UART_BUFFERED
    
    //*****************************************************************************
    //
    // This global controls whether or not we are echoing characters back to the
    // transmitter.  By default, echo is enabled but if using this module as a
    // convenient method of implementing a buffered serial interface over which
    // you will be running an application protocol, you are likely to want to
    // disable echo by calling UARTEchoSet(false).
    //
    //*****************************************************************************
    static tBoolean g_bDisableEcho;
    
    //*****************************************************************************
    //
    // Output ring buffer.  Buffer is full if g_ulUARTTxReadIndex is one ahead of
    // g_ulUARTTxWriteIndex.  Buffer is empty if the two indices are the same.
    //
    //*****************************************************************************
    static unsigned char g_pcUARTTxBuffer[UART_TX_BUFFER_SIZE];
    static volatile unsigned long g_ulUARTTxWriteIndex = 0;
    static volatile unsigned long g_ulUARTTxReadIndex = 0;
    
    //*****************************************************************************
    //
    // Input ring buffer.  Buffer is full if g_ulUARTTxReadIndex is one ahead of
    // g_ulUARTTxWriteIndex.  Buffer is empty if the two indices are the same.
    //
    //*****************************************************************************
    unsigned char g_pcUARTRxBuffer[UART_RX_BUFFER_SIZE];//	UART_TX_BUFFER_SIZE	 change on 03/02/14
    static volatile unsigned long g_ulUARTRxWriteIndex = 0;
    static volatile unsigned long g_ulUARTRxReadIndex = 0;
    //*****************************************************************************
    //
    // Macros to determine number of free and used bytes in the transmit buffer.
    //
    //*****************************************************************************
    #define TX_BUFFER_USED          (GetBufferCount(&g_ulUARTTxReadIndex,  \
                                                    &g_ulUARTTxWriteIndex, \
                                                    UART_TX_BUFFER_SIZE))
    #define TX_BUFFER_FREE          (UART_TX_BUFFER_SIZE - TX_BUFFER_USED)
    #define TX_BUFFER_EMPTY         (IsBufferEmpty(&g_ulUARTTxReadIndex,   \
                                                   &g_ulUARTTxWriteIndex))
    #define TX_BUFFER_FULL          (IsBufferFull(&g_ulUARTTxReadIndex,  \
                                                  &g_ulUARTTxWriteIndex, \
                                                  UART_TX_BUFFER_SIZE))
    #define ADVANCE_TX_BUFFER_INDEX(Index) \
                                    (Index) = ((Index) + 1) % UART_TX_BUFFER_SIZE
    
    //*****************************************************************************
    //
    // Macros to determine number of free and used bytes in the receive buffer.
    //
    //*****************************************************************************
    #define RX_BUFFER_USED          (GetBufferCount(&g_ulUARTRxReadIndex,  \
                                                    &g_ulUARTRxWriteIndex, \
                                                    UART_RX_BUFFER_SIZE))
    #define RX_BUFFER_FREE          (UART_RX_BUFFER_SIZE - RX_BUFFER_USED)
    #define RX_BUFFER_EMPTY         (IsBufferEmpty(&g_ulUARTRxReadIndex,   \
                                                   &g_ulUARTRxWriteIndex))
    #define RX_BUFFER_FULL          (IsBufferFull(&g_ulUARTRxReadIndex,  \
                                                  &g_ulUARTRxWriteIndex, \
                                                  UART_RX_BUFFER_SIZE))
    #define ADVANCE_RX_BUFFER_INDEX(Index) \
                                    (Index) = ((Index) + 1) % UART_RX_BUFFER_SIZE
    #endif
    
    //*****************************************************************************
    //
    // The base address of the chosen UART.
    //
    //*****************************************************************************
    static unsigned long g_ulBase = 0;
    
    //*****************************************************************************
    //
    // A mapping from an integer between 0 and 15 to its ASCII character
    // equivalent.
    //
    //*****************************************************************************
    static const char * const g_pcHex = "0123456789abcdef";
    
    //*****************************************************************************
    //
    // The list of possible base addresses for the console UART.
    //
    //*****************************************************************************
    static const unsigned long g_ulUARTBase[3] =
    {
        UART0_BASE, UART1_BASE, UART2_BASE
    };
    
    #ifdef UART_BUFFERED
    //*****************************************************************************
    //
    // The list of possible interrupts for the console UART.
    //
    //*****************************************************************************
    static const unsigned long g_ulUARTInt[3] =
    {
        INT_UART0, INT_UART1, INT_UART2
    };
    
    //*****************************************************************************
    //
    // The port number in use.
    //
    //*****************************************************************************
    static unsigned long g_ulPortNum;
    #endif
    
    //*****************************************************************************
    //
    // The list of UART peripherals.
    //
    //*****************************************************************************
    static const unsigned long g_ulUARTPeriph[3] =
    {
        SYSCTL_PERIPH_UART0, SYSCTL_PERIPH_UART1, SYSCTL_PERIPH_UART2
    };
    extern void buz_on(void);
    extern tBoolean receive_flag;
    extern unsigned int interrupt_counter;
    //*****************************************************************************
    //
    //! Determines whether the ring buffer whose pointers and size are provided
    //! is full or not.
    //!
    //! \param pulRead points to the read index for the buffer.
    //! \param pulWrite points to the write index for the buffer.
    //! \param ulSize is the size of the buffer in bytes.
    //!
    //! This function is used to determine whether or not a given ring buffer is
    //! full.  The structure of the code is specifically to ensure that we do not
    //! see warnings from the compiler related to the order of volatile accesses
    //! being undefined.
    //!
    //! \return Returns \b true if the buffer is full or \b false otherwise.
    //
    //*****************************************************************************
    #ifdef UART_BUFFERED
    static tBoolean
    IsBufferFull(volatile unsigned long *pulRead,
                 volatile unsigned long *pulWrite, unsigned long ulSize)
    {
        unsigned long ulWrite;
        unsigned long ulRead;
    
        ulWrite = *pulWrite;
        ulRead = *pulRead;
    
        return((((ulWrite + 1) % ulSize) == ulRead) ? true : false);
    }
    #endif
    
    //*****************************************************************************
    //
    //! Determines whether the ring buffer whose pointers and size are provided
    //! is empty or not.
    //!
    //! \param pulRead points to the read index for the buffer.
    //! \param pulWrite points to the write index for the buffer.
    //!
    //! This function is used to determine whether or not a given ring buffer is
    //! empty.  The structure of the code is specifically to ensure that we do not
    //! see warnings from the compiler related to the order of volatile accesses
    //! being undefined.
    //!
    //! \return Returns \b true if the buffer is empty or \b false otherwise.
    //
    //*****************************************************************************
    #ifdef UART_BUFFERED
    static tBoolean
    IsBufferEmpty(volatile unsigned long *pulRead,
                  volatile unsigned long *pulWrite)
    {
        unsigned long ulWrite;
        unsigned long ulRead;
    
        ulWrite = *pulWrite;
        ulRead = *pulRead;
    
        return((ulWrite  == ulRead) ? true : false);
    }
    #endif
    
    //*****************************************************************************
    //
    //! Determines the number of bytes of data contained in a ring buffer.
    //!
    //! \param pulRead points to the read index for the buffer.
    //! \param pulWrite points to the write index for the buffer.
    //! \param ulSize is the size of the buffer in bytes.
    //!
    //! This function is used to determine how many bytes of data a given ring
    //! buffer currently contains.  The structure of the code is specifically to
    //! ensure that we do not see warnings from the compiler related to the order
    //! of volatile accesses being undefined.
    //!
    //! \return Returns the number of bytes of data currently in the buffer.
    //
    //*****************************************************************************
    #ifdef UART_BUFFERED
    static unsigned long
    GetBufferCount(volatile unsigned long *pulRead,
                   volatile unsigned long *pulWrite, unsigned long ulSize)
    {
        unsigned long ulWrite;
        unsigned long ulRead;
    
        ulWrite = *pulWrite;
        ulRead = *pulRead;
    
        return((ulWrite >= ulRead) ? (ulWrite - ulRead) :
                                     (ulSize - (ulRead - ulWrite)));
    }
    #endif
    
    //*****************************************************************************
    //
    // Take as many bytes from the transmit buffer as we have space for and move
    // them into the UART transmit FIFO.
    //
    //*****************************************************************************
    #ifdef UART_BUFFERED
    static void
    UARTPrimeTransmit(unsigned long ulBase)
    {
        //
        // Do we have any data to transmit?
        //
        if(!TX_BUFFER_EMPTY)
        {
            //
            // Disable the UART interrupt. If we don't do this there is a race
            // condition which can cause the read index to be corrupted.
            //
            MAP_IntDisable(g_ulUARTInt[g_ulPortNum]);
    
            //
            // Yes - take some characters out of the transmit buffer and feed
            // them to the UART transmit FIFO.
            //
            while(MAP_UARTSpaceAvail(ulBase) && !TX_BUFFER_EMPTY)
            {
                MAP_UARTCharPutNonBlocking(ulBase,
                                           g_pcUARTTxBuffer[g_ulUARTTxReadIndex]);
                ADVANCE_TX_BUFFER_INDEX(g_ulUARTTxReadIndex);
            }
    
            //
            // Reenable the UART interrupt.
            //
            MAP_IntEnable(g_ulUARTInt[g_ulPortNum]);
        }
    }
    #endif
    
    //*****************************************************************************
    //
    //! Initializes the UART console.
    //!
    //! \param ulPortNum is the number of UART port to use for the serial console
    //! (0-2)
    //!
    //! This function will initialize the specified serial port to be used as a
    //! serial console.  The serial parameters will be set to 115200, 8-N-1.
    //!
    //! This function must be called prior to using any of the other UART console
    //! functions: UARTprintf() or UARTgets().  In order for this function to work
    //! correctly, SysCtlClockSet() must be called prior to calling this function.
    //!
    //! It is assumed that the caller has previously configured the relevant UART
    //! pins for operation as a UART rather than as GPIOs.
    //!
    //! \return None.
    //
    //*****************************************************************************
    void
    UARTStdioInit(unsigned long ulPortNum)
    {
        //
        // Check the arguments.
        //
        ASSERT((ulPortNum == 0) || (ulPortNum == 1) ||
               (ulPortNum == 2));
    
    	#ifdef UART_BUFFERED
        //
        // In buffered mode, we only allow a single instance to be opened.
        //
        ASSERT(g_ulBase == 0);
    	#endif
    
        //
        // Check to make sure the UART peripheral is present.
        //
        if(!MAP_SysCtlPeripheralPresent(g_ulUARTPeriph[ulPortNum]))
        {
            return;
        }
    
        //
        // Select the base address of the UART.
        //
        g_ulBase = g_ulUARTBase[ulPortNum];
    
        //
        // Enable the UART peripheral for use.
        //
        MAP_SysCtlPeripheralEnable(g_ulUARTPeriph[ulPortNum]);
    
        //
        // Configure the UART for 115200, n, 8, 1					 //9600,
        //
    	// 19200 buadrate 8 bit parity non stop 1 bit //changed 19200 to 9600 on 22/04/13
        MAP_UARTConfigSetExpClk(g_ulBase, MAP_SysCtlClockGet(),9600,
                               (UART_CONFIG_PAR_NONE | UART_CONFIG_STOP_ONE |
                                 UART_CONFIG_WLEN_8));	 //115200
    	
    	// UARTStdioConfig(0,9600,SysCtlClockGet()); //	unsigned long ulPortNum
    #ifdef UART_BUFFERED
        //
        // Set the UART to interrupt whenever the TX FIFO is almost empty or
        // when any character is received.
        //
    	//buz_on();buz_on();buz_on();
        MAP_UARTFIFOLevelSet(g_ulBase, UART_FIFO_TX1_8, UART_FIFO_RX1_8);
    
        //
        // Flush both the buffers.
        //
        UARTFlushRx();
        UARTFlushTx(true);
    
        //
        // Remember which interrupt we are dealing with.
        //
        g_ulPortNum = ulPortNum;
    
        //
        // We are configured for buffered output so enable the master interrupt
        // for this UART and the receive interrupts.  We don't actually enable the
        // transmit interrupt in the UART itself until some data has been placed
        // in the transmit buffer.
    //    //
        MAP_UARTIntDisable(g_ulBase, 0xFFFFFFFF);
        MAP_UARTIntEnable(g_ulBase, UART_INT_RX | UART_INT_RT);
        MAP_IntEnable(g_ulUARTInt[ulPortNum]);
    //	buz_on();
    
    #endif
    
        //
        // Enable the UART operation.
        //
        MAP_UARTEnable(g_ulBase);
    }
    //*****************************************************************************
    //
    //! Writes a string of characters to the UART output.
    //!
    //! \param pcBuf points to a buffer containing the string to transmit.
    //! \param ulLen is the length of the string to transmit.
    //!
    //! This function will transmit the string to the UART output.  The number of
    //! characters transmitted is determined by the \e ulLen parameter.  This
    //! function does no interpretation or translation of any characters.  Since
    //! the output is sent to a UART, any LF (/n) characters encountered will be
    //! replaced with a CRLF pair.
    //!
    //! Besides using the \e ulLen parameter to stop transmitting the string, if a
    //! null character (0) is encountered, then no more characters will be
    //! transmitted and the function will return.
    //!
    //! In non-buffered mode, this function is blocking and will not return until
    //! all the characters have been written to the output FIFO.  In buffered mode,
    //! the characters are written to the UART transmit buffer and the call returns
    //! immediately.  If insufficient space remains in the transmit buffer,
    //! additional characters are discarded.
    //!
    //! \return Returns the count of characters written.
    //
    //*****************************************************************************
    int
    UARTwrite(const char *pcBuf, unsigned long ulLen)
    {
    #ifdef UART_BUFFERED
        unsigned int uIdx;
    
        //
        // Check for valid arguments.
        //
        ASSERT(pcBuf != 0);
        ASSERT(g_ulBase != 0);
    
        //
        // Send the characters
        //
        for(uIdx = 0; uIdx < ulLen; uIdx++)
        {
            //
            // If the character to the UART is \n, then add a \r before it so that
            // \n is translated to \n\r in the output.
            //
            if(pcBuf[uIdx] == '\n')
            {
                if(!TX_BUFFER_FULL)
                {
                    g_pcUARTTxBuffer[g_ulUARTTxWriteIndex] = '\r';
                    ADVANCE_TX_BUFFER_INDEX(g_ulUARTTxWriteIndex);
                }
                else
                {
                    //
                    // Buffer is full - discard remaining characters and return.
                    //
                    break;
                }
            }
    
            //
            // Send the character to the UART output.
            //
            if(!TX_BUFFER_FULL)
            {
                g_pcUARTTxBuffer[g_ulUARTTxWriteIndex] = pcBuf[uIdx];
                ADVANCE_TX_BUFFER_INDEX(g_ulUARTTxWriteIndex);
            }
            else
            {
                //
                // Buffer is full - discard remaining characters and return.
                //
                break;
            }
        }
    
        //
        // If we have anything in the buffer, make sure that the UART is set
        // up to transmit it.
        //
        if(!TX_BUFFER_EMPTY)
        {
            UARTPrimeTransmit(g_ulBase);
            MAP_UARTIntEnable(g_ulBase, UART_INT_TX);
        }
    
        //
        // Return the number of characters written.
        //
        return(uIdx);
    #else
        unsigned int uIdx;
    
        //
        // Check for valid UART base address, and valid arguments.
        //
        ASSERT(g_ulBase != 0);
        ASSERT(pcBuf != 0);
    
        //
        // Send the characters
        //
        for(uIdx = 0; uIdx < ulLen; uIdx++)
        {
            //
            // If the character to the UART is \n, then add a \r before it so that
            // \n is translated to \n\r in the output.
            //
            if(pcBuf[uIdx] == '\n')
            {
                MAP_UARTCharPut(g_ulBase, '\r');
            }
    
            //
            // Send the character to the UART output.
            //
            MAP_UARTCharPut(g_ulBase, pcBuf[uIdx]);
        }
    
        //
        // Return the number of characters written.
        //
        return(uIdx);
    #endif
    }
    
    //*****************************************************************************
    //
    //! A simple UART based get string function, with some line processing.
    //!
    //! \param pcBuf points to a buffer for the incoming string from the UART.
    //! \param ulLen is the length of the buffer for storage of the string,
    //! including the trailing 0.
    //!
    //! This function will receive a string from the UART input and store the
    //! characters in the buffer pointed to by \e pcBuf.  The characters will
    //! continue to be stored until a termination character is received.  The
    //! termination characters are CR, LF, or ESC.  A CRLF pair is treated as a
    //! single termination character.  The termination characters are not stored in
    //! the string.  The string will be terminated with a 0 and the function will
    //! return.
    //!
    //! In both buffered and unbuffered modes, this function will block until
    //! a termination character is received.  If non-blocking operation is required
    //! in buffered mode, a call to UARTPeek() may be made to determine whether
    //! a termination character already exists in the receive buffer prior to
    //! calling UARTgets().
    //!
    //! Since the string will be null terminated, the user must ensure that the
    //! buffer is sized to allow for the additional null character.
    //!
    //! \return Returns the count of characters that were stored, not including
    //! the trailing 0.
    //
    //*****************************************************************************
    int
    UARTgets(char *pcBuf, unsigned long ulLen)
    {
    #ifdef UART_BUFFERED
        unsigned long ulCount = 0;
        char cChar;
    
        //
        // Check the arguments.
        //
        ASSERT(pcBuf != 0);
        ASSERT(ulLen != 0);
        ASSERT(g_ulBase != 0);
    
        //
        // Adjust the length back by 1 to leave space for the trailing
        // null terminator.
        //
        ulLen--;
    
        //
        // Process characters until a newline is received.
        //
        while(1)
        {
    		
            //
            // Read the next character from the receive buffer.
            //
            if(!RX_BUFFER_EMPTY)
            {
    	
                cChar = g_pcUARTRxBuffer[g_ulUARTRxReadIndex];
                ADVANCE_RX_BUFFER_INDEX(g_ulUARTRxReadIndex);
    
                //
                // See if a newline or escape character was received.
                //
                //if((cChar == '\r') || (cChar == '\n') || (cChar == 0x1b))
    			if((cChar == '\r') || (cChar == '\n') || (cChar == 0x1b))
                {
                    //
                    // Stop processing the input and end the line.
                    //
                    break;
                }
    
                //
                // Process the received character as long as we are not at the end
                // of the buffer.  If the end of the buffer has been reached then
                // all additional characters are ignored until a newline is
                // received.
                //
                if(ulCount < ulLen)
                {
                    //
                    // Store the character in the caller supplied buffer.
                    //
                    pcBuf[ulCount] = cChar;
    
                    //
                    // Increment the count of characters received.
                    //
                    ulCount++;
                }
            }
        }
    
        //
        // Add a null termination to the string.
        //
        pcBuf[ulCount] = 0;
    
        //
        // Return the count of chars in the buffer, not counting the trailing 0.
        //
        return(ulCount);
    #else
        unsigned long ulCount = 0;
        char cChar;
        static char bLastWasCR = 0;
    
        //
        // Check the arguments.
        //
        ASSERT(pcBuf != 0);
        ASSERT(ulLen != 0);
        ASSERT(g_ulBase != 0);
    
        //
        // Adjust the length back by 1 to leave space for the trailing
        // null terminator.
        //
        ulLen--;
    
        //
        // Process characters until a newline is received.
        //
        while(1)
        {
           // buz_on();
    		//
            // Read the next character from the console.
            //
            cChar = MAP_UARTCharGet(g_ulBase);
    
            //
            // See if the backspace key was pressed.
            //
            /*if(cChar == '\b')
            {
                //
                // If there are any characters already in the buffer, then delete
                // the last.
                //
                if(ulCount)
                {
                    //
                    // Rub out the previous character.
                    //
                    UARTwrite("\b \b", 3);
    
                    //
                    // Decrement the number of characters in the buffer.
                    //
                    ulCount--;
                }
    
                //
                // Skip ahead to read the next character.
                //
                continue;
            }  */
    
            //
            // If this character is LF and last was CR, then just gobble up the
            // character because the EOL processing was taken care of with the CR.
            //
          /*  if((cChar == '\n') && bLastWasCR)
            {
                bLastWasCR = 0;
                continue;
            }*/
    
            //
            // See if a newline or escape character was received.
            //
            //if((cChar == '\r') || (cChar == '\n') || (cChar == 0x1b))
    		if(cChar == 0x12) 
            {
                //
                // If the character is a CR, then it may be followed by a LF which
                // should be paired with the CR.  So remember that a CR was
                // received.
                //
                if(cChar == 0xAA)//0x12)//'\r')
                {
                    bLastWasCR = 1;
                }
    
                //
                // Stop processing the input and end the line.
                //
                break;
            }
    
            //
            // Process the received character as long as we are not at the end of
            // the buffer.  If the end of the buffer has been reached then all
            // additional characters are ignored until a newline is received.
            //
            if(ulCount < ulLen)
            {
                //
                // Store the character in the caller supplied buffer.
                //
                pcBuf[ulCount] = cChar;
    
                //
                // Increment the count of characters received.
                //
                ulCount++;
    
                //
                // Reflect the character back to the user.
                //
                //MAP_UARTCharPut(g_ulBase, cChar);
            }
        }
    
        //
        // Add a null termination to the string.
        //
        pcBuf[ulCount] = 0;
    
        //
        // Send a CRLF pair to the terminal to end the line.
        //
        //UARTwrite("\r\n", 2);
    
        //
        // Return the count of chars in the buffer, not counting the trailing 0.
        //
        return(ulCount);
    #endif
    }
    
    //*****************************************************************************
    //
    //! Read a single character from the UART, blocking if necessary.
    //!
    //! This function will receive a single character from the UART and store it at
    //! the supplied address.
    //!
    //! In both buffered and unbuffered modes, this function will block until a
    //! character is received.  If non-blocking operation is required in buffered
    //! mode, a call to UARTRxAvail() may be made to determine whether any
    //! characters are currently available for reading.
    //!
    //! \return Returns the character read.
    //
    //*****************************************************************************
    unsigned char
    UARTgetc(void)
    {
    #ifdef UART_BUFFERED
        unsigned char cChar;
    
        //
        // Wait for a character to be received.
        //
        while(RX_BUFFER_EMPTY)
        {
    	//	buz_on();
            //
            // Block waiting for a character to be received (if the buffer is
            // currently empty).
            //
        }
    
        //
        // Read a character from the buffer.
        //
    
        cChar = g_pcUARTRxBuffer[g_ulUARTRxReadIndex];
        ADVANCE_RX_BUFFER_INDEX(g_ulUARTRxReadIndex);
    
        //
        // Return the character to the caller.
        //
        return(cChar);
    #else
        //
        // Block until a character is received by the UART then return it to
        // the caller.
        //
    //	buz_on();  return(1);
        return(MAP_UARTCharGet(g_ulBase));
    #endif
    }
    
    //*****************************************************************************
    //
    //! A simple UART based printf function supporting \%c, \%d, \%p, \%s, \%u,
    //! \%x, and \%X.
    //!
    //! \param pcString is the format string.
    //! \param ... are the optional arguments, which depend on the contents of the
    //! format string.
    //!
    //! This function is very similar to the C library <tt>fprintf()</tt> function.
    //! All of its output will be sent to the UART.  Only the following formatting
    //! characters are supported:
    //!
    //! - \%c to print a character
    //! - \%d to print a decimal value
    //! - \%s to print a string
    //! - \%u to print an unsigned decimal value
    //! - \%x to print a hexadecimal value using lower case letters
    //! - \%X to print a hexadecimal value using lower case letters (not upper case
    //! letters as would typically be used)
    //! - \%p to print a pointer as a hexadecimal value
    //! - \%\% to print out a \% character
    //!
    //! For \%s, \%d, \%u, \%p, \%x, and \%X, an optional number may reside
    //! between the \% and the format character, which specifies the minimum number
    //! of characters to use for that value; if preceded by a 0 then the extra
    //! characters will be filled with zeros instead of spaces.  For example,
    //! ``\%8d'' will use eight characters to print the decimal value with spaces
    //! added to reach eight; ``\%08d'' will use eight characters as well but will
    //! add zeroes instead of spaces.
    //!
    //! The type of the arguments after \e pcString must match the requirements of
    //! the format string.  For example, if an integer was passed where a string
    //! was expected, an error of some kind will most likely occur.
    //!
    //! \return None.
    //
    //*****************************************************************************
    void
    UARTprintf(const char *pcString, ...)
    {
        unsigned long ulIdx, ulValue, ulPos, ulCount, ulBase, ulNeg;
        char *pcStr, pcBuf[16], cFill;
        va_list vaArgP;
    
        //
        // Check the arguments.
        //
        ASSERT(pcString != 0);
    
        //
        // Start the varargs processing.
        //
        va_start(vaArgP, pcString);
    
        //
        // Loop while there are more characters in the string.
        //
        while(*pcString)
        {
            //
            // Find the first non-% character, or the end of the string.
            //
            for(ulIdx = 0; (pcString[ulIdx] != '%') && (pcString[ulIdx] != '\0');
                ulIdx++)
            {
            }
    
            //
            // Write this portion of the string.
            //
            UARTwrite(pcString, ulIdx);
    
            //
            // Skip the portion of the string that was written.
            //
            pcString += ulIdx;
    
            //
            // See if the next character is a %.
            //
            if(*pcString == '%')
            {
                //
                // Skip the %.
                //
                pcString++;
    
                //
                // Set the digit count to zero, and the fill character to space
                // (i.e. to the defaults).
                //
                ulCount = 0;
                cFill = ' ';
    
                //
                // It may be necessary to get back here to process more characters.
                // Goto's aren't pretty, but effective.  I feel extremely dirty for
                // using not one but two of the beasts.
                //
    again:
    
                //
                // Determine how to handle the next character.
                //
                switch(*pcString++)
                {
                    //
                    // Handle the digit characters.
                    //
                    case '0':
                    case '1':
                    case '2':
                    case '3':
                    case '4':
                    case '5':
                    case '6':
                    case '7':
                    case '8':
                    case '9':
                    {
                        //
                        // If this is a zero, and it is the first digit, then the
                        // fill character is a zero instead of a space.
                        //
                        if((pcString[-1] == '0') && (ulCount == 0))
                        {
                            cFill = '0';
                        }
    
                        //
                        // Update the digit count.
                        //
                        ulCount *= 10;
                        ulCount += pcString[-1] - '0';
    
                        //
                        // Get the next character.
                        //
                        goto again;
                    }
    
                    //
                    // Handle the %c command.
                    //
                    case 'c':
                    {
                        //
                        // Get the value from the varargs.
                        //
                        ulValue = va_arg(vaArgP, unsigned long);
    
                        //
                        // Print out the character.
                        //
                        UARTwrite((char *)&ulValue, 1);
    
                        //
                        // This command has been handled.
                        //
                        break;
                    }
    
                    //
                    // Handle the %d command.
                    //
                    case 'd':
                    {
                        //
                        // Get the value from the varargs.
                        //
                        ulValue = va_arg(vaArgP, unsigned long);
    
                        //
                        // Reset the buffer position.
                        //
                        ulPos = 0;
    
                        //
                        // If the value is negative, make it positive and indicate
                        // that a minus sign is needed.
                        //
                        if((long)ulValue < 0)
                        {
                            //
                            // Make the value positive.
                            //
                            ulValue = -(long)ulValue;
    
                            //
                            // Indicate that the value is negative.
                            //
                            ulNeg = 1;
                        }
                        else
                        {
                            //
                            // Indicate that the value is positive so that a minus
                            // sign isn't inserted.
                            //
                            ulNeg = 0;
                        }
    
                        //
                        // Set the base to 10.
                        //
                        ulBase = 10;
    
                        //
                        // Convert the value to ASCII.
                        //
                        goto convert;
                    }
    
                    //
                    // Handle the %s command.
                    //
                    case 's':
                    {
                        //
                        // Get the string pointer from the varargs.
                        //
                        pcStr = va_arg(vaArgP, char *);
    
                        //
                        // Determine the length of the string.
                        //
                        for(ulIdx = 0; pcStr[ulIdx] != '\0'; ulIdx++)
                        {
                        }
    
                        //
                        // Write the string.
                        //
                        UARTwrite(pcStr, ulIdx);
    
                        //
                        // Write any required padding spaces
                        //
                        if(ulCount > ulIdx)
                        {
                            ulCount -= ulIdx;
                            while(ulCount--)
                            {
                                UARTwrite(" ", 1);
                            }
                        }
                        //
                        // This command has been handled.
                        //
                        break;
                    }
    
                    //
                    // Handle the %u command.
                    //
                    case 'u':
                    {
                        //
                        // Get the value from the varargs.
                        //
                        ulValue = va_arg(vaArgP, unsigned long);
    
                        //
                        // Reset the buffer position.
                        //
                        ulPos = 0;
    
                        //
                        // Set the base to 10.
                        //
                        ulBase = 10;
    
                        //
                        // Indicate that the value is positive so that a minus sign
                        // isn't inserted.
                        //
                        ulNeg = 0;
    
                        //
                        // Convert the value to ASCII.
                        //
                        goto convert;
                    }
    
                    //
                    // Handle the %x and %X commands.  Note that they are treated
                    // identically; i.e. %X will use lower case letters for a-f
                    // instead of the upper case letters is should use.  We also
                    // alias %p to %x.
                    //
                    case 'x':
                    case 'X':
                    case 'p':
                    {
                        //
                        // Get the value from the varargs.
                        //
                        ulValue = va_arg(vaArgP, unsigned long);
    
                        //
                        // Reset the buffer position.
                        //
                        ulPos = 0;
    
                        //
                        // Set the base to 16.
                        //
                        ulBase = 16;
    
                        //
                        // Indicate that the value is positive so that a minus sign
                        // isn't inserted.
                        //
                        ulNeg = 0;
    
                        //
                        // Determine the number of digits in the string version of
                        // the value.
                        //
    convert:
                        for(ulIdx = 1;
                            (((ulIdx * ulBase) <= ulValue) &&
                             (((ulIdx * ulBase) / ulBase) == ulIdx));
                            ulIdx *= ulBase, ulCount--)
                        {
                        }
    
                        //
                        // If the value is negative, reduce the count of padding
                        // characters needed.
                        //
                        if(ulNeg)
                        {
                            ulCount--;
                        }
    
                        //
                        // If the value is negative and the value is padded with
                        // zeros, then place the minus sign before the padding.
                        //
                        if(ulNeg && (cFill == '0'))
                        {
                            //
                            // Place the minus sign in the output buffer.
                            //
                            pcBuf[ulPos++] = '-';
    
                            //
                            // The minus sign has been placed, so turn off the
                            // negative flag.
                            //
                            ulNeg = 0;
                        }
    
                        //
                        // Provide additional padding at the beginning of the
                        // string conversion if needed.
                        //
                        if((ulCount > 1) && (ulCount < 16))
                        {
                            for(ulCount--; ulCount; ulCount--)
                            {
                                pcBuf[ulPos++] = cFill;
                            }
                        }
    
                        //
                        // If the value is negative, then place the minus sign
                        // before the number.
                        //
                        if(ulNeg)
                        {
                            //
                            // Place the minus sign in the output buffer.
                            //
                            pcBuf[ulPos++] = '-';
                        }
    
                        //
                        // Convert the value into a string.
                        //
                        for(; ulIdx; ulIdx /= ulBase)
                        {
                            pcBuf[ulPos++] = g_pcHex[(ulValue / ulIdx) % ulBase];
                        }
    
                        //
                        // Write the string.
                        //
                        UARTwrite(pcBuf, ulPos);
    
                        //
                        // This command has been handled.
                        //
                        break;
                    }
    
                    //
                    // Handle the %% command.
                    //
                    case '%':
                    {
                        //
                        // Simply write a single %.
                        //
                        UARTwrite(pcString - 1, 1);
    
                        //
                        // This command has been handled.
                        //
                        break;
                    }
    
                    //
                    // Handle all other commands.
                    //
                    default:
                    {
                        //
                        // Indicate an error.
                        //
                        UARTwrite("ERROR", 5);
    
                        //
                        // This command has been handled.
                        //
                        break;
                    }
                }
            }
        }
    
        //
        // End the varargs processing.
        //
        va_end(vaArgP);
    }
    
    //*****************************************************************************
    //
    //! Returns the number of bytes available in the receive buffer.
    //!
    //! This function, available only when the module is built to operate in
    //! buffered mode using \b UART_BUFFERED, may be used to determine the number
    //! of bytes of data currently available in the receive buffer.
    //!
    //! \return Returns the number of available bytes.
    //
    //*****************************************************************************
    #if defined(UART_BUFFERED) || defined(DOXYGEN)
    int
    UARTRxBytesAvail(void)
    {
        return(RX_BUFFER_USED);
    }
    #endif
    
    #if defined(UART_BUFFERED) || defined(DOXYGEN)
    //*****************************************************************************
    //
    //! Returns the number of bytes free in the transmit buffer.
    //!
    //! This function, available only when the module is built to operate in
    //! buffered mode using \b UART_BUFFERED, may be used to determine the amount
    //! of space currently available in the transmit buffer.
    //!
    //! \return Returns the number of free bytes.
    //
    //*****************************************************************************
    int
    UARTTxBytesFree(void)
    {
        return(TX_BUFFER_FREE);
    }
    #endif
    
    //*****************************************************************************
    //
    //! Looks ahead in the receive buffer for a particular character.
    //!
    //! \param ucChar is the character that is to be searched for.
    //!
    //! This function, available only when the module is built to operate in
    //! buffered mode using \b UART_BUFFERED, may be used to look ahead in the
    //! receive buffer for a particular character and report its position if found.
    //! It is typically used to determine whether a complete line of user input is
    //! available, in which case ucChar should be set to CR ('\\r') which is used
    //! as the line end marker in the receive buffer.
    //!
    //! \return Returns -1 to indicate that the requested character does not exist
    //! in the receive buffer.  Returns a non-negative number if the character was
    //! found in which case the value represents the position of the first instance
    //! of \e ucChar relative to the receive buffer read pointer.
    //
    //*****************************************************************************
    #if defined(UART_BUFFERED) || defined(DOXYGEN)
    int
    UARTPeek(unsigned char ucChar)
    {
        int iCount;
        int iAvail;
        unsigned long ulReadIndex;
    
        //
        // How many characters are there in the receive buffer?
        //
        iAvail = (int)RX_BUFFER_USED;
        ulReadIndex = g_ulUARTRxReadIndex;
    
        //
        // Check all the unread characters looking for the one passed.
        //
        for(iCount = 0; iCount < iAvail; iCount++)
        {
            if(g_pcUARTRxBuffer[ulReadIndex] == ucChar)
            {
                //
                // We found it so return the index
                //
                return(iCount);
            }
            else
            {
                //
                // This one didn't match so move on to the next character.
                //
                ADVANCE_RX_BUFFER_INDEX(ulReadIndex);
            }
        }
    
        //
        // If we drop out of the loop, we didn't find the character in the receive
        // buffer.
        //
        return(-1);
    }
    #endif
    
    //*****************************************************************************
    //
    //! Flushes the receive buffer.
    //!
    //! This function, available only when the module is built to operate in
    //! buffered mode using \b UART_BUFFERED, may be used to discard any data
    //! received from the UART but not yet read using UARTgets().
    //!
    //! \return None.
    //
    //*****************************************************************************
    #if defined(UART_BUFFERED) || defined(DOXYGEN)
    void
    UARTFlushRx(void)
    {
        unsigned long ulInt;
    
        //
        // Temporarily turn off interrupts.
        //
        ulInt = IntMasterDisable();
    
        //
        // Flush the receive buffer.
        //
        g_ulUARTRxReadIndex = 0;
        g_ulUARTRxWriteIndex = 0;
    
        //
        // If interrupts were enabled when we turned them off, turn them
        // back on again.
        //
        if(!ulInt)
        {
            IntMasterEnable();
        }
    }
    #endif
    
    //*****************************************************************************
    //
    //! Flushes the transmit buffer.
    //!
    //! \param bDiscard indicates whether any remaining data in the buffer should
    //! be discarded (\b true) or transmitted (\b false).
    //!
    //! This function, available only when the module is built to operate in
    //! buffered mode using \b UART_BUFFERED, may be used to flush the transmit
    //! buffer, either discarding or transmitting any data received via calls to
    //! UARTprintf() that is waiting to be transmitted.  On return, the transmit
    //! buffer will be empty.
    //!
    //! \return None.
    //
    //*****************************************************************************
    #if defined(UART_BUFFERED) || defined(DOXYGEN)
    void
    UARTFlushTx(tBoolean bDiscard)
    {
        unsigned long ulInt;
    
        //
        // Should the remaining data be discarded or transmitted?
        //
        if(bDiscard)
        {
            //
            // The remaining data should be discarded, so temporarily turn off
            // interrupts.
            //
            ulInt = IntMasterDisable();
    
            //
            // Flush the transmit buffer.
            //
            g_ulUARTTxReadIndex = 0;
            g_ulUARTTxWriteIndex = 0;
    
            //
            // If interrupts were enabled when we turned them off, turn them
            // back on again.
            //
            if(!ulInt)
            {
                IntMasterEnable();
            }
        }
        else
        {
            //
            // Wait for all remaining data to be transmitted before returning.
            //
            while(!TX_BUFFER_EMPTY)
            {
            }
        }
    }
    #endif
    
    //*****************************************************************************
    //
    //! Enables or disables echoing of received characters to the transmitter.
    //!
    //! \param bEnable must be set to \b true to enable echo or \b false to
    //! disable it.
    //!
    //! This function, available only when the module is built to operate in
    //! buffered mode using \b UART_BUFFERED, may be used to control whether or not
    //! received characters are automatically echoed back to the transmitter.  By
    //! default, echo is enabled and this is typically the desired behavior if
    //! the module is being used to support a serial command line.  In applications
    //! where this module is being used to provide a convenient, buffered serial
    //! interface over which application-specific binary protocols are being run,
    //! however, echo may be undesirable and this function can be used to disable
    //! it.
    //!
    //! \return None.
    //
    //*****************************************************************************
    #if defined(UART_BUFFERED) || defined(DOXYGEN)
    void
    UARTEchoSet(tBoolean bEnable)
    {
        g_bDisableEcho = !bEnable;
    }
    #endif
    
    //*****************************************************************************
    //
    //! Handles UART interrupts.
    //!
    //! This function handles interrupts from the UART.  It will copy data from the
    //! transmit buffer to the UART transmit FIFO if space is available, and it
    //! will copy data from the UART receive FIFO to the receive buffer if data is
    //! available.
    //!
    //! \return None.
    //
    //*****************************************************************************
    #if defined(UART_BUFFERED) || defined(DOXYGEN)
    void
    UARTStdioIntHandler(void)
    {
        unsigned long ulInts;
        char cChar;
        long lChar;
        static tBoolean bLastWasCR = false;
    //	 signed int received_data;
        
    	receive_flag=0;interrupt_counter=0;
    	
    	//
        // Get and clear the current interrupt source(s)
        //
        ulInts = MAP_UARTIntStatus(g_ulBase, true);
        MAP_UARTIntClear(g_ulBase, ulInts);
    
        //
        // Are we being interrupted because the TX FIFO has space available?
        //
        if(ulInts & UART_INT_TX)
        {
            //
            // Move as many bytes as we can into the transmit FIFO.
            //
            UARTPrimeTransmit(g_ulBase);
    
            //
            // If the output buffer is empty, turn off the transmit interrupt.
            //
            if(TX_BUFFER_EMPTY)
            {
                MAP_UARTIntDisable(g_ulBase, UART_INT_TX);
            }
        }
    
        //
        // Are we being interrupted due to a received character?
        //
        if(ulInts & (UART_INT_RX )|(UART_INT_RT))
        {
            //
            // Get all the available characters from the UART.
            //
            while(MAP_UARTCharsAvail(g_ulBase))
            {
                //
                // Read a character
                //
                lChar = MAP_UARTCharGetNonBlocking(g_ulBase);
                cChar = (unsigned char)(lChar & 0xFF);
    			//	buz_on();
                //
                // If echo is disabled, we skip the various text filtering
                // operations that would typically be required when supporting a
                // command line.
                //
                if(!g_bDisableEcho)
                {
                    //
                    // Handle backspace by erasing the last character in the buffer.
                    //
                    if(cChar == '\b')
                    {
                        //
                        // If there are any characters already in the buffer, then
                        // delete the last.
                        //
                        if(!RX_BUFFER_EMPTY)
                        {
                            //
                            // Rub out the previous character on the users terminal.
                            //
                            UARTwrite("\b \b", 3);
    
                            //
                            // Decrement the number of characters in the buffer.
                            //
                            if(g_ulUARTRxWriteIndex == 0)
                            {
                                g_ulUARTRxWriteIndex = UART_RX_BUFFER_SIZE - 1;
                            }
                            else
                            {
                                g_ulUARTRxWriteIndex--;
                            }
                        }
    
                        //
                        // Skip ahead to read the next character.
                        //
                        continue;
                    }
    
                    //
                    // If this character is LF and last was CR, then just gobble up
                    // the character since we already echoed the previous CR and we
                    // don't want to store 2 characters in the buffer if we don't
                    // need to.
                    //
                    if((cChar == '\n') && bLastWasCR)
                    {
                        bLastWasCR = false;
                        continue;
                    }
    
                    //
                    // See if a newline or escape character was received.
                    //
                    if((cChar == '\r') || (cChar == '\n') || (cChar == 0x1b))
                    {
                        //
                        // If the character is a CR, then it may be followed by an
                        // LF which should be paired with the CR.  So remember that
                        // a CR was received.
                        //
                        if(cChar == '\r')
                        {
                            bLastWasCR = 1;
                        }
    
                        //
                        // Regardless of the line termination character received,
                        // put a CR in the receive buffer as a marker telling
                        // UARTgets() where the line ends.  We also send an
                        // additional LF to ensure that the local terminal echo
                        // receives both CR and LF.
                        //
                        cChar = '\r';
                        UARTwrite("\n", 1);
                    }
                }
    
                //
                // If there is space in the receive buffer, put the character
                // there, otherwise throw it away.
                //
                if(!RX_BUFFER_FULL)
                {
    				//
                    // Store the new character in the receive buffer
                    //
                   //	received_data = (unsigned char)(lChar & 0xFF);
                    
    //				if(cChar == 0x3A)
    //				{
    //					 receive_flag=1;
    //				}
    //	        	else if(cChar != 0x3A)
    //			    {
    //					interrupt_counter++;
    //				}
    //				if(receive_flag )//== 1)
    //				{
    					g_pcUARTRxBuffer[g_ulUARTRxWriteIndex] =
                        (unsigned char)(lChar & 0xFF);
                    ADVANCE_RX_BUFFER_INDEX(g_ulUARTRxWriteIndex);
    
    //					g_pcUARTRxBuffer[g_ulUARTRxWriteIndex] = cChar ;
    //			    	ADVANCE_RX_BUFFER_INDEX(g_ulUARTRxWriteIndex);
    //				}
                    //
                    // If echo is enabled, write the character to the transmit
                    // buffer so that the user gets some immediate feedback.
                    //
                    if(!g_bDisableEcho)
                    {
                        UARTwrite(&cChar, 1);
                   }
                }
            }
    
            //
            // If we wrote anything to the transmit buffer, make sure it actually
            // gets transmitted.
            //
            UARTPrimeTransmit(g_ulBase);
            MAP_UARTIntEnable(g_ulBase, UART_INT_TX);
        }
    }
    #endif
    
    //*****************************************************************************
    //
    // Close the Doxygen group.
    //! @}
    //
    //*****************************************************************************
    
    3465.main.c
    int
    main(void)
    {
        FRESULT FileResult;
    
        FIL  fdst; 
        FRESULT res;         // FatFs function common result code
        WORD  bw;//br,         // File R/W count
    
        char FileName[15];
        unsigned char filemsb,filelsb;
        //
        // Initially wait for device connection.
    
    	//display_saved_record_123(0x01);
        //
        g_eState = STATE_NO_DEVICE;
    
    
        //
        // Set the clocking to run directly from the crystal.
        //
     
        SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_8MHZ);
    
         SysCtlBrownOutConfigSet(SYSCTL_BOR_RESET,1000);	// THIS FUNCTION IS USED TO INTERNAL RESET TO CONTROLLER TO SOLVED         THE FLASH CURREPT PROBLEM 
    
    
        //
        // Enable Clocking to the USB controller.
        //
        SysCtlPeripheralEnable(SYSCTL_PERIPH_USB0);
    
        //
        // Enable the peripherals used by this example.
        //
        SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);		 
        
           SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    
        //
        // Set the USB pins to be controlled by the USB controller.
        //
             
        init_display();
    	
        init_adc_and_keyboard();
    	
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
    
        GPIOPinTypeUSBDigital(GPIO_PORTC_BASE, GPIO_PIN_5 | GPIO_PIN_6);
    
        //
        // The LM3S3748 board uses a USB mux that must be switched to use the
        // host connecter and not the device connecter.
        //
    
        //
        // Turn on USB Phy clock.
        //
        SysCtlUSBPLLEnable();
    
        //
        // Set the system tick to fire 100 times per second.
        //
        SysTickPeriodSet(SysCtlClockGet()/100);
        SysTickIntEnable();
        SysTickEnable();
    
        //
        // Enable the uDMA controller and set up the control table base.
        //
        SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA);
        uDMAEnable();
        uDMAControlBaseSet(g_sDMAControlTable);
    	
    	
        //
        // Set GPIO A0 and A1 as UART pins.
        //
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);//added on 30/04/13 by ganesh sir			
    
        GPIOPinTypeUART(GPIO_PORTA_BASE,GPIO_PIN_0 | GPIO_PIN_1); //u0tx and u0rx initilized
    
        UARTStdioInit(0); // @9600 chanes made in c:\stellaris001\uartstdio.c
    
    		display_buffer[0]= 0xEB;
    		display_buffer[1]= 0x81;			
    	  	display_buffer[2]= 0xDA;			
    		display_buffer[3]= 0xD3;	    
    		display_buffer[4]= 0xB1;		
    						
    		display_buffer[5]= 0x73;
    
    		display_buffer[6]= 0x00;
    		display_buffer[7]= 0x00;			
    	  	display_buffer[8]= 0x00;			
    
    		display_buffer[9]= 0x00;	    
    		display_buffer[10]= 0x00;						
    		display_buffer[11]= 0x00;
    
    		display_buffer[12]= 0x00;
    		display_buffer[13]= 0x00;			
    	  	display_buffer[14]= 0x00;			
    		display_buffer[15]= 0x78;	    
    		
    		display_serial();
    	
        //
        // Initialize the display driver.
        //
     	display_no_device();
     
        //
        // Register the host class drivers.
        //
        USBHCDRegisterDrivers(0, g_ppHostClassDrivers, g_ulNumHostClassDrivers);
    
        //
        // Open an instance of the mass storage class driver.
        //
        g_ulMSCInstance = USBHMSCDriveOpen(0, MSCCallback);
    
        //
        // Initialize the power configuration. This sets the power enable signal
        // to be active high and does not enable the power fault.
        //
        USBHCDPowerConfigInit(0, USB_HOST_PWREN_HIGH);
    
        //
        // Initialize the host controller.
        //
        USBHCDInit(0, g_pHCDPool, HCD_MEMORY_SIZE);
    
        //
        // Current directory is "/"
        //
        g_DirData.szPWD[0] = '/';
        g_DirData.szPWD[1] = 0;
    
        //
        // Initialize the file system.
        //
       	FileInit();
       	IntMasterDisable();
    	init_clock();
    	IntMasterEnable();
    	NewFlashProtect_using_user_dbg();
    }
    
    
    7776.transmitter_code.c
    char array_data[]={'1','a','2','b','3','c','4','d','5','e','6','f','7','g','8','h','9','i','0','j','X','Y','Z',
     					'1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','X','Y','Z',0x0d,0xff};
    
    
    
    
    void initialization()                        //this function is called on key press
    { 	
       	send_msg(array_data);
    	delay_cnt(400000);delay_cnt(400000);
    }
    
    
    void send_msg(char * ptr)
    {
    	unsigned char j,asc_data;
    	
    	for(j=0;j<=0x64;j++)
    	{
    		asc_data=ptr[j];
    		if(asc_data == 0xff)
    			return;
    	   
    		while(!MAP_UARTCharPutNonBlocking(UART0_BASE,asc_data))
    		{ }
      	}
    
    }
    6177.receiver.c
    unsigned long adc_steps;
    
    Below code is called on a key pressed and is used only to display the received characters,as to check how many characters has been accepted by UART.
    
    code:  
    	MAP_UARTIntDisable(UART0_BASE, 0xFFFFFFFF);                        //while displaying UART interrupt is disabled
    		 
    	adc_steps=0;
    	for(i=0;i<=250;i++) //	 interrupt_counter
    	{
    		adc_steps=g_pcUARTRxBuffer[i];
    		display_temp_variable();													display_serial();						
    		delay_cnt(400000);delay_cnt(400000);delay_cnt(40000);		
    		delay_cnt(400000);delay_cnt(400000);delay_cnt(40000);						
    		delay_cnt(400000);delay_cnt(400000);delay_cnt(40000);
    		delay_cnt(400000);delay_cnt(400000);delay_cnt(40000);
    	}
    	
    	UARTFlushRx();				
    	MAP_UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);       //after displaying UART interrupt is enabled again

  • Uptal,

    Yes, the buffer size is also important - you did not posted any info about, but of coarse should be bigger than 20 bytes. 

    Also, you modified a lot the routines provided, maybe it will be useful to explain why you tried to hunt the 0x3A - if this is a kind of starting mark of a message, then the routines may need to be modified a lot (this was in .rar archive..). 

    Petrei

  • Hi,

    Thanks for your reply.

    Can you please share the procedure to increase the buffer size ?

    Also share sample code to implement same ,if you have any.

  • Hi,

    The buffer size is specified in uartstdio.h file, but it is taken into account if there is a predefined symbol UART_BUFFERED - this can be done by adding this symbol at the compiler settings -> predefined symbols (I do not have a CCS open to tell you precisely path to this, but is the same place where you defined DEBUG).

    As for hunting 0x3A - you did not answer affirmative to this ...

    Also you played a lot with disabling UART interrupts, avoid this, can cause problems.

    Petrei

  • Hi pat,

    Thanks for the reply.

    I had increased the buffere size in uartstdio.h .also i had changed the compiler settings accodingly for kiel IDE.

    PF attached details. 6114.uartstdio.h

  • Hi,

    Also for 0x3A  is hex value of colon : i am saving the characters after : (colon) 

  • Hi,

    What are the results of increasing buffers size? Still with problems or you can receive more than 16 characters?

    I understand  you need to hunt the 0x3A character - unfortunately I have no code example  based on uartstdio.c file - I made my own, (for my application, which is not GSM). 

    You may google search for similar code made by others for GSM modules - the arduino is the most appropriate for that or make your own routine to hunt that character.

    One possible solution is to use a two steps approach: 

    a) step 1: receive a character and check it for ":". If equal, switch to step 2, otherwise get out of interrupts routine;

    b) step2: receive a character and if it is not the end of message, save it in a buffer and increase the buffer index for the next location. If it is the end of message (take care - could be two characters, CR and LF), then mark the end of received string with 0x0, flag for a valid message, to be processed further, and switch to step 1. 

    You may disable UART FIFO with this approach  - nothing is lost while the interrupt routine is small. If you adopt this approach, take care - your Stellarisware version is very old one, so enabling UART enables also the FIFO, so you need to disable the FIFO after enabling the UART.  See/check the file driverlib/uart.c

    Of coarse, you may try other approaches, depends on the requirements of your module.

    Petrei

  • hi ,

    no ,irrespective of increasing buffer size ,i am unable to receive more characters. 

    i found one unique thing , i am able to receive 17 values maximum                       utpal12345abcdefg . irrespective of the buffer size i.e any size greater than 17  able to receive 17 characters maximum.

    So kindly advice. & parallely i will try your suggestions to test using your solutions.

  • Hi Uptal, the best way to implement the uart is to have the interrupt service unload the UART RX data into a fifo buffer. Then your main loop code can deal with unloading and parsing the fifo without interferring with the UART at all. You can do the TX in a similar fashion. Unfortunately I can't send you my code as I am bound by company directives not to disclose code. I would definitely update to the latest Stellarisware and study the examples in there. Good Luck. Richard.

  • Hi,

    I had tested the UART echo code on LM3S8962 evm using CCSv5.2.

    I am able to send the string ,but the string i am receiving 

    UART is showing random behavior.

     Random numbers of characters are accepted by UART, every time they repeat the same test.

    For eg: Sometimes they receive 16 characters, sometimes 18, sometimes and 30, while some other times 36 characters.

    I am pasting the .c file for your reference.

    Kindly suggest me the changes.

     

    //*****************************************************************************
    //
    // uart_echo.c - Example for reading data from and writing data to the UART in
    // an interrupt driven fashion.
    //
    // Copyright (c) 2005-2012 Texas Instruments Incorporated. All rights reserved.
    // Software License Agreement
    //
    // Texas Instruments (TI) is supplying this software for use solely and
    // exclusively on TI's microcontroller products. The software is owned by
    // TI and/or its suppliers, and is protected under applicable copyright
    // laws. You may not combine this software with "viral" open-source
    // software in order to form a larger program.
    //
    // THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
    // NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
    // NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    // A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
    // CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
    // DAMAGES, FOR ANY REASON WHATSOEVER.
    //
    // This is part of revision 9453 of the EK-LM3S8962 Firmware Package.
    //
    //*****************************************************************************

    #include "inc/hw_ints.h"
    #include "inc/hw_memmap.h"
    #include "inc/hw_types.h"
    #include "driverlib/debug.h"
    #include "driverlib/gpio.h"
    #include "driverlib/interrupt.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/uart.h"
    #include "drivers/rit128x96x4.h"

    char array[25];
    int arrayptr =0;

    //*****************************************************************************
    //
    //! \addtogroup example_list
    //! <h1>UART Echo (uart_echo)</h1>
    //!
    //! This example application utilizes the UART to echo text. The first UART
    //! (connected to the FTDI virtual serial port on the evaluation board) will be
    //! configured in 115,200 baud, 8-n-1 mode. All characters received on the
    //! UART are transmitted back to the UART.
    //
    //*****************************************************************************

    //*****************************************************************************
    //
    // The error routine that is called if the driver library encounters an error.
    //
    //*****************************************************************************
    #ifdef DEBUG
    void
    __error__(char *pcFilename, unsigned long ulLine)
    {
    }
    #endif

    //*****************************************************************************
    //
    // The UART interrupt handler.
    //
    //*****************************************************************************
    void
    UARTIntHandler(void)
    {
    unsigned long ulStatus;

    //
    // Get the interrrupt status.
    //
    ulStatus = UARTIntStatus(UART0_BASE, true);

    //
    // Clear the asserted interrupts.
    //
    UARTIntClear(UART0_BASE, ulStatus);

    //
    // Loop while there are characters in the receive FIFO.
    //
    while(UARTCharsAvail(UART0_BASE))
    {
    //
    array[arrayptr]= (UARTCharGetNonBlocking(UART0_BASE));
    // Read the next character from the UART and write it back to the UART.
    //
    // UARTCharPutNonBlocking(UART0_BASE, UARTCharGetNonBlocking(UART0_BASE));
    UARTCharPutNonBlocking(UART0_BASE, array[arrayptr]);
    arrayptr++;

    if(arrayptr > 25)
    {
    arrayptr =0;
    }
    }
    }

    //*****************************************************************************
    //
    // Send a string to the UART.
    //
    //*****************************************************************************
    void
    UARTSend(const unsigned char *pucBuffer, unsigned long ulCount)
    {
    //
    // Loop while there are more characters to send.
    //
    while(ulCount--)
    {
    //
    // Write the next character to the UART.
    //
    UARTCharPutNonBlocking(UART0_BASE, *pucBuffer++);
    }
    }

    //*****************************************************************************
    //
    // This example demonstrates how to send a string of data to the UART.
    //
    //*****************************************************************************
    int
    main(void)
    {
    //
    // Set the clocking to run directly from the crystal.
    //
    SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
    SYSCTL_XTAL_8MHZ);

    //
    // Initialize the OLED display and write status.
    //
    RIT128x96x4Init(1000000);
    RIT128x96x4StringDraw("UART Echo", 36, 0, 15);
    RIT128x96x4StringDraw("Port: Uart 0", 12, 16, 15);
    RIT128x96x4StringDraw("Baud: 115,200 bps", 12, 24, 15);
    RIT128x96x4StringDraw("Data: 8 Bit", 12, 32, 15);
    RIT128x96x4StringDraw("Parity: None", 12, 40, 15);
    RIT128x96x4StringDraw("Stop: 1 Bit", 12, 48, 15);

    //
    // Enable the peripherals used by this example.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

    //
    // Enable processor interrupts.
    //
    IntMasterEnable();

    //
    // Set GPIO A0 and A1 as UART pins.
    //
    GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    //
    // Configure the UART for 115,200, 8-N-1 operation.
    //
    UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,
    (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
    UART_CONFIG_PAR_NONE));

    //
    // Enable the UART interrupt.
    //
    IntEnable(INT_UART0);
    UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);

    //
    // Prompt for text to be entered.
    //
    UARTSend((unsigned char *)"Enter text: ", 12);

    //
    // Loop forever echoing data through the UART.
    //
    while(1)
    {
    }
    }

     

  • Hi,

    Please reply.