0% found this document useful (0 votes)
46 views10 pages

21BLC1133 Esd Exp10

The document describes experiments performed using an I2C interface on a Nucleo64-STM32L152RE board. It includes tasks to read data from a master and display on a slave, read accelerometer axis values and print them, and implement a fall detection system using an accelerometer.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views10 pages

21BLC1133 Esd Exp10

The document describes experiments performed using an I2C interface on a Nucleo64-STM32L152RE board. It includes tasks to read data from a master and display on a slave, read accelerometer axis values and print them, and implement a fall detection system using an accelerometer.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

School of Electronics Engineering (SENSE)

B. Tech – Electronics & Computer Engineering

BECE403E – EMBEDDED SYSTEM DESIGN

LAB RECORD (L39+L40)

Submitted By
21BLC1133 – S.Pranesh
Submitted To
Dr. Sofana Reka
DATE: 26/03/2024

Slot: L39+L40

Date: 26/03/2024

1
LAB – 10: Working with I2C
AIM:
To understand the Working with I2C.
SOFTWARE REQUIRED: ARM Keil Studio (Mbed Online Compiler), Tera Term

HARDWARE REQUIRED: Micro USB cable, NUCLEO64-STM32L152 Board, LEDs, Jumper Wires (M-F
and M-M), Breadboard,Buzzer, ADXL345.
PROCEDURE:

• Go to ARM Keil Studio (https://studio.keil.arm.com) and log in


• Select File → New → Mbed Project
• Click the Example project drop-down list and select “mbed2-example-blinky”
• In Project name field, provide the name of the new project and click Add project
• Double click on the “main.cpp” file from the newly created project folder
• Modify the code in the editor window as per the logic of your application
• Check for any errors in the program under the “Problems” tab of the panels window
• If no errors, connect the Nucleo Board to the computer using Micro USB Cable • Click Play icon
(Run project) to upload and start the code execution on the board.

LAB TASK 1: Read the input from Master and display on Slave

PROGRAM:

Master:
#include "mbed.h"
Serial pc (USBTX, USBRX);
I2C i2c(PB_11, PB_10);
int main(){
int address = 0x50;
char data[20];
pc.printf("Enter data to be sent: \r\n");

2
pc.scanf("%s", &data);
pc.printf("%s", data);
int len = strlen(data);
i2c.write(address, data, len);
wait(2);
}
Slave:
#include "mbed.h"
Serial pc(USBTX, USBRX);
I2CSlave slave(PB_11, PB_10);
int main() {
char buf[20];
char msg[] = "Slave!";
slave.address(0xA0);
while (1)
{
int i = slave.receive();
switch(i) {
case I2CSlave::ReadAddressed:
slave.write(msg, strlen(msg) + 1);
break;
case I2CSlave::WriteGeneral:
slave.read(buf,20);
pc.printf("Read1: %s \r\n", buf);
//wait(1);
break;
case I2CSlave::WriteAddressed:
slave.read(buf,20);
pc.printf("Read2: %s \r\n", buf);
wait(2);
break;
}

3
}
}

OUTPUT:

Fig1: Read the


input from
Master and
display on
Slave

4
LAB TASK 2: Read Accelerometer axis values and print it in serial monitor.
PROGRAM:

#include "mbed.h"
#include "ADXL345_I2C.h"

ADXL345_I2C accelerometer(PB_11,PB_10);
Serial pc(USBTX, USBRX);
int X_out_raw, Y_out_raw, Z_out_raw; // Outputs int
X_out, Y_out, Z_out; // Outputs
int main() {
int readings[3] = {0, 0, 0};
pc.printf("Starting ADXL345 test...\n");
wait(.001);
pc.printf("Device ID is: 0x%02x\n", accelerometer.getDeviceID());
wait(.001);
// Test whether any of the initialization fails.
if (accelerometer.setPowerControl(0x00)){
pc.printf("didn't intitialize power control\n");
return 0; } wait(.001);
//Full resolution, +/-16g, 4mg/LSB.
if(accelerometer.setDataFormatControl(0x0B)){
pc.printf("didn't set data format\n");
return 0; }
wait(.001);
//3.2kHz data rate.
if(accelerometer.setDataRate(ADXL345_3200HZ)){
pc.printf("didn't set data rate\n");
return 0; }
wait(.001);
//Measurement mode.
if(accelerometer.setPowerControl(MeasurementMode)) {

5
pc.printf("didn't set the power control to measurement\n");
return 0; } while (1) {
wait(0.1);
accelerometer.getOutput(readings);
wait(.1);
X_out_raw = (int16_t)readings[0];
Y_out_raw = (int16_t)readings[1];
Z_out_raw = (int16_t)readings[2];
// Low-pass filter for stable X,Y,Z values
X_out = 0.94 * X_out + 0.06 * X_out_raw;
Y_out = 0.94 * Y_out + 0.06 * Y_out_raw;
Z_out = 0.94 * Z_out + 0.06 * Z_out_raw;
pc.printf("%i,%i,%i\r\n",X_out,Y_out,Z_out); }
}

OUTPUT:

Fig 2: Read
Accelerometer
axis values and
print it in serial
monitor

6
CHALLENGING TASK: Fall detection system using Accelerometer.
PROGRAM:

#include "mbed.h"
#include "ADXL345_I2C.h"

ADXL345_I2C accelerometer(PB_11,PB_10);
Serial pc(USBTX, USBRX);
DigitalOut buzz(PB_8);

int X_out_raw, Y_out_raw, Z_out_raw; // Outputs


int X_out, Y_out, Z_out; // Outputs
int main() {
int readings[3] = {0, 0, 0};
pc.printf("Starting ADXL345 test...\n");
wait(.001);
pc.printf("Device ID is: 0x%02x\n", accelerometer.getDeviceID());
wait(.001);
// Test whether any of the initialization fails.
if (accelerometer.setPowerControl(0x00)){
pc.printf("didn't intitialize power control\n");
return 0;
}
wait(.001);
//Full resolution, +/-16g, 4mg/LSB.
if(accelerometer.setDataFormatControl(0x0B)){
pc.printf("didn't set data format\n");
return 0;
}
wait(.001); //3.2kHz data rate.
if(accelerometer.setDataRate(ADXL345_3200HZ)){
pc.printf("didn't set data rate\n");
return 0;

7
}
wait(.001);
//Measurement mode.
if(accelerometer.setPowerControl(MeasurementMode)) {
pc.printf("didn't set the power control to measurement\n");
return 0;
}
while (1) {
wait(0.1);
accelerometer.getOutput(readings);
wait(.1);
X_out_raw = (int16_t)readings[0];
Y_out_raw = (int16_t)readings[1];
Z_out_raw = (int16_t)readings[2];
// Low-pass filter for stable X,Y,Z values
X_out = 0.94 * X_out + 0.06 * X_out_raw;
Y_out = 0.94 * Y_out + 0.06 * Y_out_raw;
Z_out = 0.94 * Z_out + 0.06 * Z_out_raw;
pc.printf("%i,%i,%i\r\n",X_out,Y_out,Z_out);
if(X_out > 100 && Y_out > 100){
buzz = 1;
pc.printf("Buzzer ON");
}
else{
pc.printf("Buzzer OFF");
buzz = 0;
}
}
}

OUTPUT:

8
Fig 3: Fall
detection
system using
Accelerometer

OUTPUT:

INFERENCE:
The above program implements the working of Bluetooth and the other peripherals.

RESULT:

9
Thereofore various tasks has been done and we understood the working with I2C in
Nucleo64STM32L152RE Board using Keil Studio Cloud IDE.

10

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy