um-fpu Application Note 8 Developing an I 2 C Interface for um-fpu V2

Similar documents
um-fpu Application Note 7 Developing a SPI Interface for um-fpu V2

Using um-fpu64 with Arduino

um-fpu Floating Point Coprocessor V2 Datasheet Introduction um-fpu Features

Using um-fpu V3.1 with Arduino

SRF02 Ultrasonic range finder Technical Specification

um-fpu V3.1.0 Release Notes

BV4531U. I2C or Serial 6 Way Relay

um-fpu Application Note 9 Adding a Serial Connection to um-fpu V2

SRF08 Ultra sonic range finder Technical Specification

um-fpu64 IDE Integrated Development Environment User Manual Release 411 Introduction Main Features Further Information Compiling

Theory of Operation STOP CONDITION

KNJN I2C bus development boards

HDS Series I2C Application Notes

Lesson I2C. I²C (Inter-Integrated Circuit) Lab Assignment: I2C Slave Driver

I 2 C Application Note in Protocol B

LCD03 - I2C/Serial LCD Technical Documentation

ICN12. I2C to UART Bridge, ADC,DAC and I/O

LCD03 - I2C/Serial LCD Technical Documentation

SILICON MICROSTRUCTURES

BV4542. I2C or Serial 16x2 with Keypad interface

VORAGO VA108x0 I 2 C programming application note

QBridge. I2C, SPI, CAN Control Software User s Manual. Date: Rev 1.3

Application Note: AZD025 IQ Switch - ProxSense TM Series I2C Example Code for the IQS222

USB-I2C USB to I2C Communications Module Technical Specification

EZ I 2 C Slave. Features. General Description. When to use a EZ I 2 C Slave 1.50

Thermo 6 click PID: MIKROE-2769

Dual Interface LCD Display Controller

um-fpu64 Floating Point Coprocessor 28-pin Breakout Board Introduction Bare um-fpu64 28-pin Breakout Board

RFID A1 Module User Manual V1.183

The IIC interface based on ATmega8 realizes the applications of PS/2 keyboard/mouse in the system

Laboratory 5 Communication Interfaces

CAN / RS485. Product Description. Technical Reference Note. Interface Adapter. Special Features

KNJN I2C bus development boards

Exercise 2 I 2 C Management 1/7

or between microcontrollers)

XS S ERIES TM PMB US TM O PTION C ARD

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

Using the I 2 C Interface on the ATmega328P and MC908JL16

Digital UART Product Specification

Interfacing Z8 Encore! XP MCUs with an I 2 C-Based Character LCD

Application Note 31. um-fpu V3 Floating Point Calculations. Brief Overview of the um-fpu V3 chip

Two Wire Interface (TWI) also commonly called I2C

Application Note. Utilising the E2 Interface

1.3inch OLED User Manual

OLED DISPLAY MODULE. Application Notes. DD-9664FC-2A with EVK board PRODUCT NUMBER

Tutorial for I 2 C Serial Protocol

AN F²MC-16FX Family, I2C. Contents. 1 Introduction. This application note describes how to communicate via I2C with a Serial EEPROM.

I2C on the HMC6352 Compass

ELE492 Embedded System Design

Lecture 25 March 23, 2012 Introduction to Serial Communications

AMP DISPLAY INC. SPECIFICATIONS AMP DISPLAY INC 9856 SIXTH STREET RANCHO CUCAMONGA CA TEL: FAX:

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

LCD Module with I2C / Serial Interface and Keypad Control «LCD I2C/Serial» User s Guide. Copyright 2008 IMS

Supported devices: CY8C29x66, CY8C27x43, CY8C28xxx, CY8C24x23, CY8C24x33, CY8C21x23, CY8C21x34, CY8C21x45, CY8C22x45, CY8C24x94

I2C and SPI Foundation

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

LCD05 datasheet 1.0

OEM-ORP ORP. Reads mV mV. Range. 1 reading every 420ms. Response time. Any type & brand. Supported probes. Single point.

Functional block diagram AD53x1 (Analog Devices)

AN100 v1.4. EtherCAT network synchronization. Distributed clocks

MicroToys Guide: PS/2 Mouse N. Pinckney April 2005

Specification E2 Interface

This technical note is intended to provide information about the proper power-on procedure of the Kionix KMX62, KMX63 sensors.

1. Features and Benefits

ArduCAM-M-2MP Camera Shield

User Manual for TeraRanger Evo with: USB and I2C/UART backboard

Standard EEPROM ICs. Interfacing SLx 24Cxx I 2 C-Bus Serial EEPROMs to 8051 Controller Family, especially to the Siemens C500 Controller Family

