Spi interface, User i/o devices – Digilent 410-185P-KIT User Manual
Page 9

Cerebot MC7 Reference Manual
www.digilentinc.com
page 9 of 21
Copyright Digilent, Inc. All rights reserved. Other product and company names mentioned may be trademarks of their respective owners.
plus access to the output compare units and
two of the input capture units.
Digilent Pmod peripheral modules can either
be plugged directly into the connectors on the
Cerebot MC7 or attached via cables. Digilent
has a variety of Pmod interconnect cables
available.
See the “Connector and Jumper Block Pinout
Tables” section below for more information
about connecting peripheral modules and other
devices to the Cerebot MC7.
These tables
indicate the mapping between pins on the
dsPIC microcontroller and the pins on the
various connectors.
SPI Interface
SPI is a four-wire synchronous serial
communications interface used by many
microcontrollers and peripheral devices.
The SPI interface is made up of the following
four signals generally called: SS (slave select),
MOSI (master out/slave in), MISO (master
in/slave out), and SCK (serial clock). On the
dsPIC microcontroller, the SPI signals are
called SS (slave select), SDO (serial data out),
SDI (serial data in), and SCK (serial clock).
When an SPI master device communicates
with a slave device, it initiates the
communication by bring the SS line low. This
enables the slave device to receive the data.
The master device then sends one or more
bytes to the slave. The data is shifted serially
out the MOSI pin to the slave. The slave
device simultaneously shifts out a byte to the
master on MISO. Each time a byte is sent from
the master to the slave, a byte is sent from the
slave to the master. The master generates the
serial clock on the SCK line, and the slave
uses that as the clock to shift the data in and
out. When the master has finished sending
data to the slave, it ends the transaction by
bringing the SS line high.
The dsPIC microcontroller used on the Cerebot
MC7 provides two SPI controllers. One of
these controllers (SPI2) is available for use on
Pmod connector JB. This SPI controller can be
used as either an SPI master or an SPI slave.
The other SPI controller (SPI1) is available on
Pmod connector JA. The SS signal for SPI1 is
not available at connector JA, and therefore
SPI1 can only be used as an SPI master.
When using SPI1, PORTD bit 9 (RD9) is used
to drive the SS signal of the connected SPI
slave.
Jumpers JP2 and JP3 are used to select
whether SPI2 on connector JB is operating as
an SPI master of as an SPI slave. For
operation as an SPI master, JP2 (SDI2) is
placed in the MISO position (to the left), and
JP3 (SDO2) is placed in the MOSI position (to
the right). For operation as an SPI slave, JP2
is placed in the MOSI position and JP3 is
placed in the MISO position.
M
IS
O
S
D
I2
SPI Master
SPI Slave
M
O
S
I
JP2
JP3
M
IS
O
S
D
I2
M
O
S
I
JP2
JP3
S
D
O
2
S
D
O
2
Jumper Settings for SPI
Refer to the data sheet for the dsPIC
microcontroller and the dsPIC33F Family
Reference Manual for detailed information on
configuring and using the SPI interfaces.
User I/O Devices
The Cerebot MC7 board provides two push
button switches for user input and four discrete
LEDs for output. The buttons, BTN1 and
BTN2 are connected to I/O pins RB8 and
RB14 respectively. To read the buttons, bits 8
and/or 14 of PORTB must be set as inputs by
setting the corresponding bits in the TRISB
register and then reading the PORTB register.
When a button is pressed, the corresponding
bit will be high (‘1’).
The four LEDs are connected to bits 4-7 of
PORTD. LED 1 is connected to bit 4, LED 2 is
connected to bit 5, and so on. To use the