How do I set up an MPC5xx IO port to collect data?

At Rapita, our main interest in writing to output ports of microcontrollers is to provide an efficient means of measuring code execution times or code coverage (via our RapiTime or RapiCover tools – both part of RVS). Typically, we’d have some way of logging the values written to the output port, for example the RTBx or a logic analyzer.

In common with many microcontrollers, the Freescale MPC5xx series microcontroller has a number of ports that can be configured for general purpose digital input or output, or other specific purposes. Possibilities for output ports include:

  • Queued Analog to Digital Converter Module (QADCM)
  • Queued Serial Multi Channel Module (QSMCM)
  • Modular IO System (MIOS) Parallel Port IO Submodule (MPIOSM)

Before data can be output through any port it is first necessary to:

  1. initialize the output pins as general purpose IO
  2. configure the port as output rather than input
  3. set the pin characteristics to match the signal being generated

Each IO port will have a number of associated registers that control the operation of that port that need to be set appropriately.

Within RVS, we normally initialize ports within the RVS_Init() routine, which must be called before any instrumentation is executed. To illustrate the configuration of one of the ports, we show an example RVS_Init() routine.

Most compilers are supplied with address definitions that allow register names to be used directly in the source code, however check your compiler and CPU documentation to be sure.

Here we consider how an instrumentation library can be written to output values through the QADCM. There are two QADC modules, each of which contain a pair of 8 bit ports that can be configured for output. The example RVS_Init() below shows how to initialise port A on QADC module A for output:

void RVS_Init()
   UMCR = 0;              /* high bus frequency       */
   PDMCR = 0x80000000uL;  /* normal slew rate for QAD */
   PORTQA_A = 0;          /* Initialise pins low      */
   DDRQA_A = 0xFF;        /* Set as output            */

The registers used are as follows:

  • UMCR UIMB Module Configuration Register. Used to configure the U-BUS to IMB3 interface to run at full speed.
  • PDMCR Pad Module Configuration Register. Used to set normal rather than slow slew rate.
  • PORTQA_A Port Data Register for port A on QADC module A.
  • DDRQA_A Port Data Direction Register for port A on QADC module A.

Once the port has been initialised, values can be written via the Port Data Register. For example, in RVS, instrumentation point IDs can be written by including the following definition in rvs_ipoint.h:

#define RVS_I( I ) ((void)(PORTQA_A = (I)))

Receive our blog by email