User Manual for. TeraRanger Evo with: USB and I2C/UART backboard

Release Notes um-fpu64 IDE Release 411

I 2 C Communication. Embedded Systems Interfacing. 25 October 2011

Microcontroller basics

LB5900 Series Power Sensor SPI & I2C Interface Guide

RX Family, RL78 Family

Application Brief. Using the Total Phase CAN/I2C Activity Board Pro as an I2C- to- CAN Translator Application Brief by Rick Bogart

BV4615. Dual Interface Zero Keypad. Product specification. Dec 2009 V0.a. ByVac Page 1 of 11

User Manual for TeraRanger Evo single point distance sensors and backboards

SquareWear Programming Reference 1.0 Oct 10, 2012

Basics of UART Communication

CubeSense. An integrated sun and nadir sensor module. Interface Control Document

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

Manual iaq-engine Indoor Air Quality sensor

Application Note One Wire Digital Output. 1 Introduction. 2 Electrical Parameters for One Wire Interface. 3 Start and Data Transmission

The Freescale MC908JL16 Microcontroller

Programming Specifications

ARM HOW-TO GUIDE Interfacing I2C-7SEG with LPC2148 ARM

RFID MODULE Mifare Reader / Writer SL030 User Manual Version 2.4 Nov 2011 StrongLink

USB-900 Control Center User s Guide

USER MANUAL EXPERIENCE INCREDIBLE PERFORMANCE V2.3

JMY504M User's Manual

Application Note 101 um-fpu64. Reading GPS Data. Microcontroller. GPS Receiver. Introduction. um-fpu64

MPU-32 AND FPU-32 TIA-485 NETWORK

DELPHI CORPORATION. LIN to RS-232 Gateway Systems Analysis INterface Tool (SAINT) Users Guide

BV4109. Serial LCD Controller. Product specification November ByVac 2006 ByVac Page 1 of 12

JMY505G User's Manual

SAINT2. System Analysis Interface Tool 2. Emulation User Guide. Version 2.5. May 27, Copyright Delphi Automotive Systems Corporation 2009, 2010

DS Wire Digital Thermometer and Thermostat

Using an Analog Devices AD774X Capacitance-to-Digital Converter for Differential Button Sensor Operation

RFID MODULE. Mifare Read/Write Module. CM030 User Manual. Version 2.1 Apr 2010 chenmingcard

BL24C02/BL24C04/BL24C08/BL24C16

HDV100A3 Command Response Protocol

Transcription:

