Embedded Systems Design Course Applying the mbed microcontroller

Similar documents
Embedded Systems Design Course Applying the mbed microcontroller

Data Acquisition Module with I2C interface «I2C-FLEXEL» User s Guide

DS1621 Digital Thermometer and Thermostat

DS1621 Digital Thermometer and Thermostat

Pulse width modulation

Develop a Dallas 1-Wire Master Using the Z8F1680 Series of MCUs

DS Wire Digital Thermometer and Thermostat

SRF08 Ultra sonic range finder Technical Specification

The I2C Bus. NXP Semiconductors: UM10204 I2C-bus specification and user manual HAW - Arduino 1

Elettronica dei Sistemi Digitali Costantino Giaconia SERIAL I/O COMMON PROTOCOLS

NB3H5150 I2C Programming Guide. I2C/SMBus Custom Configuration Application Note

7 OUT1 8 OUT2 9 OUT3 10 OUT4 11 OUT5 12 OUT6 13 OUT7 14 OUT8 15 OUT9 16 OUT10 17 OUT11 18 OUT12 19 OUT13 20 OUT14 21 OUT15 22 OUT16 OUT17 23 OUT18

DS1307ZN. 64 x 8 Serial Real-Time Clock

Embedded Systems Design Course Applying the mbed microcontroller

Application Note 120 Communicating Through the 1-Wire Master

MPR121 Serial Communication

PACKAGE OUTLINE DALLAS DS2434 DS2434 GND. PR 35 PACKAGE See Mech. Drawings Section

- 35mA Standby, mA Speaking pre-defined phrases with up to 1925 total characters.

RS-485 Protocol Manual

DS1821 Programmable Digital Thermostat and Thermometer

DS18B20 Programmable Resolution 1-Wire Digital Thermometer

UniPi technical documentation REV 1.1

AN2680 Application note

Adafruit SHT31-D Temperature & Humidity Sensor Breakout

Data Sheet. Adaptive Design ltd. Arduino Dual L6470 Stepper Motor Shield V th November L6470 Stepper Motor Shield

FM75 Low-Voltage Two-Wire Digital Temperature Sensor with Thermal Alarm

AN141 SMBUS COMMUNICATION FOR SMALL FORM FACTOR DEVICE FAMILIES. 1. Introduction. 2. Overview of the SMBus Specification. 2.1.

USB / Data-Acquisition Module NOW LEAD-FREE

HDMM01 V1.0. Dual-axis Magnetic Sensor Module With I 2 C Interface FEATURES. Signal Path X

Designing VM2 Application Boards

USB2.0 <=> I2C V4.4. Konverter Kabel und Box mit Galvanischetrennung

MODULE BOUSSOLE ÉLECTRONIQUE CMPS03 Référence :

Microcontroller Programming Beginning with Arduino. Charlie Mooney

Adafruit MCP9808 Precision I2C Temperature Sensor Guide

RPLIDAR. Low Cost 360 degree 2D Laser Scanner (LIDAR) System Development Kit User Manual Rev.1

Web Site: Forums: forums.parallax.com Sales: Technical:

MAX5417L Evaluation Kit/Evaluation System

Allows the user to protect against inadvertent write operations. Device select and address bytes are Acknowledged Data Bytes are not Acknowledged

Raspberry Pi. Hans- Petter Halvorsen, M.Sc.

1. Learn about the 555 timer integrated circuit and applications 2. Apply the 555 timer to build an infrared (IR) transmitter and receiver

QUICK START GUIDE FOR DEMONSTRATION CIRCUIT BIT DIFFERENTIAL ADC WITH I2C LTC2485 DESCRIPTION

IS31FL3731 AUDIO MODULATED MATRIX LED DRIVER. May 2013

MMC314xMR. Ultra Small 3-axis Magnetic Sensor, With I 2 C Interface. Signal Path X. Signal Path Y. Signal Path Z FEATURES

TDA CHANNEL VOLUME CONTROLLER 1 FEATURES 2 DESCRIPTION. Figure 1. Package

SKYEMODULE GEMINI DATASHEET VERSION

ARM Thumb Microcontrollers. Application Note. Software ISO 7816 I/O Line Implementation. Features. Introduction

