µTasker Forum

µTasker Forum => µTasker general => Topic started by: tr111 on September 07, 2007, 10:13:34 AM

Title: How to use the UART to get data and send data!
Post by: tr111 on September 07, 2007, 10:13:34 AM
hello:
     How to use the UART to get data and send data! I only the Tty_drv.c is the uart driver!
      when I send the data to the mcf52235 ,it will auto send back to me now! I don't why?
     Now  I want to get the data from UART and send to the ETH!
    But I don't know how the get the  UART data and send the data by UART!
   Regards

tr111
Title: Re: How to use the UART to get data and send data!
Post by: tr111 on September 07, 2007, 10:17:10 AM
hi:
   I think the Utasker is very easy to use!
Title: Re: How to use the UART to get data and send data!
Post by: mark on September 07, 2007, 02:05:10 PM
Hi
To use the serial interface(s) first ensure that the define SERIAL_INTERFACE is active in config.h. This will include UART driver support. It will also include use of the UART in the uTasker demo project.

It is best to start with the demo since it shows how to configure and open a UART. It will receive and actively echo characters back and it will serve a menu when the Entery key is pressed. The setup of the UART is additionally controllable via the menu, TELNET or Web Browser, where the configuration can be changed 'on-the-fly'.

1. Configuring and opening

Code: [Select]
    TTYTABLE tInterfaceParameters;                                       // table for passing information to driver
    tInterfaceParameters.Channel = DEMO_UART;                            // set UART channel for serial use
    tInterfaceParameters.ucSpeed = temp_pars->temp_parameters.ucSerialSpeed; // baud rate
    tInterfaceParameters.Rx_tx_sizes.RxQueueSize = RX_BUFFER_SIZE;       // input buffer size
    tInterfaceParameters.Rx_tx_sizes.TxQueueSize = TX_BUFFER_SIZE;       // output buffer size
    tInterfaceParameters.Task_to_wake = OWN_TASK;                        // wake self when messages have been received
    #ifdef SUPPORT_FLOW_HIGH_LOW
    tInterfaceParameters.ucFlowHighWater = temp_pars->temp_parameters.ucFlowHigh;// set the flow control high and low water levels in %
    tInterfaceParameters.ucFlowLowWater = temp_pars->temp_parameters.ucFlowLow;
    #endif
    tInterfaceParameters.usConfig = temp_pars->temp_parameters.usSerialMode;
    #ifdef TEST_MSG_MODE
        tInterfaceParameters.usConfig |= (MSG_MODE);
        #if defined (TEST_MSG_CNT_MODE) && defined (SUPPORT_MSG_CNT)
            tInterfaceParameters.usConfig |= (MSG_MODE_RX_CNT);
        #endif
        tInterfaceParameters.usConfig &= ~USE_XON_OFF;
        tInterfaceParameters.ucMessageTerminator = '\r';
    #endif
    #ifdef SERIAL_SUPPORT_DMA
        tInterfaceParameters.ucDMAConfig = UART_TX_DMA;                  // activate DMA on transmission
    #endif
    if ((SerialPortID = fnOpen( TYPE_TTY, FOR_I_O, &tInterfaceParameters )) != 0) { // open the channel with defined configurations (initially inactive)
        fnDriver( SerialPortID, ( TX_ON | RX_ON ), 0 );                  // enable rx and tx
    }

All interfaces are opened using fnOpen and the parameters are passed in a table - in this example some parameters are fixed and some are set from the user parameters. Note that DEMO_UART is the UART number (0, 1, 2 etc. depending on what the used processor supports) which can be defined in app_hw_xxx.h to suit your board or project.

SerialPortID is a handle to the UART which is then used for communication.

The demo can test also different reception modes:
TEST_MSG_MODE        - the receiver task is woken only when a complete line of data, terminated by the defined character, is received.
TEST_MSG_CNT_MODE - the same as TEST_MSG_MODE but the message length is also returned in the rx buffer.

There are various other mode details, like ECHO_RX_CHARS to automatically echo received characters, USE_XON_OFF to enable XON/XOFF flow control. See driver.h for a list.

2. Sending messages

Code: [Select]
    static const CHAR ucCOMMAND_MODE_TIMEOUT[] = "Connection timed out\r\n";
    fnWrite(SerialPortID, (unsigned char *)ucCOMMAND_MODE_TIMEOUT, sizeof(ucCOMMAND_MODE_TIMEOUT));

