ARM Technical Support Knowledge Articles

AUTOMATED SERIAL INPUT SCRIPT

Applies to: uVision Debugger

Answer


Information in this article applies to:


QUESTION

I have an 8051 application that processes a lot of serial data. I'm simulating the program using the uVision Debugger, but I have to type in a lot of data in the serial window. Is there a way to automate this?

ANSWER

Yes. You can create a simple script that injects your data into the serial input buffer. To demonstrate this, first you will need the following simple test program:

/*-----------------------------------------------------------------------------
-----------------------------------------------------------------------------*/
#include <REG52.H>
#include <stdio.h>

/*------------------------------------------------
The following string is the stuff we're gonna
send into the serial port.
------------------------------------------------*/
unsigned char xdata serial_input_buffer [] =
  "This is a test to see if this data gets "
  "injected into the serial port.
"
  "Have fun.
"
  "

";

void main (void)
{
/*------------------------------------------------
Setup the serial port for 2400 baud at 12MHz.
------------------------------------------------*/
SCON  = 0x50;  /* SCON: mode 1, 8-bit UART, enable rcvr      */
TMOD |= 0x20;  /* TMOD: timer 1, mode 2, 8-bit reload        */
TH1   = 0xF3;  /* TH1:  reload value for 2400 baud @ 12MHz   */
TR1   = 1;     /* TR1:  timer 1 run                          */
TI    = 1;     /* TI:   set TI to send first char of UART    */

/*------------------------------------------------
Get a key from the serial port and send it
right back out the serial port.
------------------------------------------------*/
while (1)
  {
  putchar (_getkey ());
  }
}

/*-----------------------------------------------------------------------------
-----------------------------------------------------------------------------*/

Note that this test program simply sets up the serial port for 2400 baud and echos characters it receives.

The data that you will send into the simulated serial port is stored in the serial_input_buffer string declared at the top of this file. This is a convenient way to get this data into memory. However, you may want to create Intel HEX files (at fixed addresses) that contain your test data. You may load the HEX files and then dump their contents into the serial window using a method similar to this one.

Second, you must create a simple debugger script that reads the input data and inputs it into the simulated serial port. The following script does that:

define int seri_index;

signal void seri_start (float baudrate) {
  seri_index = 0;

  for (seri_index = 0; serial_input_buffer[seri_index] != ''; seri_index++) {
    SIN = serial_input_buffer[seri_index];
// Wait for a little longer than 1 character time between each character
    swatch (1.0 / ((baudrate/10.0) + 20.0));
  }
}

define button "Send Data" , "seri_start(1200)"

Additionally, a button is created in the toolbox to start sending in the serial data.

There are several things to note about this script.

  1. It can actually send data faster than the 8051's serial port can receive it. So, if the test program runs at 1200 baud and the script sends 200 characters per second, your program will not receive all the serial data.
  2. This script assumes an ANSIIZ (null-terminated) string. You may of course modify it to send a fixed number of bytes.
  3. The serial_input_buffer is a variable in your program. If you want to use a fixed memory address (so you can load in Intel HEX data) you may use the _RBYTE function to read bytes from a specified address.

SEE ALSO

Article last edited on: 2005-12-15 08:05:03

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential