SlideShare a Scribd company logo
I2C Communication for
MPU6050 Data
Acquisition
Starting Notes :
• Everything that I say will be from the point of view of
understanding I2C protocol for communication
between an AVR (specifically ATTiny2313)
microcontroller and the MPU6050 Inertial
Measurement Unit
• I will be explaining both codes & concepts
simultaneously in a way that both compliment each
other’s understanding
Mind Map :
• I2C Protocol
• Basics
• Circuit
• Bus Connection
• I/O Port Structure of AVR microcontrollers
• I2C Specifications
• Signal Specifications
• Data Packet Specifications
• Device Specifications
• MPU6050
• Device Specifications
• Register Map
I2C COMMUNICATION
PROTOCOL
Communication Protocol :
A communication Protocol is a set of rules agreed upon
by two or more devices for the purpose of information
exchange
Basics :
• Inter Integrated Circuit Bus
• Developed by Philips (now by NXP semiconductors)
• official documentation at
http://www.nxp.com/documents/user_manual/UM10204.pdf
Basic Topology :
Serial Data
Serial Clock
• Each Device is recognised by a Unique ID
• A Device may be a :
• A transmitter only
• A receiver only
• A transceiver
• Three flavours :
• Standard mode : 400 Kbits/s
• Fast mode : 1 Mbits/s
• High speed mode : 3.4 Mbits/s
• More that one master is possible
I2C Device Address
Should be supported
by both Master and
Slave Devices
Terminology :
• Master : A device which initiates a transfer,
generates clock signals, and terminates a transfer
• Slave : A device Addressed by the Master
I2C Bus Circuit :
• When the bus is free (not being used for data transfer),
both lines should be high
That’s why these
pullup resistors
are required
ATmega 328 I/O port structure :
• Each microcontroller consists of a number of I/O ports
• There are three registers associated with each port :
• Data Direction Register (DDRx)
• Port Register (PORTx)
• Pin Register (PINx)
• DDRxn bit controls whether the pin is configured as an
input pin or an output pin
• PINxn bit stores the “Logic Value” as seen on that pin
of the microcontroller
• PORTxn bit controls the output of the pin when the pin
is configured as an output pin, or else it controls the
activation of the pullup register when the pin is
configured as an input pin.
Code :
First, some basics :
HOW DO YOU SET, CLEAR OR OR READ A SINGLE BIT
FROM A BYTE ?
Code :
First, some basics :
HOW DO YOU SET, CLEAR OR OR READ A SINGLE BIT
FROM A BYTE ?
uint8_t a = 0b11010010;
a |= (0x01 << 2); //set the second bit of “a”
a &= ~(0x01 << 1); // clear the first bit of “a”
(a & (0x01 << 3))>>3; // gives 3rd bit of a
11010010
00000100
—————
11010110
a |= (0x01 << 2)
a &= ~(0x01 << 1)
11010010
11111101
—————
11010110
(a & (0x01 << 3))>>3
11010010
00001000
—————
00000000
#include <avr/io.h>
DDRA |= (0x01 << 3) // pin3 of portA configured as o/p
DDRA &= ~(0x01 << 3) //pin3 of portA configured as i/p
DDRA |= (0x01<<3)
PORTA |= (0x01<<3) //output Logic 1 on pin3 of portA
PORTA &= ~(0x01<<3)//output Logic 0 on pin3 of portA
DDRA &= ~(0x01<<3)
PORTX |= (0X01<<3) //activate pullup register on pin3 of
//portA
PORTX &= ~(0X01<<3)//deactivate pullup register on pin3
//of portA
I2C Specifications :
Can be abstracted into three layers of specifications :
• Signal specifications
• Data Packet specifications
• Device specifications
Signal Specifications :
• Data on the SDA line must be stable during the high
period of the clock, th state of data can change only
when the SCL line is LOW.
Signal Specifications :
• Data on the SDA line must be stable during the high
period of the clock, th state of data can change only
when the SCL line is LOW.
Signal Specifications :
• When Data on the SDA line changes when SCL is
HIGH, a special condition is said to have occurred
START condition STOP condition
Signal Specifications :
• When Data on the SDA line changes during the high
period of clock, a special condition is said to have
occurred
START condition STOP condition
(SDA high to low
when SCL high)
(SDA low to high
when SCL high)
Signal Specifications :
• After transmission of each byte, the receiver needs to
acknowledge the transmitter that the byte has been
correctly read.
For this, the transmitter releases the control of the
SDA line for one SCL pulse (in our case, configuring the
pin as an input pin), and the receiver pulls SDA low for
that SCL pulse
Signal Specifications :
• After transmission of each byte, the receiver needs to
acknowledge the transmitter that the byte has been
correctly read.
For this, the transmitter releases the control of the
SDA line for one SCL pulse (in our case, configuring the
pin as an input pin), and the receiver pulls SDA low for
that SCL pulse
Data Packet Specifications :
• Every transmission starts with a START bit
• The first byte on every transmission contains the 7-
bit slave address and the R/W bit
R/W bit - 0 indicates that the master wishes to write data
R/W bit - 1 indicates that the master wishes to read data
Data Packet Specifications :
• Every byte is followed by an Acknowledgement bit
• During the “write operation”, the Master controls the
SDA line, whereas during the “read operation”, the
Slave controls the SDA line
• Every transmission starts with a STOP bit
Data Packet Specifications :
A complete data transfer
Data Packet Specifications :
Master Writes one byte of data to the Slave :
1. START condition
2. 7-bit Slave Address
3. R/W bit - 0
4. Acknowledge by Slave
5. 8 bit data on SDA by master
6. Acknowledge by Slave
7. STOP condition
Data Packet Specifications :
Master Writes two bytes of data to the Slave :
1. START condition
2. 7-bit Slave Address
3. R/W bit - 0
4. Acknowledge by Slave
5. 8 bit data on SDA by master
6. Acknowledge by Slave
7. 8 bit data on SDA by master
8. Acknowledge by Slave
9. STOP condition
Data Packet Specifications :
Master reads one byte of data from the Slave :
1. START condition
2. 7-bit Slave Address
3. R/W bit - 0
4. Acknowledge by Slave
5. 8 bit data on SDA by Slave
6. Acknowledge by master
7. STOP condition
Data Packet Specifications :
Master reads two bytes of data from the Slave :
1. START condition
2. 7-bit Slave Address
3. R/W bit - 0
4. Acknowledge by Slave
5. 8 bit data on SDA by Slave
6. Acknowledge by master
7. 8 bit data on SDA by Slave
8. Acknowledge by master
9. STOP condition
Device Specifications :
• In what format does the device expect data in order to
communicate the information
• Varies from device to device
Code :
assuming:
pin0 of portB is SDA
pin1 of portB is SCL
Code :
Code :
Code :
MPU6050
(by Invensense)
Consists of :
• 3 - axis Accelerometer
• 3 - axis Gyroscope
• Temperature Sensor
• Digital Motion Processor
• FIFO buffers
Device Specification :
To write data to a register of MPU6050 :
• Send MPU6050 Device ID on the I2C bus
• write Register Address to the FIFO buffer
• write Data to FIFO buffer
To read data from a register of MPU6050 :
• Send MPU6050 Device ID on the I2C BUS
• write Register Address to the FIFO buffer
• read Data from the FIFO buffer
Code :
Code :
MPU6050 Register Map :
• There are 75 8-bit registers in the Register map
• We only 15 of them
MPU6050 Register Map :
Power Management Register 1 (PWR_MGMT_1) :
the 6th bit of this register is the SLEEP bit, and it is 1 when MP
write_byte_to_slave(0x68,0x6B,0x00);
MPU6050 Register Map :
The values for each of the axes of accelerometer and gyroscop
Code :
MPU6050 Register Map :
gyroscope configuration register (GYRO_CONFIG)
accelerometer configuration register (ACCEL_CONFIG)
Recap:
• I2C Protocol
• Basics
• Circuit
• Bus Connection
• I/O Port Structure of ATmega microcontrollers
• I2C Specifications
• Signal Specifications
• Data Packet Specifications
• Device Specifications
• MPU6050
• Device Specifications
• Register Map
Thank You

