Beruflich Dokumente
Kultur Dokumente
pc025c boards.
1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.3 Connections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2 Firmware Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1
2
Chapter 1
Introduction
This document describes how to use the interface to communicate with the board KL25Z via
serial interface (Universal Serial Bus (USB)) and to configure the boards pc052c.
The firmware should be considered ”work in progress” and therefore subject to changes; it
is recommended to take this into account when using this manual: despite all the efforts to
maintain it up to date, there might be last minute changes in the code that are not described in
the documentation.
The board pc052c hosts a serial interfaced I/O expander MAX7301A. The expander has 16 ports
that can be configured independently as either digital inputs or outputs. The configuration is
performed using a Serial Peripheral Interface (SPI) bus. Note that there are 4 more ports which
have been attached to LEDs(and not the header) for testing purposes.
For the purpose of the serial communication, the MAX7301A (and hence the pc052c) is seen
as a slave so it must receive Serial Clock Line (SCL) and be selected via the slave select line.
The serial data is loaded in the MAX7310A via the Master Out Slave In (MOSI). The chip can
also output and echo of the loaded data or respond to queries by sending data on the Master In
Slave Out (MISO) line. The expander ports are directly connected to the 20-way header J2; the
remaining four pins on the header (1, 6, 11 and 16) are connected to ground.
The board also host a bi-directional level translator MAX3378EEUD that translates the sig-
nals from 3.3 V digital to 5 V digital. From the point of view of the SPI bus, this component is
3
4
completely transparent and can be ignored. The signals required for the SPI bus are fed to the
The board requires two different voltage rails: P3V3 and P5V, supplied via the 3-way con-
Any SPI-capable device can be used as a master to configure the MAX7310A; in the cur-
rent setup the role of master is performed by a KL25Z development platform. The firmware
loaded on the KL25Z interpret the commands received over the USB interface and configures
FRDM-KL25Z is a powerful microprocessor board. However, there are a lot of subtleties involved
in its setup. The driver and firmware for the board can be found at -
http://www.pemicro.com/opensda/
It is highly recommend to not install the driver/firmware from the mbed website. Also, it
should be made sure that the firmware as well as the driver are of the same type - either PEMicro
Most of the resources available on SPI on the internet are for interactions with one slave only
and for this very reason it is not advised to follow everything that you might find on online forums.
For SPI interfacing, KL25Z offers two ”channels”, SPI0 and SPI1. Unfortunately, all the
eight boards cannot be interfaced via the same SPI channel just because there are not enough
pins for any one of the two channels. Boards 1 to 5 are interfaced via SPI0 and 6 to 8 via SPI1 as
a result. The triplet (MOSI, MISO, CLK) for any board should belong to the same SPI channel.
You cannot have, for example, a MOSI pin from SPI0 and a MISO pin from SPI1for the same
board. You will break the system if you do so. So, if at any time it is required to change pins as
from what set at the moment, this should be kept in mind. This sheet with pinout descriptions
https://ece.uwaterloo.ca/~ece222/Freescale/FRDM-KL25Z-Pinouts-Rev1.pdf
5
Figure 1.1: Schematic overview of the setup used to configure pc052c via SPI bus.
1.3 Connections
The connection between any pc052c and KL25Z requires four lines (clock, data in, data out,
slave select) and a ground reference. With the current version of the firmware, the pins are
Ideally, it should have been possible for boards 1 to 5 to have the same (MOSI, MISO, CLK)
lines and 6 to 8 to have the same lines (recall SPI0 and SPI1 due to which we cannot have same
lines for all boards). However, after testing it was found that having the same MISO lines for
more than 1 board led to erratic behaviour where the MISO voltage level would be around 1V
where ideally it should have been 3.3V. For this very reason, MISO lines for all the boards were
made different. MOSI is PTD2 for boards 1 to 5 and PTE3 for 6 to 8. Similarly, CLK is PTD1
KL25Z pc052c
SIGNAL NAME PIN NAME SIGNAL NAME BOARD(S)
gnd GND GND All
mosi PTD2 SDI Board 1
miso PTD3 SDO Board 1
sclk PTD1 SCLK Board 1
slave select PTD5 CSN Board 1
mosi PTD2 SDI Board 2
miso PTC6 SDO Board 2
sclk PTD1 SCLK Board 2
slave select PTD0 CSN Board 2
mosi PTD2 SDI Board 3
miso PTC7 SDO Board 3
sclk PTD1 SCLK Board 3
slave select PTE4 CSN Board 3
mosi PTD2 SDI Board 4
miso PTA16 SDO Board 4
sclk PTD1 SCLK Board 4
slave select PTC5 CSN Board 4
mosi PTD2 SDI Board 5
miso PTA17 SDO Board 5
sclk PTD1 SCLK Board 5
slave select PTB10 CSN Board 5
mosi PTE3 SDI Board 6
miso PTD7 SDO Board 6
sclk PTE2 SCLK Board 6
slave select PTB11 CSN Board 6
mosi PTE3 SDI Board 7
miso PTE1 SDO Board 7
sclk PTE2 SCLK Board 7
slave select PTD4 CSN Board 7
mosi PTE3 SDI Board 8
miso PTD6 SDO Board 8
sclk PTE2 SCLK Board 8
slave select PTC4 CSN Board 8
Firmware Installation
An account on the mbed web-site is required to access the software. Once the software is in the
mbed developer page, it is possible to compile it and download the resulting .bin file directly
onto the board. This operation will re-write the firmware so that at the next reset the board
will have the latest version. The board will retain the firmware until you add another one to it.
Two versions of the firmware have been prepared. First is user friendly to be run using a
terminal shell. It is very fault tolerant and interactive. One can send various manual commands
The other version is minimalistic, only meant to be used with LabVIEW. This one is not
at all fault tolerant and can be a bit painful at times. Extreme caution to be taken while
sending commands to the board. It is always possible to reset the KL25Z board but never
recommended as then all the amplifiers will go through a power cycle of switching off and then
on. Unfortunately, it is not possible to use the firmwares interchangeably as both of them work
on different algorithms.
In the SPI protocol data are output on the MOSI line which is connected to all the slaves. In
order to select which slave is the recipient of the data, a slave select line, which is individual
9
10
for each slave, is driven low before the transmission begins, indicating to the device that the
incoming stream of data should be loaded onto its internal registers. A clock line, also shared
across the slaves, provides the timing reference. There are several sources of documentation
The core function used to send data over the SPI bus in this project is mySPISend, defined in the
spi functions.cpp file. Note that the KL25Z board uses an 8-bit bus, while the MAX7301A
expects 16-bit words to be loaded in its registers. For this reason, each write operation is actually
performed in two steps, first writing the first 8 MSB and then writing the remaining 8. During
the two operations, the slave select line (which is driven using the sync variable in the code)
remains low.
Once the firmware has been installed on the KL25Z and the board has been rebooted, the board
Starting interface.
The interface is still very ”clunky”. It works but it definitely need some polishing. For instance
at the moment the commands should be submitted using TAB instead of the more intuitive
ENTER key.
A list of the currently available commands and their syntax is provided below.
• exit: stops the execution of the software on the board, preventing it from listening to
further commands2 . The software can be restarted by pressing the reset button on the
boards3 .
• powermode X Y: allows to put the MAX7301A for the board X in shutdown mode (Y=0) or
in active mode (Y=1). According to the manual, when the chip is in shutdown mode:
1 See for instance
https://web.archive.org/web/20150413003534/http://www.ee.nmt.edu/˜teare/ee308l/datasheets/S12SPIV3.pdf
2 Also, leaves the EU.
3 This will not make the board re-join the EU though.
11
all ports are forced to inputs (which can be read), and the pullup current sources
are turned off. Data in the port and control registers remain unaltered so port
configuration and output levels are restored when the MAX7301 is taken out of
shutdown. The display driver can still be programmed while in shutdown mode.
Any value of X other than between 1 and 8 and Y other than 0 or 1 will be discarded.
• configure: this command performs a series of write operations in the MAX7301A registers
to configure its ports as outputs and exit the shutdown mode. The commands are listed
below.
0 x0955 ; // C o n f i g u r e p o r t s P7 , P6 , P5 , P4 a s o u t p u t s
0 x0401 ;
There seems to be a bug in the SPI interface: sometimes, when the configuration script
is run, only half of the ports are correctly configured while the others remain in high-
impedance mode. This seems to happen alternatively, so that if ports P7 - P4 are con-
figured, ports P11 - P8 are not, then P15 - P12 are correctly configured, P19 - P16 are not.
As a workaround, it is possible to manually configure the ports using the send or setport
command.
12
• setport B N X: allows to set port N for board B to be either logic high (X=1) or low (X=0).
N is an integer number in the range [12, 31] where 12-15 are just LEDs and 16-31 are actual
amplifiers.B is an integer number in the range [1,8]. The user should take care to ensure
that the port is already configured as an output before using this command.
• pullallup: Pulls all the ports in all the boards up(5 V). This is a useful command as
after configuration of ports as outputs, all the amplifiers are on and that draws a lot of
• pullalldown: Pulls all the ports in all the boards down(0 V). Pulling down the ports
• pullup X: Pulls all the ports up in board X. X has to be an integer in the range [1,8].
• pulldown X: Pulls all the ports down in board X. X has to be an integer in the range [1,8].
• send B XXXX: writes a (16-bit) word to the SPI slave B. The word must be typed in hexa-
decimal format, without base specifier (i.e. use XXXX= F31C and not 0xF31C). No check is
performed on the word so the user should pay attention to avoid sending illegal commands
• read B XXXX: reads a 16-bit word from the board B. This is a useful tool for deep level
debugging as if and when working with many boards, it would be tough to tell if and which
Once the firmware has been installed on the KL25Z and the board has been rebooted, the board
Starting interface.
From this moment it is possible to send commands to the board. However, it is highly probable
that LabVIEW will not show you this output. Do not worry, we have another layer of feedback.
Any command sent via the LabVIEW interface should be of the form xxxx\n or xxxx\tyy\n
or xxxx\tyy\tzz\n where xxxx is the command and yy and zz are integer parameters depending
upon what the command is. The essence is that different strings(if more than 1) should be
separated by \t and should always end with \n. Please do not break this rule or all hell will
break loose. If you do not end your commands with a \n it will take in the first 20 characters
13
as a command and execute it. The further characters will be followed on as the next command.
If the number of characters entered is less than 20 and there is no \n as well, the characters will
just stay stored in the buffer unless you complete 20 characters. The first layer of response from
the board after you send any command to it is just an echo echo: xxxx yy zz for a command
xxxx\tyy\tzz\n. Note how it does not actually display the tabs and end of line codes. This is
Because this firmware is not supposed to be used as a direct form of communication but via
labVIEW, the board does not talk a lot back with you and the output is just 2 layered. The first
layer is the receipt of the command and the second is the response to your command. Another
catch is that the boards have already been set to active mode and all the ports have been con-
figured as outputs with the amplifiers switched OFF. This makes reseting the board a very bad
idea as the whole cycle will then be repeated. For this very reason, you have to be very cautious
while entering the commands. Your best bet is to send a random statement ending with \n so
A list of the currently available commands and their syntax is provided below.
• powermode\tX\tY\n: Same action as in firmware 1. Note that all the boards would have
already been set to powermode 0 followed by their configuration when the KL25Z starts.
• configure\n: Same action as in firmware 1. Note that this command would automatically
arises due to reduction of number of arguments from 3 to 2 due to various reasons. Instead
of choosing the board, the port numbers have been mapped as ((X-1) modulo 16) + 1.
Which means ports 1 to 16 have been mapped to board 1, 17 to 31 to board 2 and so on.
14
Consequently, the LEDs in the boards cannot be controlled this way and in total there are
128 ports only. X has to be an integer lying in [1,128] and Y has to be an either 0 or 1.