A write to the UART handle will cause data to be transmitted.
For sending strings - eg. for debug purposes - fnDebugMsg("Test"); is typically used. Before using for the first time, divert the debug output to the required UART by setting the following global variable:
    DebugHandle = SerialPortID;
(As a side note, when not set for UART output, debug data will be sent to the routine fnNetworkTx, which can also be a TELNET connection - the demo project also support this)

3. Receiving data
Generally the UART is configured to wake the receiving task on reception.
[tInterfaceParameters.Task_to_wake = OWN_TASK;]
Depending on the exact operating mode, this can be on each received character or each received terminated line of input. The demo project shows how to receive correctly in each mode:

fnMsgs(SerialPortID); This is called to return the number of waiting messages. In character mode this is equal to the number of characters but in message mode it will indicate the number of complete messages and not individual characters.

Length = fnRead( SerialPortID, ucInputMessage, MEDIUM_MESSAGE); This will return as many waiting characters in the input buffer, up to the limit MEDIUM_MESSAGE. The number of characters actually copied to the buffer ucInputMessage is returned.

4. Simulating UARTs in the uTasker simulator
By mapping the UART(s) to COM ports on the local PC, the simulator sends and receives data as on the real target and can enable efficient testing and project development.

In app_hw_xxxx.h you can set these defines:
    #define SERIAL_PORT_0 '1'     // if we open UART channel 0 we simulate using com1 on the PC
    #define SERIAL_PORT_1 '2'     // if we open UART channel 1 we simulate using com2 on the PC
    #define SERIAL_PORT_2 '3'     // if we open UART channel 2 we simulate using com3 on the PC

etc. depending how many UARTs are available
 
If you set ‘0’ no com port will be mapped. Eg. if you instead set ‘5’ COM5. will be mapped, etc. Don’t map 2 simultaneously used UARTS to the same COM since only the first will actually work. Mapping to a non-existent or already used COM port has no detrimental effects but it will of course not be abl eto use the port.


This is only a brief introduction because the UART support has quite a lot of different configurations and there are various extra details about using DMA, flow control etc.

It should however be possible to start working with the UARTs base do this and the uTasker demo example, in the simulator and on the target. We can use this thread for extra discussion details as work progresses.

Good luck

Regards

Mark






Title: Re: How to use the UART to get data and send data!
Post by: tr111 on September 08, 2007, 01:28:30 AM
Mark:
     Thank you very much!
     Your answer is always fast and professional!
      Regards

     tr111

Title: Re: How to use the UART to get data and send data!
Post by: guibiao on September 28, 2007, 06:24:31 PM
Hi, Mark. How difficult is it to modify the tty driver code, so in character mode, it only wakes the related task when it receives fixed number of bytes, instead checking the receiving buffer in the task code. It seems more efficient to handle UART comm with fixed length. I also like to be able to change that length easily if needed to. Thanks!

Guibiao
Title: Re: How to use the UART to get data and send data!
Post by: mark on September 28, 2007, 08:17:11 PM
Hi Guibiao

It would not be very difficult to do this, but would need a change in the TTY_drv.c code.

However this type of operation is not very common. The reason is that usually the UART is used to receive messages that can be variable length. If for example it would collect 8 characters before waking the owner task it would mean that if only 7 are received they would have to wait until one more byte arrived before being serviced.

Some times it is possible to use a terminating character - example a CR or LF. This is often useful for typed input since the low level driver can collect the message and wake the owner task only when the user has hit the ENTER key. Message mode operation solves this. Also some protocols have a terminating character and this can be implemented efficiently like this.

It is less common to find protocols with fixed length messages, but there are some. In fact the use of DMA for reception in this case is the most efficient method. This is supported by the M5223X project where the receiver can be set to fixed length DMA reception mode (really because it is the only real way of using DMA on the receiver anyway...). As a reference see the routine fnSciRxByte() in tty_drv.c and the define SERIAL_SUPPORT_DMA.

At the end of this routine (which is in fact the interrupt for each received character) you will see the following lines of code:

    if ( rx_ctl->wake_task ) {                                                   // wake up an input task, if defined, when defined number of characters have been collected
        uTaskerStateChange(rx_ctl->wake_task, UTASKER_ACTIVATE);         // wake up owner task
    }

This is where the owner task is being woken and this is called on every character.
You could easily change this to something like:

    if ((rx_ctl->tty_queue.chars == 8 ) && ( rx_ctl->wake_task )) {             // wake up an input task, if defined
        uTaskerStateChange(rx_ctl->wake_task, UTASKER_ACTIVATE);         // wake up owner task
    }