More Related Content

What's hot

Presentation on python
Presentation on pythonPresentation on python
Presentation on python
Venkat Projects
 
Q4.11: Getting Started in LAVA
Q4.11: Getting Started in LAVAQ4.11: Getting Started in LAVA
Q4.11: Getting Started in LAVA
Linaro
 
Interrupt Handling with LPC2148
Interrupt Handling with LPC2148Interrupt Handling with LPC2148
Spi in arm7(lpc2148)
Spi in arm7(lpc2148)Spi in arm7(lpc2148)
Spi in arm7(lpc2148)
Aarav Soni
 
Pic16cxx instruction set
Pic16cxx instruction setPic16cxx instruction set
Pic16cxx instruction set
v Kalairajan
 
UART
UARTUART
MICROCONTROLLER - INTEL 8051
MICROCONTROLLER - INTEL 8051MICROCONTROLLER - INTEL 8051
MICROCONTROLLER - INTEL 8051
DEPARTMENT OF PHYSICS
 
IoT on Raspberry PI v1.2
IoT on Raspberry PI v1.2IoT on Raspberry PI v1.2
IoT on Raspberry PI v1.2
John Staveley
 
Teach your kids how to program with Python and the Raspberry Pi
Teach your kids how to program with Python and the Raspberry PiTeach your kids how to program with Python and the Raspberry Pi
Teach your kids how to program with Python and the Raspberry Pi
Juan Gomez
 
