This tutorial covers the details of Blinking an LED on the TRK-MPC5604B: MPC5604B StarterTRAK evaluation board. It will introduce the evaluation board, and some basic CodeWarrior features.
In this exercise students will run sample code and build an application which enables testing of the Qorivva TRK-MPC5604B board.
Students will:
To successfully complete this exercise, students will need the following board and development environment.
Read the MCU 101: LEDs article for general information on LED circuits.
The LED's are located on the board and visible in the board schematic on page 4 as below:
This schematic is found here.
There are several steps necessary to prepare the evaluation board and PC for microcontroller programming and development. Interfacing the evaluation board with a PC requires downloading and installing the CodeWarrior IDE, as well as the device drivers for programming the microcontroller via USB.
Before completing this example project, download and install CodeWarrior for MPC56xx 2.8 or the latest version.
In addition to CodeWarrior, it may (needs verified) be necessary to install one or both of the following tools:
To use the Hyperterminal communications features described in the following sections and in the attached sample code you must populate the U5 on your TRK-MPC5604B board.
To use hyperterminal style debugging through the Serial port you must populate U5 with a RS232 transceiver and C55.
In the project menu select MAKE (or F7) you will get few warning messages and can ignore them. Next select Debug option (or F5) from project menu. The debug window opens with few sub windows such as Code, Status and CPU etc. To run the program, select the Source GO menu button.
Note: Much of the code in the sample file is utilized to send and receive messages serially. Some quick, minor changes can be applied as follows:
Open main.c
within the for loop, remove or comment out all the code. Now, manually call the specific function desired, in this case:
for (; ; )
{
LED();
}
In sample.mcp project manager window target selection window is set to the default RAM. This means the code runs in the RAM. This target option can be changed using the drop down menu to internal_FLASH. This means the code runs in the flash and this code can run without debugger when the board is powered up. You can select either RAM target or internal_FLASH target for the following test procedure. If you select internal_FLASH target you can test the standalone operation of the board.
If you encounter errors, look in the Problems view and resolve them. You can ignore any warnings.
If the project builds correctly, it is time to download to the board and watch it work. Ensure that the USB cable that came with the board connects the board to the host computer’s USB port.
There are multiple ways to issue the Debug command. Right click the project in the projects view and choose Debug As->CodeWarrior Download. Alternatively, y go to the Run menu and choose Debug (F11).
Within the sample code, there is a for loop which calls a switch statement. With working hyper-terminal and proper serial connector interface into a PC, entering the numerical characters "1" - "9" into the hyper-terminal will call each separate function initiating the following actions
(hyperterminal code documentation needs verified )
TransmitData("\n\r**The Freescale Cup**"); TransmitData("\n\r*********************"); TransmitData("\n\r1.Led\n\r"); TransmitData("2.Switch\n\r"); TransmitData("3.Servo\n\r"); TransmitData("4.Motor Left\n\r"); TransmitData("5.Motor Right\n\r"); TransmitData("6.Camera\n\r"); TransmitData("7.Left Motor Current\n\r"); TransmitData("8.Right Motor Current"); TransmitData("\n\r**********************"); option = ReadData(); option = 1; switch(option) { case '1': LED(); break; case '2': SWITCH(); break; case '3': SERVO(); break; case '4': MOTOR_LEFT(); break; case '5': MOTOR_RIGHT(); break; case '6': CAMERA(); break; case '7': LEFT_MOTOR_CURRENT(); break; case '8': RIGHT_MOTOR_CURRENT(); break; default: break; }
As visible from the schematic - the LED's are accessed via the following ports.
Hardware | Chip Port/Pin | Comment |
---|---|---|
LED1 | PE4 | |
LED2 | PE5 | |
LED3 | PE6 | |
LED4 | PE7 |
The following function is utilized in the code to blink the LED's
This function is located in main.c
void LED(void) { SIU.PCR[68].R = 0x0200; /* Program the drive enable pin of LED1 (PE4) as output*/ SIU.PCR[69].R = 0x0200; /* Program the drive enable pin of LED2 (PE5) as output*/ SIU.PCR[70].R = 0x0200; /* Program the drive enable pin of LED3 (PE6) as output*/ SIU.PCR[71].R = 0x0200; /* Program the drive enable pin of LED4 (PE7) as output*/ TransmitData("****Led Test****\n\r"); TransmitData("All Led ON\n\r"); Delayled(); SIU.PGPDO[2].R |= 0x0f000000; /* Disable LEDs*/ SIU.PGPDO[2].R &= 0x07000000; /* Enable LED1*/ TransmitData("Led 1 ON\n\r"); Delayled(); SIU.PGPDO[2].R |= 0x08000000; /* Disable LED1*/ SIU.PGPDO[2].R &= 0x0b000000; /* Enable LED2*/ TransmitData("Led 2 ON\n\r"); Delayled(); SIU.PGPDO[2].R |= 0x04000000; /* Disable LED2*/ SIU.PGPDO[2].R &= 0x0d000000; /* Enable LED3*/ TransmitData("Led 3 ON\n\r"); Delayled(); SIU.PGPDO[2].R |= 0x02000000; /* Disable LED3*/ SIU.PGPDO[2].R &= 0x0e000000; /* Enable LED4*/ TransmitData("Led 4 ON\n\r"); Delayled(); SIU.PGPDO[2].R |= 0x01000000; /* Disable LED4*/ }
Code Details:
From viewing the user manual, under Functional port pin descriptions, it is
Within the main find the infinite for loop.
for ( ; ; )
{
}
loop of Main.c, remove all code, and add the LED's with the following function:
for(;;)
{
LED();
}
To alter the behavior of the LEDs, change the function itself, or pull specific code from the function and insert it within loops of a program for testing purposes.
LED's are often used for testing important parts of an algorithm. By connecting an oscilloscope to a LED, it is possible to test the duration of a key algorithm, or to verify if signal timing is as expected along with the visual cue.
TRK-MPC5064B Freescale Webpage
TRK-MPC5064B Freescale Reference Manual
TRK-MPC5064B Freescale Schematic
Getting errors for this code while debugging ....How to overcome this..?