This would then only wake when the number of waiting characters reaches 8. This can be set as a global variable which can be modified (or better as an entry in the TTYQUE struct belonging to the UART channel).

Regards

Mark
Title: Re: How to use the UART to get data and send data!
Post by: guibiao on October 19, 2007, 11:33:36 PM
Hi, Mark. When I try the simulator, the demo serial port works (get the menu after enter key). But, when I download the demo code onto the Raisonance Demo board (STR912FX). Nothing on the serial port1 (Could not see anything even with scope). Did I miss something obvious? Thanks!
 
Guibiao
Title: Re: How to use the UART to get data and send data!
Post by: guibiao on October 19, 2007, 11:54:50 PM
Never mind, I forgot the jumpers!
Title: Re: How to use the UART to get data and send data!
Post by: mark on October 29, 2007, 11:48:54 PM
Hi All

For some more information about UART flow control see the following thread:

http://www.utasker.com/forum/index.php?topic=105.msg420#msg420

Regards

Mark
Title: Re: How to use the UART to get data and send data!
Post by: Tino on January 20, 2008, 06:56:17 PM
Hi,
I can write to the serial port and receive it on the pc. But when I try to receive data, it crashes.

I use the following code:

if (fnMsgs(SerialPortID) > 0) {
unsigned char ucRx[10];
unsigned char ucLength = 5;
ucLength = fnRead( SerialPortID, ucRx, 10);
fnWrite(SerialPortID, (unsigned char *)ucRx, ucLength);
}

When it is commented, ethernet, can and serial send work.
But as soon as I uncomment it, ethernet and serial send don't work anymore. Only can goes on but very unreliable.

I tried many things like changing the defines in config.h and the parameters in application.c.
It didn't work.
What to do?
Is there some tutorial how to do it? I tried all things written in the forum and also from the documents.

I use serial port 0.

Thanks,
Tino
Title: Re: How to use the UART to get data and send data!
Post by: mark on January 20, 2008, 08:15:05 PM
Hi Tino

I don't see any error with the code below.
However, check that the code is not being called before the interface has been opened - i.e. that it is not crashing because fnMsgs(SerialPortID) is being called with an invalid value for SerialPortID.

It is not clear whether the code crashes only when something has been received or if it crashes as soon as the program is run, even when no data has been received. (If you can run the same code in the uTasker simulator it would be interesting if you get the same results).

I can't make any statement concerning the fact that CAN is still working (but unreliably) - I believe you are using the SAM7X project where CAN is not supported so you possibly have added your own CAN driver (?).

Regards

Mark

PS. If you can send me your project (or the complete code of the modules(s) working the serial port) it may help to see the reason.