PIC timer programming
PIC timer programmingPIC timer programming
PIC timer programming
Akash Puri
 
6LoWPAN: An open IoT Networking Protocol
6LoWPAN: An open IoT Networking Protocol6LoWPAN: An open IoT Networking Protocol
6LoWPAN: An open IoT Networking Protocol
Samsung Open Source Group
 
Embedded c program and programming structure for beginners
Embedded c program and programming structure for beginnersEmbedded c program and programming structure for beginners
Embedded c program and programming structure for beginners
Kamesh Mtec
 
Design a processor
Design a processorDesign a processor
Design a processor
Farzana Aktar
 
Presentation on arp protocol
Presentation on arp protocolPresentation on arp protocol
Presentation on arp protocol
Mohd. Ahmad Siddiqi
 
Unit 5
Unit 5Unit 5
Unit 5
sowndaryaM5
 
I o ports.ppt
I o ports.pptI o ports.ppt
I o ports.ppt
Pradeep V Dev
 
8051 architecture
8051 architecture8051 architecture
8051 architecture
sb108ec
 
What is Bootloader???
What is Bootloader???What is Bootloader???
What is Bootloader???
Dinesh Damodar
 
System bus timing 8086
System bus timing 8086System bus timing 8086
System bus timing 8086
mpsrekha83
 

What's hot (20)

Presentation on python
Presentation on pythonPresentation on python
Presentation on python
 
Q4.11: Getting Started in LAVA
Q4.11: Getting Started in LAVAQ4.11: Getting Started in LAVA
Q4.11: Getting Started in LAVA
 
Interrupt Handling with LPC2148
Interrupt Handling with LPC2148Interrupt Handling with LPC2148
Interrupt Handling with LPC2148
 
Spi in arm7(lpc2148)
Spi in arm7(lpc2148)Spi in arm7(lpc2148)
Spi in arm7(lpc2148)
 
Pic16cxx instruction set
Pic16cxx instruction setPic16cxx instruction set
Pic16cxx instruction set
 
UART
UARTUART
UART
 
MICROCONTROLLER - INTEL 8051
MICROCONTROLLER - INTEL 8051MICROCONTROLLER - INTEL 8051
MICROCONTROLLER - INTEL 8051
 
IoT on Raspberry PI v1.2
IoT on Raspberry PI v1.2IoT on Raspberry PI v1.2
IoT on Raspberry PI v1.2
 
The 80386 80486
The 80386 80486The 80386 80486
The 80386 80486
 
Teach your kids how to program with Python and the Raspberry Pi
Teach your kids how to program with Python and the Raspberry PiTeach your kids how to program with Python and the Raspberry Pi
Teach your kids how to program with Python and the Raspberry Pi
 
PIC timer programming
PIC timer programmingPIC timer programming
PIC timer programming
 
6LoWPAN: An open IoT Networking Protocol
6LoWPAN: An open IoT Networking Protocol6LoWPAN: An open IoT Networking Protocol
6LoWPAN: An open IoT Networking Protocol
 
Embedded c program and programming structure for beginners
Embedded c program and programming structure for beginnersEmbedded c program and programming structure for beginners
Embedded c program and programming structure for beginners
 
Design a processor
Design a processorDesign a processor
Design a processor
 
Presentation on arp protocol
Presentation on arp protocolPresentation on arp protocol
Presentation on arp protocol
 
Unit 5
Unit 5Unit 5
Unit 5
 
I o ports.ppt
I o ports.pptI o ports.ppt
I o ports.ppt
 
8051 architecture
8051 architecture8051 architecture
8051 architecture
 
What is Bootloader???
What is Bootloader???What is Bootloader???
What is Bootloader???
 
System bus timing 8086
System bus timing 8086System bus timing 8086
System bus timing 8086
 

Viewers also liked