Accessing I2C devices with Digi Embedded Linux 5.2 example on Digi Connect ME 9210

Temp. & humidity Transmitter Instructions

MANUAL FOR RX700 LR and NR

The Secrets of RS-485 Half-duplex Communication

Software Manual RS232 Laser Merge Module. Document # SU Rev A

LM75A. 1. General description. 2. Features. Digital temperature sensor and thermal watchdog

MAX6683 Evaluation System/Evaluation Kit

USING I2C WITH PICAXE

IR Communication a learn.sparkfun.com tutorial

Definitions and Documents

I 2 C Master Mode Overview and Use of the PICmicro MSSP I 2 C Interface with a 24xx01x EEPROM

TSL2561 Luminosity Sensor

MicroMag3 3-Axis Magnetic Sensor Module

PCAN-MicroMod Universal I/O Module with CAN Interface. User Manual. Document version ( )

RFID MODULE Mifare Reader / Writer SL030 User Manual Version 2.6 Nov 2012 StrongLink

System theremino MasterDIL-V3

Integration of Arduino as a slave system to LonWorks based System using I2C Interface

Ultrasonic Distance Measurement Module

ZX-NUNCHUK (# )

The Secrets of Flow Control in Serial Communication

Product Specification. 1000BASE-T RoHS Compliant Copper SFP Transceiver FCLF8520P2BTL / FCLF8521P2BTL / FCLF8522P2BTL

Dolphin In-Circuit programming Updating Firmware in the field

EVAL-UFDC-1/UFDC-1M-16

76-77 GHz RF Transmitter Front-end for W-band Radar Applications

1000BASE-T and 10/100/1000BASE-T Copper SFP Transceiver

Wireless Security Camera

Bidirectional wireless communication using EmbedRF

GTS-4E Hardware User Manual. Version: V1.1.0 Date:

AN601 I2C 2.8 Communication Protocol. SM130 SM130 - Mini APPLICATION NOTE

SFP-TX 1000BASE-T SFP Transceiver 10/100/1000M SFP Transceiver

AVR315: Using the TWI Module as I2C Master. Introduction. Features. AVR 8-bit Microcontrollers APPLICATION NOTE

Arduino Due Back. Warning: Unlike other Arduino boards, the Arduino Due board runs at 3.3V. The maximum. Overview

Single channel data transceiver module WIZ2-434

udrive-usd-g1 Embedded DOS micro-drive Module Data Sheet

Serial port interface for microcontroller embedded into integrated power meter

RDF1. RF Receiver Decoder. Features. Applications. Description. Ordering Information. Part Number Description Packages available

Arduino ADK Back. For information on using the board with the Android OS, see Google's ADK documentation.

LIN (Local Interconnect Network):

RoHS Compliant Copper Small Form Factor Pluggable (SFP) Transceiver for Gigabit Ethernet

PN532 NFC RFID Module User Guide

Microcontroller Based Low Cost Portable PC Mouse and Keyboard Tester

Web Site: Forums: forums.parallax.com Sales: Technical:

AVR311: Using the TWI Module as I2C Slave. Introduction. Features. AVR 8-bit Microcontrollers APPLICATION NOTE

Lab Experiment 1: The LPC 2148 Education Board

User s Manual of Board Microcontroller ET-MEGA2560-ADK ET-MEGA2560-ADK

TDA General description. 2. Features and benefits. Multiple smart card slot interface IC

Microcontroller to Sensor Interfacing Techniques

NHD-0420D3Z-FL-GBW-V3

FUNCTIONAL BLOCK DIAGRAM SDA SCL SMBALERT. SMBus SERIAL BUS INTERFACE ADDRESS SELECTION PWM CONFIG AUTOMATIC FAN SPEED CONTROL REGISTERS

Fiber Optic Monitor and Control Evaluation Kit

B Robo Claw 2 Channel 5A Motor Controller Data Sheet

ABACOM - netpio.

Advanced Data Capture and Control Systems

Eliminate Risk of Contention and Data Corruption in RS-485 Communications

Transcription:

Embedded Systems Design Course Applying the mbed microcontroller Serial communications with I 2 C These course notes are written by R.Toulson (Anglia Ruskin University) and T.Wilmshurst (University of Derby). (c) ARM 2012 These course notes accompany the textbook Fast and effective embedded system design : Applying the ARM mbed 1

Serial communications with I 2 C Introducing I 2 C Evaluating simple I 2 C communications I 2 C on the mbed Working with the TMP102 I2C temperature sensor Working with the SRF08 ultrasonic rangefinder Interfacing multiple devices on a single I2C bus Extended exercises 2

Introducing I 2 C The name I 2 C is shorthand for Standard Inter-Integrated Circuit bus I 2 C is a serial data protocol which operates with a master/slave relationship I 2 C only uses two physical wires, this means that data only travels in one direction at a time. 3

Introducing I 2 C The I 2 C protocol is a two-wire serial bus: The I 2 C communication signals are serial data (SDA) and serial clock (SCL) These two signals make it possible to support serial communication of 8-bit data bytes, 7-bit device addresses as well as control bits Using just two wires makes it cheap and simple to implement in hardware 4

Evaluating simple I 2 C communications I 2 C has a built-in addressing scheme, which simplifies the task of linking multiple devices together. In general, the device that initiates communication is termed the master. A device being addressed by the master is called a slave. Each I 2 C-compatible slave device has a predefined device address. The slaves are therefore responsible for monitoring the bus and responding only to data and commands associate with their own address. This addressing method, however, limits the number of identical slave devices that can exist on a single I 2 C bus, as each device must have a unique address. For some devices, only a few of the address bits are user configurable. 5

Evaluating simple I 2 C communications A data transfer is made up of the Master signalling a Start Condition, followed by one or two bytes containing address and control information. The Start condition is defined by a high to low transition of SDA when SCL is high. A low to high transition of SDA while SCL is high defines a Stop condition One SCL clock pulse is generated for each SDA data bit, and data may only change when the clock is low. 6

Evaluating simple I 2 C communications The byte following the Start condition is made up of seven address bits, and one data direction bit (Read/Write) All data transferred is in units of one byte, with no limit on the number of bytes transferred in one message. Each byte must be followed by a 1-bit acknowledge from the receiver, during which time the transmitter relinquishes SDA control. 7

I 2 C on the mbed The mbed I 2 C library functions are shown in the table below: I2C Functions I2C frequency read read write write start stop An I2C Master, used for communicating with I2C slave devices Usage Create an I 2 C Master interface, connected to the specified pins Set the frequency of the I 2 C interface Read from an I 2 C slave Read a single byte from the I 2 C bus Write to an I 2 C slave Write single byte out on the I 2 CC bus Creates a start condition on the I 2 C bus Creates a stop condition on the I 2 C bus 8

I 2 C on the mbed The I2C Interface can be used on mbed pins p9/p10 and p28/p27 Note also that the SDA and SCL data signals each need to be pulled up to 3.3V, with a resistor value which can be optimised for the exact circuit configuration; in this setup we choose 2.2 kω resistor 9

Evaluating the TMP102 I 2 C temperature sensor Configuration and data register details are given in the TMP102 data sheet http://focus.ti.com/lit/ds/sbos397b/sbos397b.pdf To configure the temperature sensor we need to: Use arrays of 8-bit values for the data variables, because the I 2 C bus can only communicate data in one bytes. Set the configuration register; we first need to send a data byte of 0x01 to specify that the Pointer Register is set to Configuration Register. Send two bytes of data to perform the configuration. A simple configuration value to initialise the TMP102 to normal mode operation is 0x60A0. To read the data register we need to: To read the data register we need to set the pointer value to 0x00. To print the data we need to convert the data from a 16-bit data reading to an actual temperature value. The conversion required is to shift the data right by 4 bits (its actually only 12-bit data held in two 8-bit registers) and to multiply by the 1-bit resolution which is 0.0625 degrees C per LSB. 10

Interfacing the TMP102 with the mbed The TMP102 can be connected to the mbed as shown: Signal TMP102 Pin Mbed Pin Notes Vcc (3.3V) 1 40 Gnd (0V) 4 1 SDA 2 9 SCL 3 10 2.2kΩ pull-up to 3.3V 2.2kΩ pull-up to 3.3V 11

Working with the TMP102 I2C temperature sensor Exercise 1: Connect the temperature sensor to an I 2 C bus. Verify that the correct data can be read by continuously display updates of temperature to the screen. Test that the temperature increases when you press your finger against the sensor. You can even try placing the sensor on something warm, for example a pocket hand warmer, in order to check that it reads temperature correctly. 12

Working with the TMP102 I2C temperature sensor The following program will configure the TMP102 sensor, read data, convert data to degrees Celsius and then display values to the screen every second: #include "mbed.h I2C tempsensor(p9, p10); //sda, sc1 Serial pc(usbtx, USBRX); //tx, rx const int addr = 0x90; char config_t[3]; char temp_read[2]; float temp; int main() { config_t[0] = 0x01; config_t[1] = 0x60; config_t[2] = 0xA0; tempsensor.write(addr, config_t, 3); config_t[0] = 0x00; tempsensor.write(addr, config_t, 1); while(1) { wait(1); } } //set pointer reg to 'config register' // config data byte1 // config data byte2 //set pointer reg to 'data register' //send to pointer 'read temp' tempsensor.read(addr, temp_read, 2); //read the two-byte temp data temp = 0.0625 * (((temp_read[0] << 8) + temp_read[1]) >> 4); //convert data pc.printf("temp = %.2f degc\n\r", temp); 13

Evaluating the SRF08 ultrasonic rangefinder Configuration and data register details are given in the SRF08 data sheet: http://www.rapidonline.com/netalogue/specs/78-1086.pdf The following information summarises the configuration and data read procedures for the SRF08: The rangefinder I 2 C address is 0xE0. The pointer value for the command register is 0x00. A data value of 0x51 to the command register initialises the range finder to operate and return data in cm. A pointer value of 0x02 prepares for 16-bit data (i.e. two bytes) to be read. 14

Interfacing the SRF08 with the mbed The SRF08 ultrasonic range finder is an I 2 C device which measures distance and proximity of items The SRF08 can be connected to the mbed as shown: 15

Working with the SRF08 ultrasonic rangefinder Exercise 2: Configure the SRF08 ultrasonic rangefinder to update distance data to the screen. The following code will perform this operation: #include "mbed.h" I2C rangefinder(p9, p10); //sda, sc1 Serial pc(usbtx, USBRX); //tx, rx const int addr = 0xE0; char config_r[2]; char range_read[2]; float range; int main() { while (1) { config_r[0] = 0x00; config_r[1] = 0x51; rangefinder.write(addr, config_r, 2); wait(0.07); config_r[0] = 0x02; rangefinder.write(addr, config_r, 1); } } //set pointer reg to cmd register' // config data byte1 //set pointer reg to 'data register' //send to pointer 'read range' //read the two-byte range data rangefinder.read(addr, range_read, 2); range = ((range_read[0] << 8) + range_read[1]); pc.printf("range = %.2f cm\n\r", range); //print range on screen wait(0.05); 16

Working with the SRF08 ultrasonic rangefinder Exercise 3: Evaluate the SRF08 datasheet to understand the different control setup and data conversion options. Now configure the SRF08 to accurately return data in inches measured to a maximum range of 10 feet. Note: 1 inch = 25.4 mm 1 foot = 12 inches 17

Interfacing multiple devices on an I 2 C bus Exercise 4: Connect both the temperature sensor and the range finder to the same I 2 C bus and verify that the correct data can be read by addressing commands appropriately. Update your screen readout to continuously display updates of temperature and detected range. 18

Extended Exercises Exercise 5: Use an ultrasonic range finder to control the position of a servo motor. When items are distant, the servo will take a 0 degrees position, but as objects come within range of the SRF08, the servo will move towards a 180 degrees position. Exercise 6: Communicate between two mbeds on an I 2 C bus. Program the master mbed to count a value from 0 to 15 and to broadcast this count value on the I 2 C bus. The slave mbed should be programmed to read the I 2 C data at regular intervals and set the onboard LEDs to display the binary count value. 19

Summary Introducing I 2 C Evaluating simple I 2 C communications I 2 C on the mbed Working with the TMP102 I2C temperature sensor Working with the SRF08 ultrasonic rangefinder Interfacing multiple devices on a single I2C bus Extended exercises 20