PPS. The uTasker demo project contains serial interface support. Connect with 19'200 and hit the enter key of a connected terminal emulator to activate a menu driven interface. This should work on your board and then serve as a reference.
Otherwise this thread gives most details about how best to use it.
Title: Re: How to use the UART to get data and send data!
Post by: Tino on January 21, 2008, 12:57:59 PM
Hi,
It seems that I called the code before the usart was initialized.
Now I check
if (SerialPortID > 0) {
and it works.
But is the check correct? What is the initial value of SerialPortID?

I also had to comment some lines in the application.c which echoes the received chars.

Finallly everything is working!!
The CAN driver is self implemented.

Thank you for your support,
Tino
Title: Re: How to use the UART to get data and send data!
Post by: mark on January 21, 2008, 01:51:07 PM
Hi Tino

The initial value of the SerialPortID handle is defined by the code using it - generally 0 (which indicates that it has not been allocated yet).
Generally code should not try to use a serial handle before the interface has actually been opened - checking it as you have of course protects against this. The correct method is however to open the interface at a place in the code which is always called before other accesses are made.

Regards

Mark
Title: Re: How to use the UART to get data and send data!
Post by: Fausto_F on March 17, 2008, 09:24:17 PM
Hi Mark,

I'm using the serial port to create a RS485 Bus, however in half mode.
In this case, I need to guarantee that all output buffer was sent and then change the 485 driver from transmit to receive mode, in other words I have to wait something like UART_TEMP = 1 (Transmit Buffer Empty), so my question is: Can uTasker generate any unsoliceted event to show me that the transmit buffer was really sent?
If no, which would be the most suitable way to do this?

Thanks

Fausto

Title: Re: How to use the UART to get data and send data!
Post by: mark on March 17, 2008, 11:05:45 PM
Hi Fausto

One possibility to get an event when the tx buffer becomes empty would be to use the TX_FREE event.

This is a small extract from tty_drv.c:
#ifdef WAKE_BLOCKED_TX
    #ifdef SUPPORT_FLOW_HIGH_LOW
            fnWakeBlockedTx(ptTTYQue, rx_control[channel]->low_water_level);
    #else


Assuming the defines WAKE_BLOCKED_TX and SUPPORT_FLOW_HIGH_LOW are active, the owner task will be sent a TX_FREE event each time the level of the output buffer readuces to equal the low water level. If you are not using flow control, this can be set to 0 so that it happens when a message has been sent.
Before transmitting the message, the following call will enter the task to be woken (it has to be reset on each message):
fnDriver( SerialHandle, MODIFY_WAKEUP, (MODIFY_TX | OWN_TASK) );

Of course, the tty_drv.c code can also be slightly modified if needed to send this event every time the output buffer becomes empty.

There is however a problem involved which is hardware specific. Most UARTs generate interrupts when there is space in the output buffer. Some can also generate interrupts when the transmission has completed (when the last interrupt arrives, it generally means that there is space to send the next byte but not that the transmission has in fact terminated). Depending on the UART in question there may be a more accurate method but tty_drv.c is HW independent and any more specific work will need to be performed in the HW driver itself.

The problem means that when the TX_FREE event arrives and the code wants to change the direction it is probably too early since the last byte is still being transmitted. If the UART that you are using doesn't give a method to get notification when the bytes has completely been transmitted, the SW will have to first wait a short time equal to the transmission delay of one character. To do this, a generic solution would be to use the TX_FREE event to start a timer equal to the bit time multiplied by the character bits, including stop bits, etc. When this timer fires, the direction of the the RS485 bus can be changed.

Good luck

Regards

Mark


Title: Re: How to use the UART to get data and send data!
Post by: Fausto_F on March 18, 2008, 02:00:22 PM
Hi Mark,

A debounce timer after the event seems to be the best solution.

Thanks again for all your support.

Fausto
Title: Re: How to use the UART to get data and send data!
Post by: Arun Bhargav on August 07, 2008, 11:43:13 AM
Hello,

A better solution to UART problems is Cypress. They are an expert in UART, Data acquisition and control system.  Cypress provides a wide selection of Documentation, Design Kits, Training, Technical Articles, Example Projects and more to help design engineers use our products effectively.
Check this at http://www.cypress.com/
Title: Recieving Data via Simulator
Post by: kyork on August 21, 2008, 09:53:12 PM
I have a USB->Serial device connected to my PC and I would like to use the Simulator to talk to it.  I have the following simple task setup:

Code: [Select]
void fnApplication(TTASKTABLE *pTable)
{
//initialize
if( state == 0 )
{
TTYTABLE tInterfaceParameters;       //table for passing information to driver

tInterfaceParameters.Channel = DEMO_UART;  // serial 0, 1, 2, 3, 4, etc.
  tInterfaceParameters.ucSpeed =  SERIAL_BAUD_115200; // baud rate
  tInterfaceParameters.Rx_tx_sizes.RxQueueSize = RX_BUFFER_SIZE;       // input buffer size
tInterfaceParameters.Rx_tx_sizes.TxQueueSize = TX_BUFFER_SIZE; // outpu buffer size
    tInterfaceParameters.Task_to_wake = 0;
tInterfaceParameters.usConfig = (CHAR_8 | NO_PARITY | ONE_STOP | RTS_CTS | NO_HANDSHAKE | CHAR_MODE);    

if ( (SerialPortID = fnOpen(TYPE_TTY, FOR_I_O, &tInterfaceParameters)) != 0 )  // open or change the channel with defined configurations (initially inactive)
{
fnDriver( SerialPortID, (RX_ON | TX_ON), 0 );        // enable RX & TX
DebugHandle = SerialPortID;
state = 1;
}
}
else
{
int count = fnMsgs(SerialPortID);
if( count > 0 )
{
unsigned char buffer[MEDIUM_MESSAGE];
int read;

read = fnRead(SerialPortID,buffer,MEDIUM_MESSAGE);
}
}
}

Also, I have #define SERIAL_PORT_0   '8' set in app_hw_m5223x.h

If I reset the device connected to the USB->Serial connection, it sends some data on bootup.  If I connect to COM8 with Hyperterminal, I can see this data come in.  However, the above task never gets a value from fnMsgs() greater than zero.

Am I missing some step to get the Simulators serial emulation to work?
Title: Re: How to use the UART to get data and send data!
Post by: mark on August 22, 2008, 01:20:50 PM
Hi

By setting the define #define SERIAL_PORT_0   '8' all communication with the UART 0 should be mapped to COM 8 - in both directions. There should be nothing more necessary.

I would suggest the following checks.
1. Check that DEMO_UART is also 0

2. Check that you don't have SERIAL_SUPPORT_DMA active. This would require tInterfaceParameters.ucDMAConfig = x; to also be configured when setting it up. Undefined configuration parameters could cause problems.

3. Connect your COM 8 via a cross-over cable (null-modem cable) to a terminal emulator set up to 115200 baud. Add a test transmission to your code after it has opened the UART interface (eg. fnWrite(SerialPortID, ""HELLO", 5);, or fnDebugMsg("HELLO"); since you have set the debug output to the UART) This should arrive at the terminal emulator so that you can verify that transmission is operating correctly.

4. I would set tInterfaceParameters.Task_to_wake to TASK_APPLICATION so that each received character will wake the task (is it polling in your test case?). When entering something at the terminal emulator the task should be woken (set a break point in it to verify) and then fnMsgs() should also return the character count and the read return the entered character(s).

I just verified your code, with modifications for 3 and 4. It was using COM 3 (also a USB-RS232 converter) and it ran successfully.

Regards

Mark
Title: Re: How to use the UART to get data and send data!
Post by: kyork on August 22, 2008, 05:22:28 PM
Mark,

Thanks for the follow up. 

The problem seems to be some kind of buffering, maybe on the USB/Serial converter.  Here's what I'm seeing happen.

1) Start the Simulator
2) Power up the serial device
3) <no incoming message>
4) Stop Simulator
5) Start Simulator
6) <message expected from #3 reads in immediately>
7) Write command to serial to cause a reset
8) Serial device resets (so obviously writing works)
9) <no incoming message>