MPU6050 IMU with Arduino
MPU6050 IMU with ArduinoMPU6050 IMU with Arduino
MPU6050 IMU with Arduino
yeokm1
 
Reglamento
ReglamentoReglamento
Reglamento
jose rubio ortega
 
The Future of Education (LEGO, Billund)
The Future of Education (LEGO, Billund)The Future of Education (LEGO, Billund)
The Future of Education (LEGO, Billund)
Michell Zappa
 
Internet Of Things: Hands on: YOW! night
Internet Of Things: Hands on: YOW! nightInternet Of Things: Hands on: YOW! night
Internet Of Things: Hands on: YOW! night
Andy Gelme
 
Quadcopter navigation using aakash tablet with on board image processing
Quadcopter navigation using aakash tablet with on board image processingQuadcopter navigation using aakash tablet with on board image processing
Quadcopter navigation using aakash tablet with on board image processing
D Yogendra Rao
 
Embedded Programming for Quadcopters
Embedded Programming for QuadcoptersEmbedded Programming for Quadcopters
Embedded Programming for Quadcopters
Ryan Boland
 
Quadcopter Talk (Abstractions)
Quadcopter Talk (Abstractions)Quadcopter Talk (Abstractions)
Quadcopter Talk (Abstractions)
Ryan Boland
 
Two wheel self balancing robot
 Two wheel self balancing robot Two wheel self balancing robot
Two wheel self balancing robot
adeela aslam
 
QUADCOPTER
QUADCOPTERQUADCOPTER
QUADCOPTER
tusarjena22
 
Gyroscope
GyroscopeGyroscope

Viewers also liked (12)

MPU6050 IMU with Arduino
MPU6050 IMU with ArduinoMPU6050 IMU with Arduino
MPU6050 IMU with Arduino
 
Bathymetry ME Thesis
Bathymetry ME ThesisBathymetry ME Thesis
Bathymetry ME Thesis
 
Reglamento
ReglamentoReglamento
Reglamento
 
The Future of Education (LEGO, Billund)
The Future of Education (LEGO, Billund)The Future of Education (LEGO, Billund)
The Future of Education (LEGO, Billund)
 
Internet Of Things: Hands on: YOW! night
Internet Of Things: Hands on: YOW! nightInternet Of Things: Hands on: YOW! night
Internet Of Things: Hands on: YOW! night
 
Quadcopter navigation using aakash tablet with on board image processing
Quadcopter navigation using aakash tablet with on board image processingQuadcopter navigation using aakash tablet with on board image processing
Quadcopter navigation using aakash tablet with on board image processing
 
Embedded Programming for Quadcopters
Embedded Programming for QuadcoptersEmbedded Programming for Quadcopters
Embedded Programming for Quadcopters
 
Quadcopter Talk (Abstractions)
Quadcopter Talk (Abstractions)Quadcopter Talk (Abstractions)
Quadcopter Talk (Abstractions)
 
Two wheel self balancing robot
 Two wheel self balancing robot Two wheel self balancing robot
Two wheel self balancing robot
 
QUADCOPTER
QUADCOPTERQUADCOPTER
QUADCOPTER
 
p i d controller
p i d controllerp i d controller
p i d controller
 
Gyroscope
GyroscopeGyroscope
Gyroscope
 

Similar to I2 c and mpu6050 basics

Peripherals and interfacing
Peripherals  and interfacingPeripherals  and interfacing
Peripherals and interfacing
RAMPRAKASHT1
 
I2C And SPI Part-23
I2C And  SPI Part-23I2C And  SPI Part-23
I2C And SPI Part-23
Techvilla
 
Serial Peripheral Interface(SPI)
Serial Peripheral Interface(SPI)Serial Peripheral Interface(SPI)
Serial Peripheral Interface(SPI)
Dhaval Kaneria
 
I2c protocol - Inter–Integrated Circuit Communication Protocol
I2c protocol - Inter–Integrated Circuit Communication ProtocolI2c protocol - Inter–Integrated Circuit Communication Protocol
I2c protocol - Inter–Integrated Circuit Communication Protocol
Ankur Soni
 
Serial Peripheral Interface
Serial Peripheral InterfaceSerial Peripheral Interface
Serial Peripheral Interface
Anurag Tomar
 
Avr report
Avr reportAvr report
Avr report
NITISH KUMAR
 
Assembler4
Assembler4Assembler4
Assembler4
Omar Sanchez
 
Embedded systems and robotics by scmandota
Embedded systems and robotics by scmandotaEmbedded systems and robotics by scmandota
Embedded systems and robotics by scmandota
scmandota
 
communication interfaces-Embedded real time systems
communication interfaces-Embedded real time systemscommunication interfaces-Embedded real time systems
communication interfaces-Embedded real time systems
Raghunath reddy
 
Introduction to PIC.pptx
Introduction to PIC.pptxIntroduction to PIC.pptx
Introduction to PIC.pptx
Anbuselvi Mathivanan
 
8255.pdf
8255.pdf8255.pdf
8255.pdf
someshdash1
 
One-Wire-Serial-Communication.pdf
One-Wire-Serial-Communication.pdfOne-Wire-Serial-Communication.pdf
One-Wire-Serial-Communication.pdf
shamtekawambwa1
 
The presentation is about USART and serial communication
The presentation is about USART and serial communicationThe presentation is about USART and serial communication
The presentation is about USART and serial communication
sinaankhalil
 
PPI-MECHATRONICS
PPI-MECHATRONICSPPI-MECHATRONICS
PPI-MECHATRONICS
selvakumar948
 
AN INTRODUCTION TO SERIAL PORT INTERFACING
AN INTRODUCTION TO SERIAL PORT INTERFACINGAN INTRODUCTION TO SERIAL PORT INTERFACING
AN INTRODUCTION TO SERIAL PORT INTERFACING
Total Project Solutions
 
Welcome to International Journal of Engineering Research and Development (IJERD)
Welcome to International Journal of Engineering Research and Development (IJERD)Welcome to International Journal of Engineering Research and Development (IJERD)
Welcome to International Journal of Engineering Research and Development (IJERD)
IJERD Editor
 
MECHATRONICS-Unit 3-PROGRAMMABLE PERIPERAL INTERFACE.ppt
MECHATRONICS-Unit 3-PROGRAMMABLE PERIPERAL INTERFACE.pptMECHATRONICS-Unit 3-PROGRAMMABLE PERIPERAL INTERFACE.ppt
MECHATRONICS-Unit 3-PROGRAMMABLE PERIPERAL INTERFACE.ppt
CHANDRA KUMAR S
 
8051 serialp port
8051 serialp port8051 serialp port
8051 serialp port
Teju Kotti
 

Similar to I2 c and mpu6050 basics (20)

Peripherals and interfacing
Peripherals  and interfacingPeripherals  and interfacing
Peripherals and interfacing
 
I2C And SPI Part-23
I2C And  SPI Part-23I2C And  SPI Part-23
I2C And SPI Part-23
 
Serial Peripheral Interface(SPI)
Serial Peripheral Interface(SPI)Serial Peripheral Interface(SPI)
Serial Peripheral Interface(SPI)
 
I2c protocol - Inter–Integrated Circuit Communication Protocol
I2c protocol - Inter–Integrated Circuit Communication ProtocolI2c protocol - Inter–Integrated Circuit Communication Protocol
I2c protocol - Inter–Integrated Circuit Communication Protocol
 
Serial Peripheral Interface
Serial Peripheral InterfaceSerial Peripheral Interface
Serial Peripheral Interface
 
Avr report
Avr reportAvr report
Avr report
 
SPI Protocol in LPC2148
SPI  Protocol in LPC2148SPI  Protocol in LPC2148
SPI Protocol in LPC2148
 
Assembler4
Assembler4Assembler4
Assembler4
 
Embedded systems and robotics by scmandota
Embedded systems and robotics by scmandotaEmbedded systems and robotics by scmandota
Embedded systems and robotics by scmandota
 
communication interfaces-Embedded real time systems
communication interfaces-Embedded real time systemscommunication interfaces-Embedded real time systems
communication interfaces-Embedded real time systems
 
Introduction to PIC.pptx
Introduction to PIC.pptxIntroduction to PIC.pptx
Introduction to PIC.pptx
 
8255.pdf
8255.pdf8255.pdf
8255.pdf
 
One-Wire-Serial-Communication.pdf
One-Wire-Serial-Communication.pdfOne-Wire-Serial-Communication.pdf
One-Wire-Serial-Communication.pdf
 
The presentation is about USART and serial communication
The presentation is about USART and serial communicationThe presentation is about USART and serial communication
The presentation is about USART and serial communication
 
PPI-MECHATRONICS
PPI-MECHATRONICSPPI-MECHATRONICS
PPI-MECHATRONICS
 
AN INTRODUCTION TO SERIAL PORT INTERFACING
AN INTRODUCTION TO SERIAL PORT INTERFACINGAN INTRODUCTION TO SERIAL PORT INTERFACING
AN INTRODUCTION TO SERIAL PORT INTERFACING
 
