Freescale Semiconductor, Inc.

Similar documents
Add a Non-Volatile Clock to the MC68HC705J1A. Some applications of using the DS1307 are:

Freescale Semiconductor, I

AN1745. Interfacing the HC705C8A to an LCD Module By Mark Glenewinkel Consumer Systems Group Austin, Texas. Introduction

AN1818. Motorola Semiconductor Application Note

IIC Master on the MC9RS08KA2 Inga Harris East Kilbride, Scotland

Freescale Semiconductor, I

AN1742. Programming the 68HC705J1A In-Circuit By Chris Falk CSG Product Engineering Austin, Texas. Introduction. Overview

AN1239. HC05 MCU Keypad Decoding Techniques Using the MC68HC705J1A. Introduction

INTRODUCTION HARDWARE INTERFACE

Parallel Data Transfer. Suppose you need to transfer data from one HCS12 to another. How can you do this?

Preliminary Data MOS IC. Type Ordering Code Package SDA Q67100-H5092 P-DIP-8-1

Embedded Systems and Software. Serial Interconnect Buses I 2 C (SMB) and SPI

Preliminary Data MOS IC. Type Ordering Code Package SDA Q67100-H5096 P-DIP-8-1

AN-HK-32. In-Circuit Programming of FLASH Memory in the MC68HC908GP32. nc... Freescale Semiconductor, I. PART 1 Introduction

AN-HK-33. In-Circuit Programming of FLASH Memory in the MC68HC908JL3. Roger Fan Applications Engineering Microcontroller Division Hong Kong

MC68705P3 Bootstrap ROM

AN1228. Motorola Semiconductor Application Note. Interfacing the M68HC05 MCU to the MC A/D Converter. Freescale Semiconductor, I.

Design and development of embedded systems for the Internet of Things (IoT) Fabio Angeletti Fabrizio Gattuso

Introduction to I2C & SPI. Chapter 22

Application Note. Interfacing the CS5521/22/23/24/28 to the 68HC05. Figure 1. 3-Wire and 4-Wire Interfaces

Microcontrollers and Interfacing

Introduction the Serial Communications Parallel Communications Parallel Communications with Handshaking Serial Communications

Application Note. Interfacing the CS5525/6/9 to the 68HC05. By Keith Coffey MOSI (PD3) SDO MISO (PD2) SCLK. Figure 1. 3-Wire and 4-Wire Interfaces

Lecture 25 March 23, 2012 Introduction to Serial Communications

TUG Combo Board

MC68705U3 Bootstrap ROM

The PC's keyboard. PC Keyboard Theory. Quality Information in one Place...

1.3inch OLED User Manual

Microcontroller basics

Tutorial for I 2 C Serial Protocol

AN1298. Variations in the Motorola MC68HC(7)05Cx Family By Joanne Field CSIC Applications. Introduction

Growing Together Globally Serial Communication Design In Embedded System

Messaging Strategies for a Remote Temperature and Pressure Monitor

Emulating I2C Bus Master by using FlexIO

GT24C02. 2-Wire. 2Kb Serial EEPROM (Smart Card application)

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING. EE Microcontroller Based System Design

How to Implement I 2 C Serial Communication Using Intel MCS-51 Microcontrollers

2-Wire, 5-Bit DAC with Three Digital Outputs

BL24C02/BL24C04/BL24C08/BL24C16

nc. SPI - Serial peripheral interface (usually pronounced spy). SPI is a standard protocol and a synchronous serial interface that includes a clock li

AN Kbyte Addressing with the M68HC11. Overview

Development and research of different architectures of I 2 C bus controller. E. Vasiliev, MIET

FM24C Kb FRAM Serial Memory Features

Serial Peripheral Interface. What is it? Basic SPI. Capabilities. Protocol. Pros and Cons. Uses

AN1227. Using 9346 Series Serial EEPROMs with 6805 Series Microcontrollers. Abstract

AN1292. Adding a Voice User Interface to M68HC05 Applications. nc... Freescale Semiconductor, I. Introduction

instruction 1 Fri Oct 13 13:05:

Implementation of MCU Invariant I2C Slave Driver Using Bit Banging

SILICON MICROSTRUCTURES

Section 16. Basic Sychronous Serial Port (BSSP)

Fremont Micro Devices, Inc.

McMaster University Embedded Systems. Computer Engineering 4DS4 Lecture 6 Serial Peripherals Amin Vali Feb. 2016

INTRODUCTION HARDWARE INTERFACE

AN1742. Motorola Semiconductor Application Note. Programming the 68HC705J1A In-Circuit By Chris Falk CSG Product Engineering Austin, Texas

Theory of Operation STOP CONDITION

Infineon C167CR microcontroller, 256 kb external. RAM and 256 kb external (Flash) EEPROM. - Small single-board computer (SBC) with an