um-fpu Application Note 8 Developing an I 2 C Interface for um-fpu V2 This application note describes a suggested method of developing support software for connecting a microcontroller to the um-fpu V2 floating point coprocessor using an I 2 C interface. Introduction Micromega provides support software for many popular microcontrollers, so it s worth checking the Micromega website ( http://www.micromegacorp.com ) to see if software is already available for your microcontroller, or email info@micromegacorp.com to enquire about any plans for development. If support is not currently available for your microcontroller, you can easily develop your own support software. This application note describes a suggested method for developing an I 2 C interface. Since implementation details vary with each different microcontroller, pseudo-code is used to describe the actions of the each routine, which can then be translated into assembly code, C or Basic for your microcontroller. Additional Documents Before getting started it is recommended that you review the um-fpu V2 Datasheet, and the um-fpu V2 Instruction Set documents. It is also recommended that the serial interface for the um-fpu debug monitor be connected as described in the um-fpu V2 Datasheet. This provides access to valuable debugging information while testing the support routines. Support software and documentation provided by Micromega for other microcontrollers can also serve as a good example of the code you will need to develop. I 2 C Interface The I 2 C interface uses two bi-directional lines, SCL and SDA, that are connected through a pull-up resistor to the positive supply voltage, and shared by all connected devices. The um-fpu can handle I 2 C data speeds up to 400 khz. I 2 C Connection Microcontroller Pins SDA Note: SDA and SCL must have pull-up resistors as required by the I2C bus. SCL +5V um-fpu CS VDD SOUT TSTIN SCL TSTOUT VSS SDA +5V RS-232 Rx RS-232 Tx Each connected device must have a unique slave address. The um-fpu uses the 7-bit address mode. Data is transferred using a protocol that consists of a Start condition, followed by data, and terminated by a Stop condition (or in some cases a new Start conditon). The first byte following the Start condition is the 7-bit um-fpu slave address, followed by an 8th bit which specifies whether the microcontroller wishes to write Micromega Corporation 1 Revised 2005-05-05

data to the um-fpu (0), or read data from the um-fpu (1). The default slave address for the um-fpu is 1100100x (binary). expressed as a 7-bit value (no Read/Write bit), the default um-fpu address is 0x64 (hex), or 100 (decimal) expressed as a 8-bit value (Read/Write bit set to zero) the default um-fpu address is 0xC8 (hex), or 200 (decimal) The slave address can be changed to another value and stored in nonvolatile flash memory using the builtin serial debug monitor, as described in the um-fpu V2 Datasheet. The following diagrams show the write and read data transfers. The write transfer consists of a start condition, slave address, write bit, and register address, followed by 0 to n data bytes and a stop condition. A read transfer is normally preceded by a write transfer to select the register to read from. The read transfer consists of a start condition, slave address, and read bit, followed by 0 to n data bytes and a stop condition. A NAK should be sent on the last byte of a read transfer. Slave Address I 2 C Write Data Transfer S 1100100 0 A aaaaaaaa A dddddddd A dddddddd A P S - Start Condition A - ACK/NAK P - Stop Condition Register Address Data Data I 2 C Read Data Transfer 0 to n data bytes Slave Address Data Data S 1100100 1 A dddddddd A dddddddd A P S - Start Condition A - ACK/NAK P - Stop Condition I 2 C Device Level Support Routines 1 to n data bytes I 2 C Registers Register Address Write Read 0 Data Data / Status 1 Reset Buffer Space The I 2 C interface can be implemented with the following device level support routines: i2c_master initializes the I 2 C interface for master mode sends the Start condition sends the Stop condition i2c_write writes a byte of data and s the ACK/NAK value i2c_readack reads a byte of data and responds with an ACK fpu_readnak reads a byte of data and responds with a NAK Implementation of the I 2 C device level support routines is not discussed in this application note. These are common routines for use with any I 2 C device, and most compilers for microcontrollers provide support for these or similar functions. Basic compilers generally have commands such as I2CWRITE, I2CREAD that Micromega Corporation 2 um-fpu Application Note 8

allows writing and reading of multiple bytes to I 2 C devices. They handle the start condition, stop condition and address byte. If you need to develop your own routines, there are many examples available to work from. um-fpu Device Level Support Routines The interface with the um-fpu is described in terms of the I 2 C device level support routines listed above. fpu_reset fpu_startread fpu_readbyte fpu_wait fpu_readdelay resets the um-fpu starts a write transfer starts a read transfer reads an 8-bit byte from the um-fpu waits until the um-fpu buffer is empty implements the required read delay The steps required to implement the support routines are as follows: 1. Implement initial version of fpu_reset 2. Implement 3. Implement fpu_startread 4. Implement fpu_readbyte 5. Add synchronization check to fpu_reset 6. Implement fpu_wait 7. Implement fpu_readdelay 8. Create include file with um-fpu opcode definitions Step 1 Implement initial version of fpu_reset The um-fpu must be reset at the start of every program to establish synchronization with the microprocessor. This is the first routine that needs to be implemented. The fpu_reset routine sends the reset command, waits for the um-fpu to complete the reset code, then checks for proper synchronization by sending a SYNC opcode (0xF0) and reading the response byte. Since we have not yet developed the code to send and read data, we will add the synchronization check later (in step 5). sync character unsigned char fpu_reset(void); ; send Start condition i2c_write(0xc8) ; send write address (um-fpu address plus write bit) i2c_write(1) ; select control register (register 1) i2c_write(0) ; write 0 to control register (reset) ; send Stop condition delay for 8 milliseconds ; wait for reset to complete Debug Monitor: Whenever a reset occurs, the following message is displayed by the debug monitor: {RESET} Step 2 Implement This routine starts a write transfer to the um-fpu, and is called before sending any instructions to the um- FPU. Data is sent to the um-fpu using the i2c_write routine. The function is called to terminate a write transfer. Micromega Corporation 3 um-fpu Application Note 8

void (void); ; send Start condition i2c_write(0xc8) ; send write address (um-fpu address plus write bit) i2c_write(0) ; select data register (register 0) Write a test routine to send three bytes to the um-fpu (e.g. 0x00, 0xFF and 0xAA). fpu_reset i2c_write(0x00) i2c_write(0xff) i2c_write(0xaa) ( Debug Monitor: If the instructions are received properly by the um-fpu, the debug monitor will display the following: 00 FF AA Step 3 Implement fpu_startread This routine starts a read transfer, and is called before reading any data from the um-fpu. Data is read from the um-fpu using either the i2c_readack or i2c_readnak functions. If multiple bytes are read, i2c_readack should be used for all bytes except the last byte. To ensure that the read transfer is terminated properly, the last byte must be read using i2c_readnak. If only a single byte is read, i2c_readnak should be used. The function is called to terminate a read transfer. void fpu_startread(void); ; send Start condition, Write address, and select register 0 ; send new Start condition i2c_write(0xc9) ; send read address (um-fpu address plus read bit) Step 4 Implement fpu_readbyte This routine can be called after any instruction that s data from the um-fpu. It waits for the Read Setup Delay, then starts a read transfer, reads a single byte and terminates the read transfer. The byte read from the um-fpu is ed. 8-bit value unsigned char fpu_readbyte(void); fpu_readdelay fpu_startread n = i2c_readnak n ; wait for read delay ; send Start condition and Read address ; read byte from um-fpu ; end the read transfer ; the byte Micromega Corporation 4 um-fpu Application Note 8

Write a test routine to send the SYNC opcode (0xF0) to the um-fpu and read the byte that is ed. If SYNC is successful, a 0x5C byte will be ed. The sequence is as follows: i2c_write(0xf0) n = fpu_readbyte ; start write transfer ; send SYNC command ; stop write transfer ; read the value Debug Monitor: If the instructions are received properly by the um-fpu, the debug monitor will display the following: F0:5C Step 5 Add synchronization check to fpu_reset Add the synchronization code shown above to the end of the fpu_reset routine. The byte that is read after sending the SYNC opcode is ed by fpu_reset. The calling routine can check if the value is 0x5C to ensure that the reset and synchronization was successful. Note: In all other situations fpu_wait must be called before sending an opcode that s data, but fpu_wait is specifically not used in the fpu_reset routine, since an 8 millisecond delay immediately precedes it, and the um-fpu will always be ready if the reset is successful. If the reset is not successful an fpu_wait could wait indefinitely, so by not including it, the fpu_reset routine will always with a value. Step 6 Implement fpu_wait The fpu_wait routine is used to ensure that the 32-byte instruction buffer and the debug trace buffer are both empty. The fpu_wait routine must always be called before data is read from the um-fpu. It should also be called at least once for every 32 bytes of output to ensure that the instruction buffer doesn t overflow. The busy/ready status is ed whenever the data register is read and no data is waiting to be ed. If the um-fpu is ready, a zero byte is ed. If the um-fpu is busy, either executing instructions, or because the debug monitor is active, a 0x80 byte is ed. The fpu_wait routine continues to read the busy/ready status until the um-fpu is ready. void fpu_wait(void); loop: fpu_startread databyte = i2c_readnak if databyte <> 0 then goto loop Step 7 Implement fpu_readdelay ; read busy/ready status ; wait until ready Instructions that read data from the um-fpu require a minimum 180 microseconds delay after the opcode has been sent before data can be read (or 90 microseconds if debug trace is not enabled). The read delay routine simply delays for 180 microseconds. In some implementations, the fpu_readdelay routine may not be required if sufficient delay occurs due to the overhead associated with I 2 C bus protocol. For future compatibility, and when operating at higher speeds, it is a good idea to still implement code using fpu_readdelay before reading data. Micromega Corporation 5 um-fpu Application Note 8

void fpu_readdelay(void); delay for 180 microseconds ; delay for Read Setup Delay Step 8 Create include file with um-fpu opcode definitions To make it easer to write code for the um-fpu, an include file should be created that contains definitions for all of the um-fpu opcodes and the sync character. Various include files are available on the Micromega website and can easily be adapted as required. Examples using the Device Level Support Routines Calculate y = 5x + 30 ; start write transfer i2c_write(selecta+y) ; select Y register i2c_write(loadbyte) ; load 5 to register 0 and convert to floating point i2c_write(5) i2c_write(fset) ; y = 5.0 i2c_write(fmul+x) ; y = y * x i2c_write(loadbyte) i2c_write(30) ; load 30 to register 0 and convert to floatint point i2c_write(fadd) ; y = y + 30 ; end write transfer Read byte from um-fpu register n fpu_wait i2c_write(selecta+n) i2c_write(xop) i2c_write(readbyte) n = fpu_readbyte ; wait until um-fpu is ready ; start write transfer ; select N register (32-bit integer value) ; send READBYTE instruction ; end the write transfer ; read the byte Adding Additional Support Routines The five device level support routines developed above provide all of the necessary support for using the um-fpu with your microcontroller. Using these device level routines, additional routines can be developed to provide a higher level of support. Examples might include: print_float print_long print_version load_float load_long load_floatstr load_longstr print formatted floating point number print formatted long integer number print um-fpu version number load floating point value load long integer value load floating point string load long integer string Further Information Check the Micromega website at www.micromegacorp.com for up-to-date information. Micromega Corporation 6 um-fpu Application Note 8