I'm going to play with it some more, see if I can narrow down exactly what's going on.
Title: Re: How to use the UART to get data and send data!
Post by: mark on August 22, 2008, 07:57:58 PM
Hi

Make sure that the default setup of the USB-RS232 interface (or the terminal emulator) is not HW handshake since it may refuse to sent in this case. This is also valid for all COM ports.

I sometimes have my USB-RS232 adapter block in XOFF mode and have to disconnect and reconnect to get it working again (not a big issue since it only happens when unexpected random data is receivd by it in XON/XOFF handshake mode).

Recently there was an article in a well known electronics magazine where they wrote about setting up a board via an RS232 interface. Their recommendation was not to use a USB-RS232 converter but rather a PC with COM ports. They even wrote that "if you don't have a PC with COM port then try to borrow one from someone for the setup which does"! This is very extreme - the USB-RS232 adapters can certainly give a few more problems that the real COM ports but they are not that bad....

Regards

Mark
Title: Re: How to use the UART to get data and send data!
Post by: kyork on August 25, 2008, 10:56:09 PM
Mark,

I have some legacy code that writes data to the UART and then polls until it gets a response.  Is it possible to write directly to the serial driver?

Thanks
Title: Re: How to use the UART to get data and send data!
Post by: mark on August 25, 2008, 11:01:24 PM
Hi

I am not exactly sure what you mean by writing directly to the serial driver. It is of course possible to use a different driver interface by removing SERIAL_INTERFACE and adding other code to do it.

Have you an example of the legacy code?

Regards

Mark
Title: Re: How to use the UART to get data and send data!
Post by: kyork on August 25, 2008, 11:25:46 PM
The legacy code is a transport layer driver, the psuedocode is:

driverInit();   //open serial

while( !connected )
{
  fnWrite(RESET); //this sends a RESET frame to the UART device
  fnRead(buffer);
  if( buffer == RSTACK )
     connected = true;
}

The RESET frame is never sent out in this case (I assume because the data is buffered, and sent later by the scheduler).  Is there any way to force the UART driver to write the buffered data?
Title: Re: How to use the UART to get data and send data!
Post by: mark on August 26, 2008, 04:09:06 AM
Hi

OK - I understand now.