DS1845 Dual NV Potentiometer and Memory

DESIGNING OF INTER INTEGRATED CIRCUIT USING VERILOG

Using the HT16K33 in DVD Player Panel Applications

GT24C WIRE. 1024K Bits. Serial EEPROM

FM24C16C-GTR. 16Kb Serial 5V F-RAM Memory. Features. Description. Pin Configuration NC NC NC VSS VDD WP SCL SDA. Ordering Information.

AN-HK-32. Motorola Semiconductor Application Note. In-Circuit Programming of FLASH Memory in the MC68HC908GP32. PART 1 Introduction

DS1676 Total Elapsed Time Recorder, Erasable

DS WIRE INTERFACE 11 DECOUPLING CAP GND

Ryerson University Department of Electrical and Computer Engineering ELE 538 Microprocessor Systems Final Examination December 8, 2003

The Cubesat Internal bus: The I2C

ACE24C512C Two-wire serial EEPROM

Part 1 Using Serial EEPROMs

FM24CL04 4Kb FRAM Serial Memory

Programming the Motorola MC68HC11 Microcontroller

INTRODUCTION WHY USE A REAL-TIME KERNEL?

FM24C16B-GTR. 16Kb Serial 5V F-RAM Memory. Features. Pin Configuration. Description. Ordering Information NC NC NC VSS VDD WP SCL SDA.

Handson Technology. I2C Specification and Devices. 1

< W3150A+ / W5100 Application Note for SPI >

Interfacing to Digital Potentiometers

I2C a learn.sparkfun.com tutorial

GT24C256 2-WIRE. 256K Bits. Serial EEPROM

512K bitstwo-wire Serial EEPROM

HCS12 Inter-Integrated Circuit(IIC) Block Guide V02.06

Inter-Integrated Circuit Bus IIC I2C TWI

MC68HC05J1A/D Rev. 1.0 HC 5 MC68HC05J1A MC68HCL05J1A MC68HSC05J1A. HCMOS Microcontroller Units TECHNICAL DATA

Universität Dortmund. IO and Peripheral Interfaces

+Denotes a lead(pb)-free/rohs-compliant package.

ZD24C32A. I 2 C-Compatible (2-wire) Serial EEPROM. 32-Kbit (4,096 x 8) DATASHEET. Features. Description. Low Voltage Operation

DS1682 Total-Elapsed-Time Recorder with Alarm

RM24C64AF 64-Kbit 1.65V Minimum Non-volatile Fast Write Serial EEPROM I 2 C Bus

Using FlexIO to emulate communications and timing peripherals

*********************************************** * MOR Byte Definition * *********************************************** org MOR fcb $20

University of Florida EEL 4744 Fall 1998 Dr. Eric M. Schwartz

AT24C01A/02/04/08/16. 2-Wire Serial CMOS E 2 PROM. Features. Description. Pin Configurations. 1K (128 x 8) 2K (256 x 8) 4K (512 x 8) 8K (1024 x 8)

JTAG and I 2 C on ELMB

PIC16C7X 11.0 SYNCHRONOUS SERIAL PORT (SSP) MODULE SSP Module Overview. Applicable Devices

Hello, and welcome to this presentation of the STM32 I²C interface. It covers the main features of this communication interface, which is widely used

Lecture 5: Computing Platforms. Asbjørn Djupdal ARM Norway, IDI NTNU 2013 TDT

M68HC08 Microcontroller The MC68HC908GP32. General Description. MCU Block Diagram CPU08 1

AN-HK-33. Motorola Semiconductor Application Note. In-Circuit Programming of FLASH Memory in the MC68HC908JL3. PART 1 Introduction

GT34C02. 2Kb SPD EEPROM

Nuvoton NCT5655Y/W. 16-bit I 2 C-bus and SMBus GPIO controller with interrupt. Revision: 1.0 Date: May, 2016 NCT5655Y/W

MC68HC12 Parallel I/O

CprE 488 Embedded Systems Design. Lecture 4 Interfacing Technologies

Transcription:

Order this document by /D Software I 2 C Communications By Brad Bierschenk MMD Applications Engineering Austin, Texas Introduction I 2 C Overview The I 2 C (inter-integrated circuit) protocol is a 2-wire serial communications interface, implemented on numerous microcontrollers and peripheral devices. Many MCUs (microcontroller units) do not have an I 2 C module, yet they are required to communicate to 2-wire, or I 2 C, devices. This application note describes a method of communicating on an I 2 C bus by controlling digital input/output (I/O) pins. This "bit-banged" method can be implemented on any Freescale MCU. I 2 C is a 2-wire communications link, requiring a clock line (SCK) and a data line (SDA) to communicate. The frequency of the I 2 C clock can go up to 100 Kbits per second for standard mode, and up to 400 Kbits per second for fast mode. An I 2 C bus has both master devices and slave devices attached to it. A master is defined as a device which initiates a transfer, generates clock signals, and terminates a transfer. A slave device is simply a device Motorola, Inc., 1999

