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.
No.
--Cpt. Vince Foster 2nd Cannon Place Fort Marcy Park, VA
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.
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?
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
View all questions in Keil forum