First of all - check out the following thread which will explain why the reset is not sent out when using the simulator:
http://www.utasker.com/forum/index.php?topic=330.0

Try putting your original code in a task similar to the folliwing and you should find that - with a small(ish) change - it will work:

void fnMyTask(TTASKTABLE *ptrTaskTable)
{
    static int iState = 0;
    if (!iState) {
        driverInit();   //open serial on initialisation
        iState = 1;
    }
    switch (iState) {
    case 1:             // need to connect
        fnWrite(RESET); //this sends a RESET frame to the UART device
        iState = 2;
        uTaskerStateChange(OWN_TASK, UTASKER_GO);  // switch to polling mode
        break;
    case 2:
        if (fnRead(buffer) != 0) { // read the input (do nothing if nothing arrived)
            if( buffer == RSTACK ) {
                iState = 3;
                uTaskerStateChange(OWN_TASK, UTASKER_STOP); // switch to event mode of operation
                break;
            }
        }
        fnWrite(RESET); // sends the RESET frame again until a correct answer is received
        break;
    case 3:            // synchronised - continue with normal operation
        break;
    }
}



This will send the RESET frame and then quit. Since the task is set to polling mode it will then return (after allowing other stuff to run in the meantime) and see whether there is an answer. If not it will repeat until there is.

It can then be made more efficient by allowing reception to wake the task and adding a timer to repeat if there is no answer after a certain time, rather than polling.

Once in state 3 the reset has received an answer and further code can be run.

You could possibly map the original read and write calls to uTasker ones by using macros.
eg.
#define fnWrite(x) buff = x; fnWrite(serialID, &buff, 1);  // buff is a byte declared somewhere as unsigned char buff;
#define fnRead(x) fnRead(serialID, &x, 1);


If there are not a lot of such calls they could also be simply replaced.


I have rebuilt a number of old projects, especially ones running in super-loops. You usually find that there are various ways to make them more efficient by adding some timer or event support instead of polling. The simulator helps because the changes can be quite easily tested immediately. The code tends to become more structured/modular which then helps when additional features then need to be added. Also the original code works alongside new Ethernet stuff - as long as the new code occupies new tasks they shouldn't disturb each other and so can be kept logically separate.


Regards

Mark

Title: Re: How to use the UART to get data and send data!
Post by: mark on May 10, 2009, 09:15:20 PM
Hi All

Please note that there is a new UART document here: http://www.utasker.com/docs/uTasker/uTaskerSerialLoader.PDF

At the time of writing it is a preliminary (in work) document but it will be extended to include all present support as well as extensions.

Comments on extra modes or explanations which would be useful in the document are welcome here.

Regards

Mark

Title: Re: How to use the UART to get data and send data!
Post by: Kevin on June 16, 2010, 01:47:18 AM
I cannot get the simulator uart to work on COM1 (only serial port) or COM13 (usb to serial dongle).

I've got COM1 connected through a null modem to COM13 and have tera term connected to COM13.