nc. addressed by a master. I 2 C provides for multiple masters on the same bus. The I 2 C also provides some error checking by acknowledgment bits during byte transfers. The application presented in this document illustrates a limited version of the I 2 C specification. It is not intended to implement all the features of an I 2 C bus. It only provides the basic functionality required to transmit as a master device to slave devices through a 2-wire interface. The advantage of this method is it uses standard digital input/output pins available on any Freescale MCU. The application presented here provides the following functionality: 7-bit addressing Single master transmitter Multiple data bytes within a serial transfer Serial clock frequency of approximately 28 khz (arbitrary) Acknowledgment polling for error checking By controlling two digital I/O pins, one can simulate an I 2 C transfer. When the I/O pins are CMOS and not open-drain, some safegaurds have to be implemented. A series resistor should be used between the CMOS output pin and the receiver s input pin. This will provide some current limiting should the two devices attempt to output conflicting logic levels. The other consideration is supporting a logic high for any open-drain receiver pins. A pullup resistor can be used at the receiver s open-drain pin to passively pullup to the supply voltage, when the pin is not being actively driven low. This pullup resistor should be carefully chosen, so that when the master pin drives low, a valid V IL level is presented to the I 2 C receiver s pin. The diagram shown in Figure 1 illustrates a way to connect digital I/O pins to an external I 2 C receiver device. In this case, a MC68HC705J1A microcontroller is connected to a Maxim MAX517 DAC (Digital-to- Analog Converter). The MAX517 has a 2-wire interface that is I 2 C compatible. The MC68HC705J1A has CMOS bidirectional input/output 2

nc. I 2 C Overview pins. When connected as shown, successful I 2 C communications can be made to the external IC. An I 2 C transfer is composed of specific stages, defined by the states of the two wires. Figure 2 shows the timing between the clock and data lines. To signal the beginning of a transmission, a START condition is presented to the bus. This START condition is indicated by a falling edge on SDA, while SCK is held high. Once the START condition has been driven, the master device places a 7-bit address on the bus, with its most significant bit first. This address corresponds to the address of the I 2 C device the transfer is intended for. The eighth bit following the 7-bit address can be high or low, depending on whether it is a "read" or "write" operation. PA0 PA1 MC68HC705J1A 1 k 1 k 30 k DAC OUTPUT CLOCK -> <- DATA -> OUT0 V SS SCL SDA Figure 1. Hardware Diagram MAX517 DAC REF0 V DD AD0 AD1 SDA START A7 A6 A5 A4 A3 A2 A1 R/W Ack D8 D7 D6 D5 D4 D3 D2 D1 Ack STOP SCL Figure 2. Example of I 2 C Transfer Timing 3

NOTE: nc. I 2 C Overview As with all bytes transferred on the I 2 C bus, a ninth clock cycle is used as an acknowledgment. The SDA line is read during this ninth clock cycle and signifies whether or not the byte is acknowledged. The receiver will drive the SDA line low during the ninth clock cycle if it acknowledges the byte transmission. Any number of data bytes can follow the address byte, each composed of eight data bits and a ninth acknowledge bit. To end a transfer, a STOP condition is imposed on the I 2 C bus. The STOP condition is indicated by a rising edge on SDA, while the SCK line is held high. To avoid unwanted START or STOP conditions, the software must transition the SDA pin only while the SCK line is held low. A listing of assembly code that shows a specific implementation of I 2 Cin software follows this text. This application does require some software overhead, but is somewhat interruptible as the I 2 C bus is completely synchronous. An implementation that requires less software overhead could be created using a more automated timing source, such as a freerunning counter or real-time interrupt. The code shows how a MC68HC705J1A microcontroller can be connected to an I 2 C peripheral, in this case a Maxim MAX517 DAC. The software continuously sends a write command to the DAC, ramping the digital value for the DAC from $00 to $FF and back down again. This creates a triangular wave at the output of the DAC. The point is not to show a completely useful DAC application, but to illustrate the use of digital input/output pins as an I 2 C master device.

