📄 eval_faq.htm
字号:
<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="Microsoft FrontPage Express 2.0">
<title>Eval_c5131 FAQ and help page</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<p align="center"><font size="4" face="Verdana">FAQ : Help for
Eval_c5131</font></p>
<p align="center"><font size="3" face="Verdana">Compiling,
loading, testing, modifying and extending</font></p>
<hr>
<p><font size="2" face="Verdana"><strong>Running HI TIDE (Hi-tech
8051 compiler, trial version)</strong></font></p>
<p><font size="2" face="Tahoma">I have installed the Hi-Tide C-8051
trial version fresh on an old PC running Windows 98. This
successfully compiled eval_c5131 with no error. I have previously
installed Hi-Tide on a Windows XP (SP2) machine and got it to
compile successfully. Any problem you are having may be due to
incorrect installation, wrong project configuration, or maybe
some system incompatibility. My suggestion is to uninstall Hi-Tide
on your system and follow my instructions in the text file,
"Build_Notes.txt". <br>
(This file has now been added to the 'C5131 download package.)</font><font
size="2" face="Verdana"> </font></p>
<p><font size="2" face="Verdana"><strong>Atmel USB Firmware
"Library" modifications</strong></font></p>
<p><font size="2" face="Tahoma">You do not need to be concerned
with the internals of the usb library files (usb*.c, usb*.h). Use
the usb function library in much the same way you use "standard
C library" functions, e.g. putchar(), getchar(), etc. In the
case of the Atmel usb library, the only functions likely to be of
interest to you are: </font></p>
<pre>
void usb_vuart_init(void); // initialise the USB "virtual UART"
bit usb_vuart_rx_data_avail(void); // check if there's any chars received from PC
char usb_vuart_getchar(void); // read a char from the RX buffer
bit usb_vuart_tx_ready(void); // check if the TX buffer can be written into
char usb_vuart_putchar(Uchar); // write a char to the TX buffer
void usb_vuart_flush(void); // transmit the TX buffer to the host PC
</pre>
<p><font size="2" face="Tahoma">For example, to send the string
"Hello, world." to the host PC via USB, you can do this:</font></p>
<pre>
const char hello[] = "Hello, world.";
...
const char *str = hello;
usb_vuart_init();
while ( (c = *str++) != 0 )
{
usb_vuart_putchar( c );
}
usb_vuart_flush();
</pre>
<p><font size="2" face="Tahoma">This code may be implemented as a
background task, executed once, for example. Of course, your
program also needs to have a main loop, as in ALERT, from which
the "USB engine" is called frequently. This routine is
called maintain_usb_connection() in eval_c5131.</font></p>
<p><font size="2" face="Tahoma">At the PC end, running
HyperTerminal (as described in my eval_c5131 notes), you should
see the string displayed on the screen. Your PC application
software can communicate with the device, via USB, using the
"Virtual COM Port" driver, which is built into Windows
(from 98ME to XP). But first, I recommend you get eval_c5131
working, without any changes, to make sure you are communicating
with Hyperterminal. </font></p>
<p><font size="2" face="Verdana"><strong>Getting your device to
"enumerate" properly with the host PC</strong></font></p>
<p><font size="2" face="Tahoma">Until you understand precisely
what you are doing, leave the Vendor ID, product ID, and
everything else in the usb device descriptor exactly as it is in
the original eval_c5131 source files. Data in the device
descriptors must match exactly the corresponding information in
the device driver information file, "c5131_cdc.inf". Do
not change anything! To install the USB device driver on your PC,
the file "c5131_cdc.inf" must be copied into the
Windows directory. When you plug in the USB cable, the New
Hardware Wizard will attempt to find the .inf file and install
the required driver. </font></p>
<p><font size="2" face="Tahoma">NB: Use the Vendor ID, product
code, etc, supplied with eval_c5131, NOT those supplied with your
kit. Use the driver info file supplied with eval_c5131, i.e.
"c5131_cdc.inf". Do not make any changes to driver .inf
file.</font></p>
<p><font size="2" face="Tahoma">You don't need a thrid-party
"virtual COM port" driver to use HyperTerminal. Windows
has its own built-in VCP driver. Please read carefully all notes
provided in the EVAL_c5131 download package and comments in the
main eval_c5131 source files. There is a freeware utility called
"USB View" which tells you if your USB device is
communicating correctly with the host PC. The first step is to
get the PC to "enumerate" the device. If you don't know
what is meant by "enumeration", you should do some more
reading about USB comm's! (There's plenty of info on the web!) </font></p>
<p><font size="2" face="Tahoma">When you get the (unmodified)
"eval" program working, then you can make changes and
additions to suit your project, but keep the general structure of
your program as close to "eval" as possible. This will
keep problems to a minimum. Your application code should go into
one or more "background tasks" or CLI command function(s),
or both, as explained in the ALERT overview (html file).</font><font
size="2" face="Verdana"> </font></p>
<p><font size="2" face="Verdana"><strong>Getting HyperTerminal to
talk via USB in "Virtual COM port" mode</strong></font></p>
<p><font size="2" face="Tahoma">I had forgotten how tricky it is
to get going! To get HyperTerminal working in USB "Virtual
COM port" mode, follow these steps </font></p>
<p><font size="2" face="Tahoma">1. First, power up your USB
device and connect it to the host PC. Make sure the device is
running your application program (e.g. eval_c5131), not the Atmel
on-chip bootloader. You might need to reset the device. Assuming
the Atmel 'AT89C5131 CDC' driver is correctly installed, the PC
will recognise the device and make a USB connection, i.e. "enumerate"
it. If the device is not functioning correctly, Windows will give
an error message saying so. If the device is working OK, but the
driver is not installed, Windows will say "Found New
Hardware" and prompt you to install a driver. The best way
to proceed is to browse to the location on the hard disk where
the driver file (c5131_cdc.inf) was copied, i.e. don't let
Windows search for a driver automatically. </font></p>
<p><font size="2" face="Tahoma">2. Start HyperTerminal. If first
time run, use any arbitrary settings. It wants to know your
location, area code, etc. Anything will do. Disconnect (if
connected) and select 'File - Properties' from the menu bar. A
dialog box appears. Select the "Connect To" tab. In the
"Connect Using" field, select 'COMx', where x is the
highest number shown. This should be the "virtual COM port".
If you get an error, close HyperTerminal and start again at step
1. </font></p>
<p><font size="2" face="Tahoma">3. In HyperTerminal, click the
"Connect" button (if not already connected) and press
Ctrl+V 3 times. The eval_c5131 command line prompt (-->)
should appear. </font></p>
<p><font size="2" face="Tahoma">As I noted in the eval
documentation, HyperTerminal seems to be "quirky" (unpredictable)
to start up in USB virtual COM mode, so you might need to try
resetting the device, disconnecting and reconnecting the USB
cable, and/or "disconnecting" and "reconnecting"
in HyperTerminal (using the tool buttons). Once communications
with the USB device is established, HyperTerminal then behaves
reliably.</font></p>
<p><font size="2" face="Verdana"><strong>Tips on getting Eval_c5131
loaded and running on your target board</strong></font></p>
<p><font size="2" face="Tahoma">1. Have you used 'FLIP'
successfully to load firmware into your development board? Don't
forget to tick the 'BLJB' check-box in FLIP. This changes the
RESET vector to start your application program. Otherwise, the
bootloader starts by default on RESET. Alternatively, you can
start the application firmware using the big red button in FLIP,
after downloading. Once you tick the BLJB box, you must hold down
the 'ISP' button while pressing the RESET button, to start the
device bootloader. (The Futurlec board calls the 'ISP' button 'PSEN'.)
</font></p>
<p><font size="2" face="Tahoma">2. Have you tried communicating
with the board, running eval_c5131, via the serial (RS-232)
connection, i.e. using a real COM port set to 38400 Baud? (If not,
I suggest you do... it may be less trouble than USB. This is a
good way to check that the application code is laoded and running
properly.) </font></p>
<p><font size="2" face="Verdana"><strong>MCU crystal frequency</strong></font></p>
<p><font size="2" face="Tahoma">Eval_c5131 firmware (as
distributed) assumes a 16MHz crystal oscillator frequency. <br>
Change 'FOSC' (in usb_config.h) to suit other MCU crystal
frequency (MHz) as required. <br>
NB: FOSC has no effect on the UART (serial port) clock rate; it
only affects the USB clock.</font></p>
<p><font size="2" face="Tahoma">If you use a 24MHz crystal, the
UART baud rate will be 57600 Baud with no firmware change. <br>
The Baud rate can be changed in the source code. See comments in
the function initialise_uart(). <br>
For example, to get 38400 Baud using a 24MHz crystal, replace
these two lines in initialise_uart()...</font></p>
<pre>
if ( CKCON0 & BIT0 ) BRL = 230; /* MCU clock 'X2' mode => BDCLKDIV = 26 */
else BRL = 243; /* MCU clock 'X1' mode => BDCLKDIV = 13 */
</pre>
<p><font size="2" face="Tahoma">... with the one line below:</font></p>
<pre>
BRL = 217; /* 38400Bd using MCU 'X2' mode; FOSC = 24 (MHz).
</pre>
<p><font size="2" face="Verdana"><strong>Futurlec "USB
Development Board"</strong></font></p>
<p><font size="2" face="Tahoma">The Futurlec board design is
compatible with Atmel's AT89STK-05 board, so it should run my 'Eval_c5131'
firmware without modification, except you need to fit a 16MHz
crystal on the board for USB comm's. (See previous FAQ). </font></p>
<p><font size="2" face="Tahoma">Also, the Futurlec board runs 5V
to the MCU chip, but the AT89C5131(A) is specified to run at 3.3V
(see Atmel datasheet).</font></p>
<p><font size="2" face="Verdana"><strong>Handling compiler
incompatibilities</strong></font></p>
<p><font size="2" face="Tahoma">My source code is written for Hi-Tech
C, so I recommend using the Hi-Tech compiler. The Keil compiler
uses different qualifiers (keywords) to declare various 8051
memory spaces. For example, Hi-Tech uses the "far"
qualifier to access the extended RAM space, but (I believe) Keil
uses "xdata". The qualifiers "const" and
"code" may also have different meanings in each
compiler. Beware of other compiler differences. Check the
compiler reference manuals. </font></p>
<p><font size="2" face="Tahoma">The original Atmel USB Virtual
UART firmware library (from Atmel's website) was written to suit
the Keil compiler, so this might help you to make the necessary
changes to the source code, if you are using the Keil compiler.</font></p>
<p><font size="2" face="Tahoma">Do not modify the USB library
modules (usb_*.c, usb_*.h), except as necessary to suit non-standard
compiler keyword differences (and perhaps 'FOSC', as noted
earlier), unless you fully understand how the USB functions work.</font></p>
<p><font size="2" face="Verdana"><strong>Using USB "virtual
UART" functions in your application</strong></font></p>
<p><font size="2" face="Tahoma">If you want to transmit data via
USB at periodic intervals, the best method is to use the
background task scheduler, named "background_process()"
in eval_c5131. The real-time interrupt routine sets "task
pending" flags at various intervals. The task scheduler
monitors these flags. When a flag is set, a corresponding task
function is called. The task itself clears the flag when the task
is completed. Create new task functions to suit your application.
These can be placed in the main source file, or in a new
dedicated source file. </font></p>
<p><font size="2" face="Tahoma">For example, let's say you want
to send a 16-bit number to the host PC every second. If you are
using HyperTerminal for testing the program (recommended), then
it makes sense to send the data as printable ASCII characters,
not raw binary, so you can view the output. </font></p>
<p><font size="2" face="Tahoma">If using eval_c5131 as a
framework for your program (recommended), note that you cannot
use putch() and getch() for USB I/O, because these functions are
reserved for use by the CLI. You can easily prevent the CLI from
using USB, simply by deleting one line from the main loop (as
shown in the example source file, "example.c"). The CLI
will remain accessible via the RS232 port (UART), for use as a
debugging tool. You'll need two terminal emulators, preferably
running on separate PCs, one for the CLI on RS232, the other for
USB comm's testing with Hyperterminal. If you have only one PC
available, you can run HyperTerminal for USB, and "TeraTerm"
for the CLI on RS232. (TeraTerm is a free download. Try Google.) </font></p>
<p><font size="2" face="Tahoma">The example program ("example.c")
includes additional USB virtual uart "library"
functions, for sending data as ASCII-encoded strings. You can
extend the I/O "library" with your own functions, as
required. A background task, transmit_data_via_usb(), is called
once every second by the "task scheduler", background_process().
When you run the program, you should see a 5-digit decimal number
(counting up in seconds) in the HyperTerminal window. Once you
get this example working, I'm sure you'll be able to extend the
program to serve your particular requirements. </font></p>
<hr>
<p><font size="4" face="Verdana"><strong>MJB</strong></font></p>
<p><font size="2" face="Verdana">2006-09-04</font></p>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -