This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

UART help(LPC1114)

Is it possible for me to send a C file over a UART connection to an LPC1114 mcu? The C file has configurations for the mcu, if it is possible how can I do so using C# in Visual Studio.

Parents Reply Children
  • Is it possible to send C text that can trigger functions within the firmware?

  • Your post implies that you expect to have the target MCU (the LPC1114) implement code from a .c file sent over the UART.

    This won't happen.

    If, on the otherhand, the code within the MCU expects to have operating parameters sent through the UART, then it is possible to do that.

    This relies on the firmware already in the target MCU to accept this data (not executable ".C" code) and act on that information.

    Since you said 'send C text/file' it is clear that you don't know enough about embedded software, and therefore I answered 'No.'

    What you need to do is modify the LPC1114 MCU firmware to accept serial parameters over the UART. The new software in the LPC1114 could then interpret the data to implement the 'triggering of functions.' Which means that you would need to be able to write embedded software.

    --Cpt. Vince Foster
    2nd Cannon Place
    Fort Marcy Park, VA

  • So in the mcu itself I have written code that does expect to be triggered by incoming data, however I'm new to sending data over a serial port. So far I have only been able to send strings and it has not provoked any reaction within the mcu.

  • That is a good thing. I'm glad you are able to write/modify code with the LPC1114.

    There are too many forum contributors that have zero clue on how embedded systems work.

    Can you provide a code snippet that represents the data being sent, and how your firmware is processing it?

    --Cpt. Vince Foster
    2nd Cannon Place
    Fort Marcy Park, VA

  • So heres the interrupt on the firmware side

    void UART_IRQHandler(void) {
            static NetworkLayerState networkState = Network_Idle;
            unsigned int interruptId = LPC_UART->IIR;
    
            while((interruptId & 1) == 0)
            {
                    switch((interruptId >> 1) & 0x07)
                    {
                            case 0x02: //Receive Data Available
                            case 0x06: //Character time-out indicator (buffer flush)
                                    networkState = NetworkStateMachine(LPC_UART->RBR & 0xFF, networkState);
                                    break;
    
                            case 0x03: //Receive Line Status interrupt
                                    break; //Not handling frame errors
                    }
    
                    interruptId = LPC_UART->IIR;
            }
    }
    

    And now I want to send for example

    WriteRegisterOpt(8, 1, 0x03249249, 0);
    


    WriteRegisterOpt is a function within the mcu that I have coded.

    I am still fairly new when it comes to how exactly the mcu and computer interact so I'm confused as to how I can take data I send and then code firmware to utilize it.

  • In just the same way you send strings, you can open a file on the PC and send it a character or line at a time across the serial connection. How the microprocessor handles this stream of data will depend on how effectively you've implemented your character and line parser.

    It's not going to do anything with .C file code unless your parser explicitly handles such.

    In C you have fopen/fclose/fread/fwrite/fseek, under Win32 you have CreateFile/CloseFile/ReadFile/WriteFile

  • Ugh.

    Are you really trying to send, as data, a string that contains "WriteRegisterOpt(8, 1, 0x03249249, 0);" and then expect the MCU to execute it?

    You can't do that.

    (The experienced engineers could, but that is complicated)

    You need to write code that reads the data being sent, then upon reception, parse the data to extract the information from it.

    You should send data like "0x55, 0x08, 0x01, 0x03249249, 0x00" where the 0x55 represents the function "WriteRegisterOpt()" function.

    Assuming that you have a receive buffer you have access to, is could look similar to this:

    Receive_Buffer[ 0 ] = 0x55; // This is just an example
    Receive_Buffer[ 1 ] = 0x08; //  of the data you wanted to send
    Receive_Buffer[ 2 ] = 0x01; //  but in array form
    Receive_Buffer[ 3 ] = 0x03;
    Receive_Buffer[ 4 ] = 0x24;
    Receive_Buffer[ 5 ] = 0x92;
    Receive_Buffer[ 6 ] = 0x49;
    Receive_Buffer[ 7 ] = 0x00;
    


    Then you should have the ability to group the data:

    #define COMMAND_WRITEREGISTEROPT   0x55 // Arbitrary value
    
    Command   = Receive_Buffer[ 0 ];   // the arbitrary value that represents 'WriteRegisterOpt'
    Argument1 = Receive_Buffer[ 1 ];   // the 0x08 value
    Argument2 = Receive_Buffer[ 2 ];   // the 0x01 value
    Argument3 = Get_Value( &(Receive_Buffer[ 3 ]) );// where the Get_Value( ) function converts
                                                    // the bytes to that '0x03249249' number
    Argument4 = Receive_Buffer[ 7 ];   // the 0x00 value
    

    Then you can write code that runs your send command:

        if( Command == COMMAND_WRITEREGISTEROPT )
        {
           WriteRegisterOpt( Argument1, Argument2, Argument3, Argument4 );
        }
    

    This is not actual code to implement. This should just give you an idea on what tasks are involved in getting your target code to execute routines (within your code) with parameters

    --Cpt. Vince Foster
    2nd Cannon Place
    Fort Marcy Park, VA

  • There is a book that I think would be belpfull by YIU called the
    Definitive Guide to the ARM Cortex M0. Even if you do not want to
    buy the book, if you search for the book and find the book home page
    of the publisher you should be able to download the example projects
    for no charge.

    store.elsevier.com/product.jsp

    there are online companion materials that you can download there.

    This book targets LPC1114 Keil board.

    I think the text_io might be instructive to look at.

    Also, I would try just using Tera Term progam to talk with the board instead of
    writing a C program. At least to get the MCU program correct.

    Also, I do not see any example there that uses interrupt for the UART.

    I also like to look at the Measure example for a Cortex M3 at the following
    location:

    C:\Keil_v5\ARM\Examples\Measure

    Although I has a lot of things going on at the same time.

  • I'll definitley check the book out. Thanks a lot Cpt. Vince your post really gave me a lot of insight on what I'm supposed to do. I don't know why I didn't think about doing it that way in the first place. Thanks!

  • Olson, an issue I'm running into is how to trigger the UART interrupt loop that I posted.

  • I'm glad I was able to help you realize and refine what you need to learn to implement your goal.

    Back in the day, I didn't know what I was doing either.

    I had searched high and low to find a "pull-up resistor" because I thought it was a different component than a regular resistor.

    Eventually, I asked an engineer and he explained it. I felt like an idiot.
    Feeling like an idiot is better than not asking at all.

    --Cpt. Vince Foster
    2nd Cannon Place
    Fort Marcy Park, VA

  • Feeling like an idiot is better than not asking at all.

    Unfortunately there are too many who don't do this, thinking it's better to become a consultant.

  • Some people ask - but lots of people gravely fails to supply enough information that anyone can answer. And the (often total) lack of information in the questions indicates the lack of thought spent before asking the questions.

    So very few questions are bad questions (unless they are constantly repeated). But the way the questions are asked tends to quickly separate the fools from people who wants to learn.

  • Forgot to say the USART example uses Interrupt