Welcome to International Journal of Engineering Research and Development (IJERD)
Welcome to International Journal of Engineering Research and Development (IJERD)Welcome to International Journal of Engineering Research and Development (IJERD)
Welcome to International Journal of Engineering Research and Development (IJERD)
 
MECHATRONICS-Unit 3-PROGRAMMABLE PERIPERAL INTERFACE.ppt
MECHATRONICS-Unit 3-PROGRAMMABLE PERIPERAL INTERFACE.pptMECHATRONICS-Unit 3-PROGRAMMABLE PERIPERAL INTERFACE.ppt
MECHATRONICS-Unit 3-PROGRAMMABLE PERIPERAL INTERFACE.ppt
 
8051 serialp port
8051 serialp port8051 serialp port
8051 serialp port
 
UART.pptx
UART.pptxUART.pptx
UART.pptx
 

Recently uploaded

DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
FluxPrime1
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
Pipe Restoration Solutions
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
AhmedHussein950959
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
AJAYKUMARPUND1
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
ViniHema
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
Massimo Talia
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
VENKATESHvenky89705
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
Pratik Pawar
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
SamSarthak3
 
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdfCOLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
Kamal Acharya
 
Democratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek AryaDemocratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek Arya
abh.arya
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
Jayaprasanna4
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Teleport Manpower Consultant
 
addressing modes in computer architecture
addressing modes  in computer architectureaddressing modes  in computer architecture
addressing modes in computer architecture
ShahidSultan24
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.
PrashantGoswami42
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation & Control
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 

Recently uploaded (20)

DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
 
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdfCOLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
 
Democratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek AryaDemocratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek Arya
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
 
addressing modes in computer architecture
addressing modes  in computer architectureaddressing modes  in computer architecture
addressing modes in computer architecture
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
 
Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 

