![]() |
| RabbitCore RCM3900 User's Manual |
3. Running Sample Programs
To develop and debug programs for the RCM3900 (and for all other Rabbit hardware), you must install and use Dynamic C.
3.1 Introduction
To help familiarize you with the RCM3900 modules, Dynamic C includes several sample programs. Loading, executing and studying these programs will give you a solid hands-on overview of the RCM3900's capabilities, as well as a quick start with Dynamic C as an application development tool.
In order to run the sample programs discussed in this chapter and elsewhere in this manual,
- Your RCM3900 must be plugged in to the Prototyping Board as described in Chapter 2, "Getting Started."
- Dynamic C must be installed and running on your PC.
- The programming cable must connect the programming header (J1) on the RCM3900 to your PC.
- Power must be applied to the RCM3900 through the Prototyping Board.
Refer to Chapter 2, "Getting Started," if you need further information on these steps.
Since the RCM3900 runs at 44.2 MHz and is equipped with a fast program execution SRAM, remember to allow the compiler to run the application in the fast program execution SRAM by selecting Code and BIOS in Flash, Run in RAM from the Dynamic C Options > Project Options > Compiler menu.
To run a sample program, open it with the File menu, then compile and run it by pressing F9.
Complete information on Dynamic C is provided in the Dynamic C User's Manual.
3.2 Sample Programs
Of the many sample programs included with Dynamic C, several are specific to the RCM3900. Sample programs illustrating the general operation of the RCM3900, serial communication, and the NAND flash are provided in the
SAMPLES\RCM3900folder. Each sample program has comments that describe the purpose and function of the program. Follow the instructions at the beginning of the sample program.TCP/IP sample programs are described in Chapter 6, "Using the TCP/IP Features." Sample programs for the optional LCD/keypad module that is used on the RCM3900 Prototyping Board are described in Appendix C.
CONTROLLEDS.cDemonstrates use of the digital outputs by having you turn the LEDs on the Prototyping Board on or off from the STDIO window on your PC.Once you compile and run
CONTROLLEDS.C, the following display will appear in the Dynamic C STDIO window.![]()
Press "3" or "4" or "5"or "6" or "7"on your keyboard to select LED DS3 or DS4 or DS5 or DS6 on the Prototyping Board or the USR LED on the RCM3900. Then follow the prompt in the Dynamic C STDIO window to turn the LED on or off.
FLASHLEDS.cDemonstrates assembly-language program by flashing the USR LED on the RCM3900 and LEDs DS3, DS4, DS5, and DS6 on the Prototyping Board.
SWRELAY.cDemonstrates the relay-switching function call using the relay installed on the Prototyping Board by toggling the relay output state via the Dynamic C STDIO window.
TOGGLESWITCH.cUses costatements (cooperative multitasking) to detect switches S2 and S3 using debouncing. The corresponding LEDs (DS3 and DS4) will turn on or off.Once you have loaded and executed these four programs and have an understanding of how Dynamic C and the RCM3900 modules interact, you can move on and try the other sample programs, or begin building your own.
3.2.1 Use of NAND Flash (RCM3900 only)
The following sample programs can be found in the
SAMPLES\RCM3900\NANDFlashfolder.
NOTE These sample programs cannot be run on the RCM3910, which does not have NAND flash installed.
NFLASH_DUMP.CThis program is a utility for dumping the nonerased contents of a NAND flash chip to the Dynamic C STDIO window, and the contents may be redirected to a serial port.When the sample program starts running, it attempts to communicate with the NAND flash chip. If this communication is successful and the main page size is acceptable, the nonerased page contents (non 0xFF) from the NAND flash page are dumped to the Dynamic C STDIO window.
Note that an error message might appear when the first 32 pages (0x20 pages) are "dumped." You may ignore the error message.
NFLASH_ERASE.CThis program is a utility for erasing all the good blocks of a NAND flash device.When the sample program starts running, it attempts to initialize the onboard NAND flash chip. If this initialization is successful, the progress of the blocks being erased is reported in the Dynamic C STDIO window.
NFLASH_INSPECT.CThis program is a utility for inspecting the contents of a NAND flash chip. When the sample program starts running, it attempts to initialize the onboard NAND flash chip. If this initialization is successful, the user can execute various commands to print out the contents of a specified page, clear (set to zero) all the bytes in a specified page, erase (set to FF), or write a specified value or count pattern to specified pages.When you run this sample program, setting the
NFLASH_USEERASEBLOCKSIZEmacro to (0) zero makes the NAND flash driver use smaller (512-byte) chunks of data, which are less tedious to manage in this program than the alternative larger (16K) chunks of data. However, using smaller chunks of data means more NAND flash block erases are required to update all the program pages in an erased block, one per program page written. In contrast, updating all the program pages in an erased block can require only a single block erase when all of the program pages within the erase block are treated as a single large page. See thenf_initDevice()function help for more information.
NFLASH_LOG.CThis program runs a simple Web server that stores a log of hits in the NAND flash. This log can be viewed and cleared from a Web browser by connecting the RJ-45 jack on the RCM3900 to your PC as described in Section 6.1. The sidebar on the next page explains how to set up your PC or notebook to view this log.Before you compile and run this sample program, make any configuration changes to match your requirements. Once you are viewing the results in a Web browser, click the "Source code" link on the Web page to see this sample program's
#ximported file content.Note that this sample program does not use the optimum method of writing to the NAND flash. The inefficiency resulting from the small amount of data written in each append operation is offset somewhat by the expected relative infrequency of these writes, and by the sample program's method of "walking" through the flash blocks when appending data as well as when a log is cleared.
There is little difference in the number of NAND flash block erase operations regardless of whether the
NFLASH_USEERASEBLOCKSIZEmacro to 0 (zero) or 1 (one). It is slightly more efficient to have the NAND flash driver use larger (16K) chunks of data. See thenf_initDevice()function help for more information.
As long as you have not modified the
TCPCONFIG 1macro in the sample program, enter the following server address in your Web browser to bring up the Web page served by the sample program.Otherwise use the TCP/IP settings you entered in the
LIB\TCPIP\TCP_CONFIG.LIBlibrary.3.2.2 Use of miniSD Cards
The following sample program can be found in the
SAMPLES\RCM3900\SD_Flashfolder.
SDFLASH_INSPECT.CThis program is a utility for inspecting the contents of a miniSD Card. When the sample program starts running, it attempts to initialize the miniSD Card on Serial Port B. The following five commands are displayed in the Dynamic C STDIO window if a miniSD Card is found:p print out the contents of a specified page on the miniSD Card
r print out the contents of a range of pages on the miniSD Card
c clear (set to zero) all of the bytes in a specified page
f sets all bytes on the specified page to the given value
t write user-specified text to a selected page
The sample program prints out a single line for a page if all bytes in the page are set to the same value. Otherwise it prints a hex/ASCII dump of the page.
This utility works with the miniSD Card at its lowest level, and writing to pages will likely make the miniSD Card unreadable by a PC. For PC compatibility, you must use the Dynamic C FAT file system module, which allows you to work with files on the miniSD Card in a way that they will be PC-compatible.
SDFLASH_LOG.CThis program demonstrates a simple Web server that stores a log of hits in the miniSD Card's data flash. This log can be viewed and cleared from a Web browsersee theNFLASH_LOG.Csample program for information oh how to access the Web page and configure your PC or workstation.3.2.3 Serial Communication
The following sample programs can be found in the
SAMPLES\RCM3900\SERIALfolder.
FLOWCONTROL.CThis program demonstrates hardware flow control by configuring Serial Port F for CTS/RTS with serial data coming from TxE (Serial Port E) at 115,200 bps. One character at a time is received and is displayed in the STDIO window.To set up the Prototyping Board, you will need to tie TxE and RxE together on the RS-232 header at J14, and you will also tie TxF and RxF together as shown in the diagram.
![]()
A repeating triangular pattern should print out in the STDIO window. The program periodically switches RTS (TxF) flow control on or off to demonstrate the effect of hardware flow control. You may use an oscilloscope to observe the CTS/RTS signals to see flow control operating
PARITY.CThis program demonstrates the use of parity modes by repeatedly sending byte values 0127 from Serial Port E to Serial Port F. The program will switch between generating parity or not on Serial Port E. Serial Port F will always be checking parity, so parity errors should occur during every other sequence.To set up the Prototyping Board, you will need to tie TxE and RxF together on the RS-232 header at J14 as shown in the diagram.
![]()
The Dynamic C STDIO window will display the error sequence.
SIMPLE3WIRE.CThis program demonstrates basic RS-232 serial communication. Lower case characters are sent by TxE, and are received by RxF. The characters are converted to upper case and are sent out by TxF, are received by RxE, and are displayed in the Dynamic C STDIO window.To set up the Prototyping Board, you will need to tie TxE and RxF together on the RS-232 header at J14, and you will also tie RxE and TxF together as shown in the diagram.
![]()
SIMPLE5WIRE.CThis program demonstrates 5-wire RS-232 serial communication by providing flow control (RTS/CTS) on Serial Port F and data flow on Serial Port E.To set up the Prototyping Board, you will need to tie TxE and RxE together on the RS-232 header at J14, and you will also tie TxF and RxF together as shown in the diagram.
![]()
Once you have compiled and run this program, you can test flow control by disconnecting TxF from RxF while the program is running. Characters will no longer appear in the STDIO window, and will display again once TxF is connected back to RxF. (Do not disconnect the data path between TxE and RxE.)
SWITCHCHAR.CThis program transmits and then receives an ASCII string on Serial Ports E and F. It also displays the serial data received from both ports in the STDIO window.To set up the Prototyping Board, you will need to tie TxE and RxF together on the RS-232 header at J14, and you will also tie RxE and TxF together as shown in the diagram.
![]()
Once you have compiled and run this program, press and release S2 on the Prototyping Board to send a message from Serial Port E to Serial Port F; press and release S3 on the Prototyping Board to send a message from Serial Port F to Serial Port E. The data sent between the serial ports will be displayed in the STDIO window.
Two sample programs,
SIMPLE485MASTER.CandSIMPLE485SLAVE.C, are available to illustrate RS-485 master/slave communication. To run these sample programs, you will need a second Rabbit-based system with RS-485the second system may be another RCM3900, or it may be any Rabbit single-board computer or RabbitCore module that supports RS-485 serial communication as long as you use the master or slave sample program associated with that board.Before running either of these sample programs on the RCM3900 assembly, make sure pins 12 and pins 56 are jumpered together on header JP5 to use the RS-485 bias and termination resistors. The sample programs use Serial Port C as the RS-485 serial port, and they use PD7 to enable/disable the RS-485 transmitter.
The RS-485 connections between the slave and master devices are as follows.
- · RS485+ to RS485+
- · RS485 to RS485
- · GND to GND
SIMPLE485MASTER.CThis program demonstrates a simple RS-485 transmission of lower case letters to a slave. The slave will send back converted upper case letters back to the master and display them in the STDIO window. UseSIMPLE485SLAVE.Cto program the slavereset the slave before you runSIMPLE485MASTER.Con the master.
SIMPLE485SLAVE.CThis program demonstrates a simple RS-485 transmission of lower case letters to a master. The slave will send back converted upper case letters back to the master and display them in the STDIO window. Compile and run this program on the slave before you useSIMPLE485MASTER.Cto program the master.3.2.4 Real-Time Clock
If you plan to use the real-time clock functionality in your application, you will need to set the real-time clock. Set the real-time clock using the Dynamic C
SAMPLES\RTCLOCK\SETRTCKB.Csample program by following the onscreen prompts. The Dynamic CSAMPLES\RTCLOCK\RTC_TEST.Csample program provides additional examples of how to read and set the real-time clock.3.2.5 Other Sample Programs
Section 6.6 describes the TCP/IP sample programs, and Appendix C.7 provides sample programs for the optional LCD/keypad module that can be installed on the Prototyping Board.
| RabbitA Digi International Brand www.rabbit.com |