Mbedweek 8
Mbedweek 8
Experiment 7
SPI PROTOCOL
Date: 14-9-2018
General information:
The mbed NXP LPC11U24 Microcontroller in particular is designed for prototyping low
cost USB devices, battery powered applications and 32-bit ARM® Cortex™-M0 based
designs. It is packaged as a small DIP form-factor for prototyping with through-hole
PCBs, stripboard and breadboard, and includes a built-in USB FLASH programmer.
The switch and LED are grounded along with the GND terminal of the microcontroller. The
supply given was the regulated 3.3 V supply. The I/O ports are from p5 to p30.
External components:
API Used:
For DAC:
AnalogIn ain(p20);
Serial pc(USBTX,USBRX);
Serial bt(p9,p10);
For delay:
API’s for
Slave:
The SPI interface:
–Default mode of 0
TASK 1:
Question:
Set the mbed up as Master, and exchanges data with a slave, sending its own switch
positions, and displaying those of the slave using LEDs.
Code:
MASTER
#include "mbed.h"
while(1) { switch_word=0xa0;
if(switch_ip1==1)
switch_word=switch_word|0x01;
if(switch_ip2==1)
switch_word=switch_word|0x02; cs=0;
recd_val=ser_port.write(switch_word);
cs=1;
wait(0.01);
led1=0;
led2=0; recd_val=recd_val&0x03;
if(recd_val==1)
SLAVE
#include "mbed.h"
SPISlave ser_port(p11,p12,p13,p14);
DigitalOut led1(p21);
while(1) { switch_word=0xa0;
if(switch_ip1==1)
switch_word=switch_word|0x01;
if(switch_ip2==1)
switch_word=switch_word|0x02;
if(ser_port.receive())
{
recd_val=ser_port.read();
ser_port.reply(switch_word);
led1=0;
led2=0; recd_val=recd_val&0x03;
if(recd_val==1)
led1=1;
led2=1;
Output:
TASK 2:
Question:
Display text typed into the MASTER terminal application on to the slave serial terminal.
Code:
MASTER
#include "mbed.h"
SPI ser_port(p11,p12,p13);
Serial pc(USBTX,USBRX);
DigitalOut cs(p14); char c;
recd_val=ser_port.write(c); cs=1;
wait(0.01);
SLAVE
#include "mbed.h"
SPISlave ser_port(p11,p12,p13,p14);
Serial pc(USBTX,USBRX);
int main()
{
while(1)
if(ser_port.receive())
recd_val = ser_port.read();
pc.printf("%c",recd_val);
}
Output:
-
MASTE
R
- SLAVE
Verification:
Result:
Thus, the SPI protocol is followed using the mbed board. The tasks given are
completed and its corresponding outputs are shown.