I2 c and mpu6050 basics

  • 1. I2C Communication for MPU6050 Data Acquisition
  • 2. Starting Notes : • Everything that I say will be from the point of view of understanding I2C protocol for communication between an AVR (specifically ATTiny2313) microcontroller and the MPU6050 Inertial Measurement Unit • I will be explaining both codes & concepts simultaneously in a way that both compliment each other’s understanding
  • 3. Mind Map : • I2C Protocol • Basics • Circuit • Bus Connection • I/O Port Structure of AVR microcontrollers • I2C Specifications • Signal Specifications • Data Packet Specifications • Device Specifications • MPU6050 • Device Specifications • Register Map
  • 5. Communication Protocol : A communication Protocol is a set of rules agreed upon by two or more devices for the purpose of information exchange
  • 6. Basics : • Inter Integrated Circuit Bus • Developed by Philips (now by NXP semiconductors) • official documentation at http://www.nxp.com/documents/user_manual/UM10204.pdf Basic Topology : Serial Data Serial Clock
  • 7. • Each Device is recognised by a Unique ID • A Device may be a : • A transmitter only • A receiver only • A transceiver • Three flavours : • Standard mode : 400 Kbits/s • Fast mode : 1 Mbits/s • High speed mode : 3.4 Mbits/s • More that one master is possible I2C Device Address Should be supported by both Master and Slave Devices
  • 8. Terminology : • Master : A device which initiates a transfer, generates clock signals, and terminates a transfer • Slave : A device Addressed by the Master
  • 9. I2C Bus Circuit : • When the bus is free (not being used for data transfer), both lines should be high That’s why these pullup resistors are required
  • 10. ATmega 328 I/O port structure : • Each microcontroller consists of a number of I/O ports • There are three registers associated with each port : • Data Direction Register (DDRx) • Port Register (PORTx) • Pin Register (PINx)
  • 11. • DDRxn bit controls whether the pin is configured as an input pin or an output pin • PINxn bit stores the “Logic Value” as seen on that pin of the microcontroller • PORTxn bit controls the output of the pin when the pin is configured as an output pin, or else it controls the activation of the pullup register when the pin is configured as an input pin.
  • 12. Code : First, some basics : HOW DO YOU SET, CLEAR OR OR READ A SINGLE BIT FROM A BYTE ?
  • 13. Code : First, some basics : HOW DO YOU SET, CLEAR OR OR READ A SINGLE BIT FROM A BYTE ? uint8_t a = 0b11010010; a |= (0x01 << 2); //set the second bit of “a” a &= ~(0x01 << 1); // clear the first bit of “a” (a & (0x01 << 3))>>3; // gives 3rd bit of a
  • 14. 11010010 00000100 ————— 11010110 a |= (0x01 << 2) a &= ~(0x01 << 1) 11010010 11111101 ————— 11010110 (a & (0x01 << 3))>>3 11010010 00001000 ————— 00000000
  • 15. #include <avr/io.h> DDRA |= (0x01 << 3) // pin3 of portA configured as o/p DDRA &= ~(0x01 << 3) //pin3 of portA configured as i/p DDRA |= (0x01<<3) PORTA |= (0x01<<3) //output Logic 1 on pin3 of portA PORTA &= ~(0x01<<3)//output Logic 0 on pin3 of portA DDRA &= ~(0x01<<3) PORTX |= (0X01<<3) //activate pullup register on pin3 of //portA PORTX &= ~(0X01<<3)//deactivate pullup register on pin3 //of portA
  • 16.
  • 17. I2C Specifications : Can be abstracted into three layers of specifications : • Signal specifications • Data Packet specifications • Device specifications
  • 18. Signal Specifications : • Data on the SDA line must be stable during the high period of the clock, th state of data can change only when the SCL line is LOW.
  • 19. Signal Specifications : • Data on the SDA line must be stable during the high period of the clock, th state of data can change only when the SCL line is LOW.
  • 20. Signal Specifications : • When Data on the SDA line changes when SCL is HIGH, a special condition is said to have occurred START condition STOP condition
  • 21. Signal Specifications : • When Data on the SDA line changes during the high period of clock, a special condition is said to have occurred START condition STOP condition (SDA high to low when SCL high) (SDA low to high when SCL high)
  • 22. Signal Specifications : • After transmission of each byte, the receiver needs to acknowledge the transmitter that the byte has been correctly read. For this, the transmitter releases the control of the SDA line for one SCL pulse (in our case, configuring the pin as an input pin), and the receiver pulls SDA low for that SCL pulse
  • 23. Signal Specifications : • After transmission of each byte, the receiver needs to acknowledge the transmitter that the byte has been correctly read. For this, the transmitter releases the control of the SDA line for one SCL pulse (in our case, configuring the pin as an input pin), and the receiver pulls SDA low for that SCL pulse
  • 24. Data Packet Specifications : • Every transmission starts with a START bit • The first byte on every transmission contains the 7- bit slave address and the R/W bit R/W bit - 0 indicates that the master wishes to write data R/W bit - 1 indicates that the master wishes to read data
  • 25. Data Packet Specifications : • Every byte is followed by an Acknowledgement bit • During the “write operation”, the Master controls the SDA line, whereas during the “read operation”, the Slave controls the SDA line • Every transmission starts with a STOP bit
  • 26. Data Packet Specifications : A complete data transfer
  • 27. Data Packet Specifications : Master Writes one byte of data to the Slave : 1. START condition 2. 7-bit Slave Address 3. R/W bit - 0 4. Acknowledge by Slave 5. 8 bit data on SDA by master 6. Acknowledge by Slave 7. STOP condition
  • 28. Data Packet Specifications : Master Writes two bytes of data to the Slave : 1. START condition 2. 7-bit Slave Address 3. R/W bit - 0 4. Acknowledge by Slave 5. 8 bit data on SDA by master 6. Acknowledge by Slave 7. 8 bit data on SDA by master 8. Acknowledge by Slave 9. STOP condition
  • 29. Data Packet Specifications : Master reads one byte of data from the Slave : 1. START condition 2. 7-bit Slave Address 3. R/W bit - 0 4. Acknowledge by Slave 5. 8 bit data on SDA by Slave 6. Acknowledge by master 7. STOP condition
  • 30. Data Packet Specifications : Master reads two bytes of data from the Slave : 1. START condition 2. 7-bit Slave Address 3. R/W bit - 0 4. Acknowledge by Slave 5. 8 bit data on SDA by Slave 6. Acknowledge by master 7. 8 bit data on SDA by Slave 8. Acknowledge by master 9. STOP condition
  • 31. Device Specifications : • In what format does the device expect data in order to communicate the information • Varies from device to device
  • 32. Code : assuming: pin0 of portB is SDA pin1 of portB is SCL
  • 37. Consists of : • 3 - axis Accelerometer • 3 - axis Gyroscope • Temperature Sensor • Digital Motion Processor • FIFO buffers
  • 38. Device Specification : To write data to a register of MPU6050 : • Send MPU6050 Device ID on the I2C bus • write Register Address to the FIFO buffer • write Data to FIFO buffer To read data from a register of MPU6050 : • Send MPU6050 Device ID on the I2C BUS • write Register Address to the FIFO buffer • read Data from the FIFO buffer
  • 41. MPU6050 Register Map : • There are 75 8-bit registers in the Register map • We only 15 of them
  • 42. MPU6050 Register Map : Power Management Register 1 (PWR_MGMT_1) : the 6th bit of this register is the SLEEP bit, and it is 1 when MP write_byte_to_slave(0x68,0x6B,0x00);
  • 43. MPU6050 Register Map : The values for each of the axes of accelerometer and gyroscop
  • 45. MPU6050 Register Map : gyroscope configuration register (GYRO_CONFIG) accelerometer configuration register (ACCEL_CONFIG)
  • 46. Recap: • I2C Protocol • Basics • Circuit • Bus Connection • I/O Port Structure of ATmega microcontrollers • I2C Specifications • Signal Specifications • Data Packet Specifications • Device Specifications • MPU6050 • Device Specifications • Register Map