app_hw_lpc23xx.h is set up as follows:
Code: [Select]
#ifdef SERIAL_INTERFACE
    #define WELCOME_MESSAGE_UART   "\r\n\nHello, world... LPC2XXX\r\n"
    #define NUMBER_EXTERNAL_SERIAL 0                                     // {6}
    #define NUMBER_SERIAL   (UARTS_AVAILABLE)                            // the number of physical queues needed for serial interface(s)
    #define SIM_COM_EXTENDED                                             // COM ports defined from 1..255
    #define SERIAL_PORT_0   1                                            // if we open UART channel 0 we simulate using this COM port on the PC
    #define SERIAL_PORT_1   4                                            // if we open UART channel 1 we simulate using this COM port on the PC
    #define SERIAL_PORT_2   11                                           // if we open UART channel 2 we simulate using this COM port on the PC
    #define SERIAL_PORT_3   12                                           // if we open UART channel 3 we simulate using this COM port on the PC

    #ifdef OLIMEX_LPC_P2103
        #define DEMO_UART        0                                       // use UART 0
    #else
        #define DEMO_UART        0                                       // use UART 0
      //#define PPP_UART         1                                       // use UART 1 for PPP
    #endif
    #define MODBUS_UART_0        0
    #define MODBUS_UART_1        1
    #define MODBUS_UART_2        2
    #define MODBUS_UART_3        3
  //#define SUPPORT_HW_FLOW                                              // enable hardware flow control support
    #if defined LPC2103 || defined LPC2102 || defined LPC2101
        #define TX_BUFFER_SIZE   (512)                                   // the size of RS232 input and output buffers
        #define RX_BUFFER_SIZE   (32)
    #else
        #define TX_BUFFER_SIZE   (4*1024)                                // the size of RS232 input and output buffers
        #define RX_BUFFER_SIZE   (64)
    #endif

    #ifndef _LPC21XX
      //#define UART1_PORT2                                              // set for alternative pin uses - TXD1 and RXD1 on P2.0 and P2.1 rather than TXD1 on P0.15 and RXD1 on P0.16
      //#define UART2_PORT2                                              // TXD2 and RXD2 on P2.8 and P2.9 rather than TXD2 and RXD2 on P0.10 and P0.11
      //#define UART3_PORT0_HIGH                                         // TXD3 and RXD3 on P0.25 and P0.26 rather than TXD3 and RXD3 on P0.0 and P0.1
    #endif

    #ifdef SUPPORT_HW_FLOW                                               // define the ports for RTS/CTS use
        #define RTS_0_PORT_SET     FIO0SET
        #define RTS_0_PORT_CLR     FIO0CLR
        #define RTS_0_PIN          PORT0_BIT6
        #define RTS_0_PORT_DDR     FIO0DIR
        #define RTS_0_PORT         PORT_0

        #define RTS_1_PORT_SET     FIO0SET
        #define RTS_1_PORT_CLR     FIO0CLR
        #define RTS_1_PIN          PORT0_BIT7
        #define RTS_1_PORT_DDR     FIO0DIR
        #define RTS_1_PORT         PORT_0

        #define RTS_2_PORT_SET     FIO0SET
        #define RTS_2_PORT_CLR     FIO0CLR
        #define RTS_2_PIN          PORT0_BIT5
        #define RTS_2_PORT_DDR     FIO0DIR
        #define RTS_2_PORT         PORT_0

        #define RTS_3_PORT_SET     FIO0SET
        #define RTS_3_PORT_CLR     FIO0CLR
        #define RTS_3_PIN          PORT0_BIT4
        #define RTS_3_PORT_DDR     FIO0DIR
        #define RTS_3_PORT         PORT_0

        #define CTS_0_PIN          PORT2_BIT0                            // CTS can be defined on ports 0 and 2 due to their interrupt capabilitieds
        #define CTS_0_PORT_DDR     FIO2DIR
        #define CTS_0_PORT         PORT_2
        #define CTS_0_STATE        FIO2PIN
        #define CTS_0_INT_PRIORITY 5

        #define CTS_1_PIN          PORT2_BIT1
        #define CTS_1_PORT_DDR     FIO2DIR
        #define CTS_1_PORT         PORT_2
        #define CTS_1_STATE        FIO2PIN
        #define CTS_1_INT_PRIORITY 5

        #define CTS_2_PIN          PORT2_BIT2
        #define CTS_2_PORT_DDR     FIO2DIR
        #define CTS_2_PORT         PORT_2
        #define CTS_2_STATE        FIO2PIN
        #define CTS_2_INT_PRIORITY 5

        #define CTS_3_PIN          PORT2_BIT3
        #define CTS_3_PORT_DDR     FIO2DIR
        #define CTS_3_PORT         PORT_2
        #define CTS_3_STATE        FIO2PIN
        #define CTS_3_INT_PRIORITY 5
    #endif

Is there something else I have to do to enable the menu through the serial port when using the Simulator?

-Kevin
Title: Re: How to use the UART to get data and send data!
Post by: Kevin on June 16, 2010, 03:30:47 AM
I ran through the "myfirsttask" tutorial and now everything seems to work.
Title: Re: How to use the UART to get data and send data!
Post by: mhoneywill on June 16, 2010, 08:31:59 AM
Hi Kevin,

To remove the need for hardware serial ports take a look at com0com http://com0com.sourceforge.net/ which will create any number of virtual serial port pairs on your PC which are linked with a virtual null modem cable. For example I have the following pairs set-up on my computer

com100 <--> com110
com101 <--> com111
com102 <--> com112

All my utasker projects connect to Uart0 to Com100, Uart1 to Com101 ... etc I then connect my terminal applications or test programs, or other utasker projects (If I'm simulating to utasker boards talking to each other) to the other port i.e. com110, com111 ... etc.

Com0com is very easy to use and in my experience just works :-). Note when it installs it creates a serial port pair with the names CNCA1 and CNCB1 just use the configuration tool to rename these to Comxxx etc.