nc. Code Listings Code Listings * -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- * TRIANGLE.ASM * -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- * Purpose: Test of I2C bit-banging using the J1A * Target: 705J1A * Author: Brad Bierschenk, MMD Applications * -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- * Tested using Maxim I 2 C DAC IC, MAX517 * Has a "2-wire interface" (another word for I 2 C) * * This code continuously sends 8-bit data to the * Digital to Analog IC, incrementing from $00 to * $FF, and back down again. This creates a * triangular waveform at the output of the DAC chip. * * The SCL frequency is approximately 28 khz. This is * completely arbitrary. * Assembler Equates RAMSPACE EQU $C0 ;RAM start address ROMSPACE EQU $300 ;EPROM start address PORTA EQU $00 ;Port A PORTB EQU $01 ;Port B DDRA EQU $04 ;Data direction A DDRB EQU $05 ;Data direction B * Emulated I2C lines on Port A pins * Need a clock (SCL) and data (SDA) SCL EQU 0 ;Serial clock SDA EQU 1 ;Serial data DACADDR EQU $2C ;Slave address of DAC * RAM Variables ORG RAMSPACE BitCounter RMB 1 ;Used to count bits in a Tx Value RMB 1 ;Used to store data value Direction RMB 1 ;Indicates increment or ;decrement * Start of program code ORG ROMSPACE ;Start of EPROM Start: ;Initialize variables CLR Value ;Clear all RAM variables CLR BitCounter CLR Direction ;Setup parallel ports LDA #$03 ;PA0 and PA1 as outputs STA PORTA ;driven high to start STA DDRA 5

nc. * This main loop just ramps up and down the data * value that is sent to the DAC chip. TxLoop: LDA Direction ;Increment or decrement? BEQ GoUp GoDown: LDA Value ;Decrement GD2: GoUp: GU2: BNE CLR GD2 Direction ;Change direction if needed BRA SendIt DEC Value ;Decrement the data value BRA SendIt LDA Value ;Increment CMP #$FF ;Change direction if needed BNE GU2 INC Direction ;Increment the data value BRA SendIt INC Value * Send the I 2 C transmission, including START, address, * data, and STOP SendIt: ;START condition JSR I2CStartBit ;Give START condition ;ADDRESS byte, consists of 7-bit address + 0 as LSbit LDA #DACADDR ;Slave device address ASLA ;Need this to align address JSR I2CTxByte ;Send the eight bits ;DATA bytes LDA #$00 ;$00 is command byte for DAC JSR I2CTxByte ;Send the 8 bits LDA Value ;Value is value to set DAC JSR I2CTxByte ;Send it ;STOP condition JSR I2CStopBit ;Give STOP condition JSR I2CBitDelay ;Wait a bit BRA TxLoop ;Repeat ; I2CTxByte ; Transmit the byte in Acc to the SDA pin ; (Acc will not be restored on return) ; Must be careful to change SDA values only while SCL is low, ; otherwise a STOP or START could be implied I2CTxByte: ;Initialize variable LDX #$08 STX BitCounter 6

nc. Code Listings I2CNextBit: ROLA ;Shift MSbit into Carry BCC SendLow ;Send low bit or high bit SendHigh: BSET SDA,PORTA ;Set the data bit value JSR I2CSetupDelay ;Give some time for data setup BSET SCL,PORTA ;Clock it in JSR I2CBitDelay ;Wait a bit BRA I2CTxCont ;Continue SendLow: BCLR SDA,PORTA JSR I2CSetupDelay BSET SCL,PORTA JSR I2CBitDelay I2CTxCont: BCLR SCL,PORTA ;Restore clock to low state DEC BitCounter ;Decrement the bit counter BEQ I2CAckPoll ;Last bit? BRA I2CNextBit I2CAckPoll: BSET SDA,PORTA BCLR SDA,DDRA ;Set SDA as input JSR I2CSetupDelay BSET SCL,PORTA ;Clock the line to get ACK JSR I2CBitDelay BRSET SDA,PORTA,I2CNoAck ;Look for ACK from slave ;device BCLR SCL,PORTA ;Restore clock line BSET SDA,DDRA ;SDA back as output ;No acknowledgment received from slave device ;Some error action can be performed here ;For now, just restore the bus I2CNoAck: BCLR SCL,PORTA BSET SDA,DDRA ; A START condition is defined as a falling edge ; on SDA while SCL is high ;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=- I2CStartBit: BCLR SDA,PORTA JSR I2CBitDelay BCLR SCL,PORTA ; A STOP condition is defined as a rising edge ; on SDA while SCL is high I2CStopBit: BCLR SDA,PORTA BSET SCL,PORTA BSET SDA,PORTA JSR I2CBitDelay 7

nc. N O N - D I S C L O S U R E A G R E E M E N T R E Q U I R E D ;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- ; Provide some data setup time to allow ; SDA to stabilize in slave device ; Completely arbitrary delay (10 cycles) I2CSetupDelay: ; Bit delay to provide (approximately) the desired ; SCL frequency ; Again, this is arbitrary (16 cycles) I2CBitDelay: * Vector Definitions ORG $07FE ;Reset vector FDB Start