Hi there Keil forums, I have a question about how my LPC 1114 responds to data over a Uart connection.
This is my UART interrupt code:
/* UART Data Received Interrupt */ 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; } }
My computer and mcu are connected via a usb to uart cable. I want to know what kind of data I need to send to my mcu in order to trigger this interrupt. For example if I want to send the integer "1" to my mcu how would I do that and then I can store that integer value in a variable within the firmware of the MCU. My GUI is done in C# and it is what I use to communicate with the mcu.
A microcontroller's UART (and a PC's COM port) just sends and receives bytes - it neither knows nor cares anything of the meaning or interpretation of those bytes.
When a microcontroller's UART (and a PC's COM port) sends a byte, it neither knows nor cares anything of the destination of that byte. It just sends; the destination is irrelevant.
When a microcontroller's UART (and a PC's COM port) receives a byte, it neither knows nor cares anything of the source of that byte. It just receives; the source is irrelevant.
So it's entirely up to you how you want to represent your data over the link.
Sending a "1" is a trivial case - you can either send a single byte with the numerical value one (0x01), or you can send a single character '1'.
Things get more interesting when you need to send stuff that can't be represented in a single byte, but you still have basically the same choice: either send as a "raw" numerical value, or send as a text string (a sequence of characters).
To send characters, you would encode them using ASCII
en.wikipedia.org/.../ASCII
http://www.asciitable.com/
There is a proviso there:
Some communication links may interpret certain byte values as "special" and use them as "control codes".
In particular:
* So-called "software" flow control uses the X-ON and X-OFF codes to start & stop transmission: en.wikipedia.org/.../Software_flow_control
* Some systems may translate "end-of-line" sequences; eg, expanding CR to CR+LF: en.wikipedia.org/.../Newline
This will obviously interfere with you sending your stuff as "raw" numeric values...
en.wikipedia.org/.../transmitter
And, of course, be sure to study the UART section in your chip's Datasheet (or "user manual" or whatever the manufacturer calls it).