I use high com port numbers to ensure I don't clash with other bits of hardware / Usb adapters I use.

Note: if you use com ports creater than com9 you will need to define SIM_COM_EXTENDED in the hardware header file for the hardware I'm simulating this is app_hw_lm3sxxxx.h

You might want to look at these other posts
http://www.utasker.com/forum/index.php?topic=343.msg1447#msg1447
http://www.utasker.com/forum/index.php?topic=673.msg2922#msg2922
http://www.utasker.com/forum/index.php?topic=663.msg2856#msg2856

Cheers

Martin
Title: Re: How to use the UART to get data and send data!
Post by: Kevin on August 19, 2010, 02:38:44 AM
Thanks Martin!
Title: Re: How to use the UART to get data and send data!
Post by: mhoneywill on August 19, 2010, 10:55:53 AM
Email me if you have any questions, I use serial ports quite a bit (Mostly with the uTasker Modbus module, which is VERY good).

Good luck Martin
Title: Re: How to use the UART to get data and send data!
Post by: Kevin on September 03, 2010, 02:11:21 AM
Where are the port assignments for the UART TXD and RXD?  I found CTS and RTS in app_hw_lpc23xx.h.

I want to add two additional uarts one for a radio link and another for irda.
Title: Re: How to use the UART to get data and send data!
Post by: mark on September 03, 2010, 11:16:47 AM
Hi Kevin

Depending on the LPC that you are using you will have a number of UARTs. These are numbered 0, 1, 2 etc. for UART0, UART1, UART2 etc.
When the interface is initialised the UART used is defined by tInterfaceParameters.Channel (= 0,1, 2 etc.).

Some of the UARTs themselves have fixed locations (for example on the LPC23XX an LPC24XX UART0 Tx is always on P0.2 and UART0 Rx is always on P0.3).

Other UARTs may have multiple locations (for example on the LPC23XX and LPC24XX UART1 Tx can be on P0.15 or P2.0 and Rx can be on P0.16 or P2.1).

In the case of multiple ports you can configure the project to use certain ones.
In app_hw_lpc23xx.h you will find these defines:

      //#define UART1_PORT2                                      // set for alternative pin uses - TXD1 and RXD1 on P2.0 and P2.1 rather than TXD1 on P0.15 and RXD1 on P0.16
      //#define UART2_PORT2                                      // TXD2 and RXD2 on P2.8 and P2.9 rather than TXD2 and RXD2 on P0.10 and P0.11
      //#define UART3_PORT0_HIGH                                 // TXD3 and RXD3 on P0.25 and P0.26 rather than TXD3 and RXD3 on P0.0 and P0.1
      //#define UART3_PORT4                                      // [only LPC24XX] TXD3 and RXD3 on P4.28 and P4.29 rather than TXD3 and RXD3 on P0.0 and P0.1


They are off, meaning that the standard (default) pins are used. When set, they effectively map the pin use to alternative pin sets.

Note that the RTS and CTS defines are special since not all UARTs have RTS/CTS lines. In this case, so that all UARTs can always be controlled with RTS/CTS irrespective of whether the chip has dedicated lines for this, there is a set of defines used to map GPIOs to RTS/CTS use. The CTS lines need to be on ports with interrupt capability (specifically ports 0 and 2 on the LPC) but otherwise are flexible as to where they actually are.

Regards

Mark
Title: Re: How to use the UART to get data and send data!
Post by: Kevin on September 04, 2010, 03:05:51 AM
Thanks.  I initially read the defin as LPC21xxx, but its for not LCP21xx.  Thanks!

-Kevin
Title: Re: How to use the UART to get data and send data!
Post by: internship2 on February 27, 2013, 11:16:43 AM
Hi i am trying to get some messege out on the Terminal in CodeWarrior. I am trying to use
fnDebugMsg("Hallo world!");
I have
#define DEMO_UART and #define SERIAL_INTERFACE
i am using the right com port
it is becource its not possible to geth out in terminal or Tera Term

I am sitting with a K60F120M tower
Title: Re: How to use the UART to get data and send data!
Post by: mark on February 27, 2013, 02:43:30 PM
Hi

For the K60F120 board you need

#define DEMO_UART    5


since the serial board is connected to its UART5.

Check also the jumper settings on the serial extension board to be sure that the RS232 lines are connected.

Regards

Mark