![]() |
| RabbitCore RCM4100 User's Manual |
3. Running Sample Programs
To develop and debug programs for the RCM4100 series (and for all other Rabbit Semiconductor hardware), you must install and use Dynamic C. This chapter provides a tour of its major features with respect to the RCM4100 series.
3.1 Introduction
To help familiarize you with the RCM4100 series of modules, Dynamic C includes several sample programs. Loading, executing and studying these programs will give you a solid hands-on overview of the RCM4100 series' capabilities, as well as a quick start with Dynamic C as an application development tool.
NOTE The sample programs assume that you have at least an elementary grasp of ANSI C. If you do not, see the introductory pages of the Dynamic C User's Manual for a suggested reading list. In order to run the sample programs discussed in this chapter and elsewhere in this manual,
- Your module 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 on the module to your PC.
- Power must be applied to the module through the Prototyping Board.
Refer to Chapter 2, "Getting Started," if you need further information on these steps.
To run a sample program, open it with the File menu (if it is not still open), then compile and run it by pressing F9.
Each sample program has comments that describe the purpose and function of the program. Follow the instructions at the beginning of the sample program.
More 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 RCM4100 series of modules. These programs will be found in the
-SAMPLES\RCM4100folder.
CONTROLLED.CDemonstrates use of the digital outputs by having you turn LEDs DS2 and DS3 on the Prototyping Board on or off from the STDIO window on your PC.Parallel Port B bit 2 = LED DS2
Parallel Port B bit 3 = LED DS3Once you compile and run
CONTROLLED.C, the following display will appear in the Dynamic C STDIO window.![]()
Press "2" or "3" on your keyboard to select LED DS2 or DS3 on the Prototyping Board. Then follow the prompt in the Dynamic C STDIO window to turn the LED ON or OFF. A logic low will light up the LED you selected.
FLASHLED1.Cdemonstrates the use of assembly language to flash LEDs DS2 and DS3 on the Prototyping Board at different rates. Once you have compiled and run this program, LEDs DS2 and DS3 will flash on/off at different rates.
FLASHLED2.Cdemonstrates the use of cofunctions and costatements to flash LEDs DS2 and DS3 on the Prototyping Board at different rates. Once you have compiled and run this program, LEDs DS2 and DS3 will flash on/off at different rates.
LOW_POWER.Cdemonstrates how to implement a function in RAM to reduce power consumption by the Rabbit microprocessor. There are four features that lead to the lowest possible power draw by the microprocessor.1. Run the CPU from the 32 kHz crystal.
2. Turn off the high-frequency crystal oscillator.
4. Ensure that internal I/O instructions do not use CS0.
Once you are ready to compile and run this sample program, use <Alt-F9> instead of just F9. This will disable polling, which will allow Dynamic C to continue debugging once the target starts running off the 32 kHz oscillator.
This sample program will toggle LEDs DS2 and DS3 on the Prototyping Board. You may use an oscilloscope. DS2 will blink the fastest. After switching to low power, both LEDs will blink together.
TAMPERDETECTION.Cdemonstrates how to detect an attempt to enter the bootstrap mode. When an attempt is detected, the battery-backed onchip-encryption RAM on the Rabbit 4000 is erased. This battery-backed onchip-encryption RAM can be useful to store data such as an AES encryption key from a remote location.This sample program shows how to load and read the battery-backed onchip-encryption RAM and how to enable a visual indicator.
Once this sample is compiled running (you have pressed the F9 key while the sample program is open), remove the programming cable and press the reset button on the Prototyping Board to reset the module. LEDs DS2 and DS3 will be flashing on and off.
Now press switch S2 to load the battery-backed RAM with the encryption key. The LEDs are now on continuously. Notice that the LEDs will stay on even when you press the reset button on the Prototyping Board.
Reconnect the programming cable briefly and unplug it again. The LEDs will be flashing because the battery-backed onchip-encryption RAM has been erased. Notice that the LEDs will continue flashing even when you press the reset button on the Prototyping Board.
You may press switch S2 again and repeat the last steps to watch the LEDs.
TOGGLESWITCH.Cdemonstrates the use of costatements to detect switch presses using the press-and-release method of debouncing. LEDs DS2 and DS3 on the Prototyping Board are turned on and off when you press switches S2 and S3. S2 and S3 are controlled by PB4 and PB5 respectively.Once you have loaded and executed these five programs and have an understanding of how Dynamic C and the RCM4100 series of modules interact, you can move on and try the other sample programs, or begin building your own.
3.2.1 Serial Communication
The following sample programs are found in the
SAMPLES\RCM4100\SERIALfolder.
FLOWCONTROL.CThis program demonstrates how to configure Serial Port D for CTS/RTS with serial data coming from Serial Port C (TxC) at 115,200 bps. The serial data received are displayed in the STDIO window.To set up the Prototyping Board, you will need to tie TxD and RxD together on the RS-232 header at J4, and you will also tie TxC and RxC together using the jumpers supplied in the Development Kit as shown in the diagram.
![]()
A repeating triangular pattern should print out in the STDIO window. The program will periodically switch flow control on or off to demonstrate the effect of no flow control.
If you have two Prototyping Boards with modules, run this sample program on the sending board, then disconnect the programming cable and reset the sending board so that the module is operating in the Run mode. Connect TxC, TxD, and GND on the sending board to RxC, RxD, and GND on the other board, then, with the programming cable attached to the other module, run the sample program.
PARITY.CThis program demonstrates the use of parity modes by repeatedly sending byte values 0127 from Serial Port C to Serial Port D. The program will switch between generating parity or not on Serial Port C. Serial Port D 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 TxC and RxD together on the RS-232 header at J4 using one of the jumpers supplied in the Development Kit as shown in the diagram.
The Dynamic C STDIO window will display the error sequence.
SERDMA.CThis program demonstrates using DMA to transfer data from the circular buffer to the serial port and vice versa. The Dynamic C STDIO window is used to view or clear the buffer.Before you compile and run the sample program, you will need to connect the RS-232 header at J4 to your PC as shown in the diagram using the serial to DB9 cable supplied in the Development Kit.
![]()
Once you have compiled and run the sample program, start Tera Term or another terminal emulation program to connect to the PC serial port using a baud rate of 115,200 bps. You can observe the output in the Dynamic C STDIO window as you type in Tera Term, and you can also use the Dynamic C STDIO window to clear the buffer.
The Tera Term serial utility can be downloaded from hp.vector.co.jp/authors/VA002416/teraterm.html.
SIMPLE3WIRE.CThis program demonstrates basic RS-232 serial communication. Lower case characters are sent by TxC, and are received by RxD. The characters are converted to upper case and are sent out by TxD, are received by RxC, and are displayed in the Dynamic C STDIO window.![]()
To set up the Prototyping Board, you will need to tie TxD and RxC together on the RS-232 header at J4, and you will also tie RxD and TxC together using the jumpers supplied in the Development Kit as shown in the diagram.
SIMPLE5WIRE.CThis program demonstrates 5-wire RS-232 serial communication with flow control on Serial Port D and data flow on Serial Port C.To set up the Prototyping Board, you will need to tie TxD and RxD together on the RS-232 header at J4, and you will also tie TxC and RxC together using the jumpers supplied in the Development Kit as shown in the diagram.
![]()
Once you have compiled and run this program, you can test flow control by disconnecting TxD from RxD while the program is running. Characters will no longer appear in the STDIO window, and will display again once TxD is connected back to RxD.
If you have two Prototyping Boards with modules, run this sample program on the sending board, then disconnect the programming cable and reset the sending board so that the module is operating in the Run mode. Connect TxC, TxD, and GND on the sending board to RxC, RxD, and GND on the other board, then, with the programming cable attached to the other module, run the sample program. Once you have compiled and run this program, you can test flow control by disconnecting TxD from RxD as before while the program is running.
SWITCHCHAR.CThis program demonstrates transmitting and then receiving an ASCII string on Serial Ports C and D. 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 TxD and RxC together on the RS-232 header at J4, and you will also tie RxD and TxC together using the jumpers supplied in the Development Kit as shown in the diagram.
![]()
Once you have compiled and run this program, press and release switches S2 and S3 on the Prototyping Board. The data sent between the serial ports will be displayed in the STDIO window.
IOCONFIG_SWITCHECHO.CThis program demonstrates how to set up Serial Ports E and F, which then transmit and then receive an ASCII string when switch S2 or S3 is pressed. The echoed serial data are displayed in the Dynamic C STDIO window.Note that the I/O lines that carry the Serial Port E and F signals are not the Rabbit 4000 defaults. The Serial Port E and F I/O lines are configured by calling the library function
serEFconfig()that was generated by the Rabbit 4000IOCONFIG.EXEutility program.Serial Port E is configured to use Parallel Port E bits PE6 and PE7. These signals are available on the Prototyping Board's Module Extension Header (header J2).
Serial Port F is configured to use Parallel Port C bits PC2 and PC3. These signals are available on the Prototyping Board's RS-232 connector (header J4).
Serial Port D is left in its default configuration, using Parallel Port C bits PC0 and PC1. These signals are available on the Prototyping Board's RS-232 connector (header J4). Serial Port D transmits and then receives an ASCII string with Serial Port F when switch S3 is pressed.
Also note that there are two libraries generated by
IOCONFIG.EXEin the Dynamic CSAMPLES\RCM4100\SERIALfolder for the 29 MHz RCM4110 and the 58 MHz RCM4100 and RCM4120.To set up the Prototyping Board, you will need to tie TxD and RxC together and tie TxC and RxD together on the RS-232 header at J4 using the jumpers supplied in the Development Kit; you will also tie TxE (PE6) and RxE (PE7) together with a soldered wire or with a wire jumper if you have soldered in the IDC header supplied with the accessory parts in the Development Kit.
![]()
Once you have compiled and run this program, press and release switches S2 or S3 on the Prototyping Board. The data echoed between the serial ports will be displayed in the STDIO window.
3.2.2 A/D Converter Inputs (RCM4100 only)
The following sample programs are found in the
SAMPLES\RCM4100\ADCfolder.
AD_CAL_ALL.CDemonstrates how to recalibrate all the single-ended analog input channels with one gain using two known voltages to generate the calibration constants for each channel. The constants will be written into the user block data area.Connect a positive voltage from 020 V DC (for example, the power supply positive output) to analog input channels LN0INLN6IN on the Prototyping Board, and connect the ground to GND. Use a voltmeter to measure the voltage, and follow the instructions in the Dynamic C STDIO window once you compile and run this sample program. Remember that analog input LN7 on the Prototyping Board is used with the thermistor and is not be used with this sample program.
NOTE The above sample program will overwrite the existing calibration constants.
AD_CAL_CHAN.CDemonstrates how to recalibrate one single-ended analog input channel with one gain using two known voltages to generate the calibration constants for that channel. The constants will be rewritten into the user block data area.Connect a positive voltage from 020 V DC (for example, the power supply positive output) to an analog input channel on the Prototyping Board, and connect the ground to GND. Use a voltmeter to measure the voltage, and follow the instructions in the Dynamic C STDIO window once you compile and run this sample program. Remember that analog input LN7 on the Prototyping Board is used with the thermistor and is not be used with this sample program.
NOTE The above sample program will overwrite the existing calibration constants for the selected channel.
AD_RDVOLT_ALL.CDemonstrates how to read all single-ended A/D input channels using previously defined calibration constants. The constants used to compute equivalent voltages are read from the user block data area, so the sample program cannot be run using the "Code and BIOS in RAM" compiler option.Compile and run this sample program once you have connected a positive voltage from 020 V DC (for example, the power supply positive output) to analog input channels LN0INLN6IN on the Prototyping Board, and ground to GND. Follow the prompts in the Dynamic C STDIO window. Raw data and the computed equivalent voltages will be displayed. Remember that analog input LN7 on the Prototyping Board is used with the thermistor and is not be used with this sample program.
AD_SAMPLE.CDemonstrates how to how to use a low level driver on single-ended inputs. The program will continuously display the voltage (averaged over 10 samples) that is present on an A/D converter channel (except LN7). The constants used to compute equivalent voltages are read from the user block data area, so the sample program cannot be run using the "Code and BIOS in RAM" compiler option.Compile and run this sample program once you have connected a positive voltage from 020 V DC to an analog input (except LN7) on the Prototyping Board, and ground to GND. Follow the prompts in the Dynamic C STDIO window. Raw data and the computed equivalent voltages will be displayed. If you attach a voltmeter between the analog input and ground, you will be able to observe that the voltage in the Dynamic C STDIO window tracks the voltage applied to the analog input as you vary it.
THERMISTOR.CDemonstrates how to use analog input LN7 to calculate temperature for display to the Dynamic C STDIO window. This sample program assumes that the thermistor is the one included in the Development Kit whose values for beta, series resistance, and resistance at standard temperature are given in the part specification.Install the thermistor at location JP25 on the Prototyping Board before running this sample program. Observe the temperature changes shown in the Dynamic C STDIO window as you apply heat or cold air to the thermistor.
3.2.2.1 Downloading and Uploading Calibration Constants
The Tera Term utility called for in these sample programs can be downloaded from hp.vector.co.jp/authors/VA002416/teraterm.html.
These sample programs must be compiled to flash memory. To do so, select Options > Project Options in Dynamic C, then select the "Compiler" tab, and select "Code and BIOS in Flash" for the BIOS Memory Setting.
Before you compile and run these sample programs, you will also need to connect the RS-232 header at J4 to your PC as shown in the diagram using the serial to DB9 cable supplied in the Development Kit.
![]()
DNLOADCALIB.CDemonstrates how to retrieve analog calibration data to rewrite it back to the user block using a terminal emulation utility such as Tera Term.Start Tera Term or another terminal emulation program on your PC, and configure the serial parameters as follows.
Now compile and run this sample program. Verify that the message "Waiting, Please Send Data file" message is being display in the Tera Term display window before proceeding.
Within Tera Term, select File-->Send File-->Path and filename, then select the OPEN option within the dialog box. Once the data file has been downloaded, Tera Term will indicate whether the calibration data were written successfully.
UPLOADCALIB.CDemonstrates how to read the analog calibration constants from the user block using a terminal emulation utility such as Tera Term.Start Tera Term or another terminal emulation program on your PC, and configure the serial parameters as follows.
Follow the remaining steps carefully in Tera Term to avoid overwriting previously saved calibration data when using same the file name.
Tera Term is now ready to log all data received on the serial port to the file you specified.
You are now ready to compile and run this sample program. A message will be displayed in the Tera Term display window once the sample program is running.
Enter the serial number you assigned to your RabbitCore module in the Tera Term display window, then press the ENTER key. The Tera Term display window will now display the calibration data.
Now select CLOSE from within the Tera Term LOG window, which will likely be a separate pop-up window minimized at the bottom of your PC screen. This finishes the logging and closes the file.
Open your data file and verify that the calibration data have been written properly. A sample is shown below.
3.2.3 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
SETRTCKB.Csample program from the Dynamic CSAMPLES\RTCLOCKfolder, using the onscreen prompts. TheRTC_TEST.Csample program in the Dynamic CSAMPLES\RTCLOCKfolder provides additional examples of how to read and set the real-time clock.
| Rabbit Semiconductor www.rabbit.com |