Professional Documents
Culture Documents
Embedded Lab 05
Embedded Lab 05
Embedded Lab 05
Observations
There was one main task in this lab. We had to communicate between the Arduino Uno
and STM32F429I Disc. using SPI and I2C protocols. The Arduino Uno was SPI Master
that was sending the its state to STM32F429 and it was acting as I 2C slave.
The state diagram was given and with the help of it we were able to code the logic.
CODE:
#include "mbed.h"
SPISlave spi_slave(PA_7, PA_6, PA_5, PA_4); // mosi, miso, sclk, ssel
char mood[10];
int main() {
spi_slave.reply(0x00); //first reply
while(1){
if(button_c.read()==1)
{
i2c.write(addr8bit, c1, 2);
}
if(button_c.read()==0)
{
i2c.write(addr8bit, c2, 2);
}
if(button_r12.read()==0)
{
i2c.write(addr8bit, c3, 2);
}
if(button_r12.read()==1)
{
i2c.write(addr8bit, c4, 2);
}
if(button_r34.read()==1)
{
i2c.write(addr8bit, c5, 2);
}
if(button_r34.read()==0)
{
i2c.write(addr8bit, c6, 2);
}
wait(1);
if(spi_slave.receive()) {
char v = spi_slave.read(); // Read byte from master
printf("First character read %c",v);
if (v=='E'){
int len = spi_slave.read();
int i = 0;
while(i<len){
mood[i] = spi_slave.read();
i++;
}
printf("Arduino is feeling with len %d ",len);
for (int i=0;i<len;i++)
printf("%c",mood[i]);
printf(" right now.\r\n");
}
wait(0.5);
}
}
Outputs
Shocked State
Bored state
Happy state
Sad state
Count up and down
Conclusion
The results were in accordance with the theory. The lab helped us understand
the communications protocols as well as their implementation.