Editor's Notes

  1. I will spend much more time in explaining I2C and relevant codes, because once that is understood, interfacing with MPU6050 is very easy
  2. In the case of I2C, the protocol is a set of rules about the values and precedence of signals on the bus that convey meaningful information
  3. the official documentation is very detailed and informative, read the Part 3 of the documentation to know everything you will need to know about I2C Serial Data and Serial Clock + plus a GND line
  4. standard mode speed is important because your microcontrollers (even the ATmega’s) can go faster than this speed, and if the slave device does not support speeds faster than 400Kbits/sec, there is going to be a communication problem. More than one master possible : bus arbitration should be used to avoid clashes in communication when both master’s try to communicate on the bus.
  5. It is very important that a device which initiates a transfer has to terminate it as well
  6. Next —> To understand how these lines are controlled at the hardware and the software level, we need to understand the I/O port structure of ATmega microcontrollers
  7. When I say “x”, it is the port name for example : DDRA for portA, … Each register is 8 bits long, one bit for each pin of the port. When I say “n”, it is the bit number of the pin in the port : for example : DDRA0 is the 0th pin of portA Next —> Lets see what the functions of these registers are
  8. So, let me explain how this works : when DDRxn = 1, the buffer is activated, and the value of the PORTxn bit is seen as the pin of the microcontroller. when DDRxn = 0, the buffer is tristated, and the Logic value at the pin is seen on the PINxn bit. when the buffer is tristated, the PORTxn bit controls the pullup register : when PORTxn is 1, pullup register is activated when PORTxn is 0, pullup register is deactivated
  9. next —> Just to quickly explain this
  10. next —> using these three concepts, I can : configure a port as input or output change the output of a port to high or low activate or deactivate a pullup register read input value from a pin
  11. avr/io.h includes all the definitions for the Port Addresses for the particular AVR microcontroller next —> So, the actual I2C circuit in our case will look like this
  12. next —> now, having discussed the I2C basics and the circuit, lets move on to the I2C specifications
  13. signal specifications -> how the signal values should change in order to represent meaningful data data packet specifications -> In what order must the signals change in order to represent meaningful data device specifications -> what data does the device expect next —> so, lets start with signal specifications
  14. eg: the register address, how many bytes to read We will look at I2C device specifications for MPU6050 next —> lets see how these things translate to code
  15. firstly, I write down these very simple functions that will make my code much more readable next —> now using these functions, we can write down more complicated and interesting functions
  16. All these functions are perfectly obvious from the signal specifications and data packet specifications
  17. All these functions are perfectly obvious from the signal specifications and data packet specifications
  18. Using these 7 functions, all I2C communications can be handled as can been seen the MPU6050 example I’ll give you later
  19. can interface with other sensors via I2C DMP can be accessed only through Invensense’s firmware, …
  20. next —> lets translate these steps to code
  21. these functions error_routine() acknowledge_routine() fin_routine() all blink different lights in different patterns, for me to debug my code
  22. with these two functions, we can do data acquisition from MPU6050, but there is just one more thing we need to know. Which register of MPU6050 to read the data from?
  23. next —> Since I need to access all these values at once every time, I wrote the following function to do the same.
  24. everything should be obvious, except the USART_transmit_byte(data); statement … There are two more registers that are important
  25. these registers help in setting the full scale ranges of the accelerometer and gyroscope values gyro values can range from + or - 250 degrees/sec to + or - 2000 degrees/sec acc values can range from + or - 2g to + or - 16 g