Interfacing CMA3000-D01 to an MSP430 ultra low-power microcontroller

Similar documents
Interfacing CMR3000-D01 to an MSP430 ultra low-power microcontroller

ECE2049: Embedded Computing in Engineering Design C Term Spring 2018

4 Degrees of Freedom MEMS Sensor Improvements

EEL 4924 Electrical Engineering Design (Senior Design) Team Baudiophile. Wireless Headphones

volatile int results[5]; // variables para la interrupcion del acelerometro //Funciones del acelerometro para mandar y recibir información

Texas Instruments Mixed Signal Processor Tutorial Abstract

// Conditions for 9600/4=2400 Baud SW UART, SMCLK = 1MHz #define Bitime_5 0x05*4 // ~ 0.5 bit length + small adjustment #define Bitime 13*4//0x0D

What is an Interrupt?

Lab 1: I/O, timers, interrupts on the ez430-rf2500

MSP430. More on MSP430

Timers and Clocks CS4101 嵌入式系統概論. Prof. Chung-Ta King. Department of Computer Science National Tsing Hua University, Taiwan

CPE/EE 323 Introduction to Embedded Computer Systems Homework V

CPE 323 Introduction to Embedded Computer Systems: MSP430 System Architecture An Overview

CPE 323: MSP430 Serial Communication

In-Depth with MSP430 s New Communication Interfaces

Interrupts, Low Power Modes

MSP430 Interrupts. Change value of internal variable (count) Read a data value (sensor, receive) Write a data value (actuator, send)

Lecture 5: MSP430 Interrupt

Getting Started with the Texas Instruments ez430

6. General purpose Input/Output

Network Embedded Systems Sensor Networks Fall Hardware. Marcus Chang,

CPE 323: MSP430 Timers

Hands-On: Implementing an RF link with MSP430 and CC1100

Copyright 2015 by Stephen A. Zajac & Gregory M. Wierzba. All rights reserved..spring 2015.

CPE 325: Embedded Systems Laboratory Laboratory #7 Tutorial MSP430 Timers, Watchdog Timer, Timers A and B

Two Wire Interface (TWI) also commonly called I2C

IV B.Tech. I Sem (R13) ECE : Embedded Systems : UNIT -2 1 UNIT 2

임베디드시스템기초 (# ) #11. Serial Communications 한림대학교전자공학과이선우

ECE2049: Embedded Computing in Engineering Design C Term Spring 2019 Lecture #22: MSP430F5529 Operating Mode & the WDT

ECE2049: Embedded Computing in Engineering Design C Term Spring Lecture #7: More Digital IO

An SPI Temperature Sensor Interface with the Z8 Encore! SPI Bus

ECE2049 Homework #2 The MSP430 Architecture & Basic Digital IO (DUE Friday 9/8/17 at 4 pm in class)

IV B.Tech. I Sem (R13) ECE : Embedded Systems : UNIT -4 1 UNIT 4

University of Texas at El Paso Electrical and Computer Engineering Department. EE 3176 Laboratory for Microprocessors I.

Implementation of MCU Invariant I2C Slave Driver Using Bit Banging

University of Texas at El Paso Electrical and Computer Engineering Department. EE 3176 Laboratory for Microprocessors I.

Product Family Specification

Texas Instruments Microcontroller HOW-TO GUIDE Interfacing Keypad with MSP430F5529

CPE/EE 421 Microcomputers

ECE PRACTICE EXAM #2 Clocks, Timers, and Digital I/O

Lab 4: Interrupt. CS4101 Introduction to Embedded Systems. Prof. Chung-Ta King. Department of Computer Science National Tsing Hua University, Taiwan

Master Thesis. Sub-Gigahertz Wireless Sensors For Monitoring Of Food Transportation. Faisal Ali Khan. Submitted by. Universität Bremen

ECE2049: Embedded Computing in Engineering Design A Term Fall Lecture #8: Making it work: LEDs, Buttons & Keypad

INTRODUCTION TO FLEXIO

2.996/6.971 Biomedical Devices Design Laboratory Lecture 6: Microprocessors II

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

Arduino Uno R3 INTRODUCTION

ECE2049: Embedded Computing in Engineering Design C Term Spring Lecture #11: More Clocks and Timers

Serial Peripheral Interface (SPI) Last updated 8/7/18

Why embedded systems?

Wireless Sensor Networks (WSN)

ECE2049: Embedded Computing in Engineering Design C Term Spring 2018 Lecture #20: Using SPI The DAC

17. I 2 C communication channel

MSP430F149 P3.4/UTXD0 P3.5/URXD0 P1.5 P1.6 P1.7 MSP430F149 P1.0 P5.4 P5.3 P5.2 P5.1. Figure B-1. BSL Replicator Block Diagram

ZigBee Compliant Platform 2.4G RF Low Power Transceiver Module for IEEE Standard. DATA SHEET Version B

Lab 4 Interrupts ReadMeFirst

MSP430 Interface to LMP91000 Code Library

Name: Clint Furrer Project Number: TI003 Project Description: Safety Walking Lights. Description:

Embedded Systems. 3. Hardware Software Interface. Lothar Thiele. Computer Engineering and Networks Laboratory

MSP430FG4618 Programming Reference Revision 3

Asservissement en température numérique d'une cavité ultra-stable au LPL pour le Strontium

Section 16. Basic Sychronous Serial Port (BSSP)

Emulating Dual SPI Using FlexIO

Amarjeet Singh. January 30, 2012

CPE 325: Embedded Systems Laboratory Laboratory #11 Tutorial Analog-to-Digital Converter and Digital-to-Analog Converter

Using the Z8051 MCU s USI Peripheral as an SPI Interface

LC-E201A. Application note. 1. Mechanical Specification: LC-E021A-application note page 1 of 16 Revision:

Microcontrollers and Interfacing

AD5669R - Microcontroller No-OS Driver

ECGR 4101/5101, Fall 2016: Lab 1 First Embedded Systems Project Learning Objectives:

Introduction to I2C & SPI. Chapter 22

RL78 Serial interfaces

File: /media/j/texas/my msp430/g3tr/g3tr.c Pagina 1 di 5

Freescale Semiconductor, I

ECE 4510/5530 Microcontroller Applications Week 10

Create and Add the Source File

Wireless communication for social robotics. Gu C. Department of Electrical & Computer Enginnering. National University of.

ECE 492 WINTER 2015 GROUP 2. Texas Instruments MSP430-FR Bit ADC Setup Guide

RFIC TX/RX Configuration

In this module we ll take a look at the MSP430 communications modules and the protocols that can be implemented over them.

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

VORAGO VA108x0 I 2 C programming application note

Serial Peripheral Interface (SPI)

Getting Started with ESPI Interface Using the Z8 Encore! XP F1680

C-CODE EXAMPLE FOR SCP1000-D01 PRESSURE SENSOR

Designing for Ultra-Low Power with MSP430

Serial communications with SPI

FAE Summit Interfacing the ADS8361 to the MSP430F449 Low Power Micro Controller

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

Using FlexIO to emulate communications and timing peripherals

Basics of UART Communication

@databasescaling Wednesday, 18 th April 2013

MSP430 Interface to LMP91000 Code Library

EE 456 Fall, Table 1 SPI bus signals. Figure 1 SPI Bus exchange of information between a master and a slave.

Hello, and welcome to this presentation of the STM32 Low Power Universal Asynchronous Receiver/Transmitter interface. It covers the main features of

Hello and welcome to this Renesas Interactive module that covers the Independent watchdog timer found on RX MCUs.

Alex Milenkovich 1. CPE/EE 421 Microcomputers. Course Administration. Review: Outline. Getting Started with EasyWeb2. Review: MSP bit RISC

Alex Milenkovich 1. CPE/EE 421 Microcomputers: The MSP430 Introduction. Outline

Hacettepe University

UNIT IV SERIAL COMMUNICATIONS

Transcription:

Interfacing CMA3000-D01 to an MSP430 ultra low-power microcontroller 1 INTRODUCTION The objective of this document is to show how to set up SPI/I2C communication between VTI Technologies CMA3000-D01 digital acceleration sensor component and a Texas Instruments MSP430 microcontroller. In the code examples: The MSP430 MCU is configured CMA3000-D01 measurement mode is activated An interrupt is used to read acceleration output data registers when new data is available Please refer to document "CMA3000-D0X Product Family Specification 8281000" for further information on CMA3000-D01 register addressing and SPI/I2C communication. For MSP430 related information please see Texas Instruments web pages (http://www.ti.com). 2 DEVELOPMENT HARDWARE Figure 1. From left to right, ez430-rf2500, adapter PCB VTI29631 and CMA3000-D01 chip carrier VTI Technologies Oy 1/14

ez430-rf2500 connector VTI chip carrier PCB Figure 2. Adapter PCB VTI29631 circuit diagram 3 C-CODE The example code is written for Texas Instruments ez430-rf2500 Development Tool (MSP430F2274) using IAR Embedded Workbench KickStart for MSP430 V4 IDE. To interface CMA3000-D01 to the ez430-rf2500 an adapter PCB VTI29631 is used (available through Hy-Line's web shop (http://www.hy-line.de/vti-msp430). The C-language software examples for SPI and I2C buses on the next pages shows an easy way to implement communication with the CMA3000-D01. Universal Serial Communication Interface peripheral inside the MSP430F2274 is used for communication. The codes set up an interrupt to wake up the MCU from low power mode thru CMA3000-D01 INT-pin when new data from the sensor is available. When no data is available (no interrupt) the MCU is kept in low power mode 4 (LPM4) to achieve lower current consumption. Clocks are set up so that the MCU clock frequency is 16 MHz, SPI clock is 250 khz and I2C clock 100 khz. These are not ideal for typical applications, but allow us to demonstrate how to set up clock domains while simultaneously emphasizing that when using SPI bus there must be at least 11 SCK clock periods between SPI frames. VTI Technologies Oy 2/14

3.1 SPI Interface Example Code flowchart: Figure 3. SPI Example Code Flowchart VTI Technologies Oy 3/14

C-Code Example, SPI Interface //****************************************************************************** // MSP430F2274 Demo - USCI_B0, SPI Interface to CMA3000 Acceleration Sensor // // Uses Texas Instruments ez430-rf2500 Development Tool with VTI Adapter PCB // VTI29631A0. Wireless connection not used. // //****************************************************************************** // CONSTANTS #define XTAL 16000000L #define TICKSPERMS (XTAL / 1000 / 5-1) #define TICKSPERUS (TICKSPERMS / 1000) // LIBRARIES #include "msp430x22x4.h" // PORT DEFINITIONS #define PORT_INT_IN P2IN #define PORT_INT_OUT P2OUT #define PORT_INT_DIR P2DIR #define PORT_INT_IE P2IE #define PORT_INT_IES P2IES #define PORT_INT_IFG P2IFG #define PORT_INT_VECTOR PORT2_VECTOR #define PORT_CSB_OUT #define PORT_CSB_DIR #define PORT_SPI_DIR #define PORT_SPI_SEL P4OUT P4DIR P3DIR P3SEL // REGISTER AND FLAG DEFINITIONS #define TX_BUFFER UCB0TXBUF #define RX_BUFFER UCB0RXBUF #define IRQ_REG IFG2 #define RX_IFG UCB0RXIFG #define SPI_CTL0 UCB0CTL0 #define SPI_CTL1 UCB0CTL1 #define SPI_BR0 UCB0BR0 #define SPI_BR1 UCB0BR1 // CMA3000 Registers #define WHO_AM_I #define REVID #define CTRL #define STATUS #define RSTR #define INT_STATUS #define DOUTX #define DOUTY #define DOUTZ #define MDTHR #define MDFFTMR #define FFTHR #define I2C_ADDR 0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0A 0x0B 0x0C VTI Technologies Oy 4/14

// Control Register setup #define G_RANGE_2 0x80 // 2g range #define INT_LEVEL_LOW 0x40 // INT active high #define MDET_NO_EXIT 0x20 // Remain in motion detection mode #define I2C_DIS 0x10 // I2C disabled #define MODE_PD 0x00 // Power Down #define MODE_100 0x02 // Measurement mode 100 Hz ODR #define MODE_400 0x04 // Measurement mode 400 Hz ODR #define MODE_40 0x06 // Measurement mode 40 Hz ODR #define MODE_MD_10 0x08 // Motion detection mode 10 Hz ODR #define MODE_FF_100 0x0A // Free fall detection mode 100 Hz ODR #define MODE_FF_400 0x0C // Free fall detection mode 400 Hz ODR #define INT_DIS 0x01 // Interrupts enabled // PIN DEFINITIONS #define PIN_INT #define PIN_CSB #define PIN_MOSI #define PIN_MISO #define PIN_SCK BIT4 BIT3 BIT1 BIT2 BIT3 // FUNCTION PROTOTYPES unsigned char ReadRegister(unsigned char Address); unsigned char WriteRegister(unsigned char Address, unsigned char Data); void wait_ms(unsigned short ms); void wait_us(unsigned short us); unsigned char Data; unsigned char RevID; unsigned char Xdata; unsigned char Ydata; unsigned char Zdata; void main(void) WDTCTL = WDTPW + WDTHOLD; BCSCTL1 = CALBC1_16MHZ; DCOCTL = CALDCO_16MHZ; BCSCTL2 = DIVS_3; PORT_INT_DIR &= ~PIN_INT; PORT_INT_IE = PIN_INT; PORT_INT_IES = 0x00; PORT_INT_IFG &= ~PIN_INT; PORT_CSB_DIR = PIN_CSB; PORT_CSB_OUT = PIN_CSB; // Stop watchdog timer // Set DCO to calibrated 16MHz // SMCLK to 2 MHz // INT pin interrupt enabled // Generate interrupt on Lo to Hi edge // Clear interrupt flag // Unselect acceleration sensor PORT_SPI_SEL = PIN_MOSI PIN_MISO PIN_SCK; // P3.3,2,1 USCI_B0 option select PORT_SPI_DIR = BIT0; // P3.0 output direction // Initialize SPI interface to acceleration sensor SPI_CTL0 = UCSYNC UCMST UCMSB UCCKPH; // SPI master, 8 data bits, MSB first, // clock idle low, data output on falling edge VTI Technologies Oy 5/14

SPI_CTL1 = UCSSEL1; // SMCLK as clock source SPI_BR0 = 0x08; // Low byte of division factor for baud rate (250 khz) SPI_BR1 = 0x00; // High byte of division factor for baud rate SPI_CTL1 &= ~UCSWRST; // Start SPI hardware RevID = ReadRegister(REVID); // Read REVID register wait_us(44); // 11 * tsck Data = WriteRegister(CTRL, G_RANGE_2 I2C_DIS MODE_400); // Activate measurement mode: 2g/400Hz wait_us(44); Xdata = ReadRegister(DOUTX); bis_sr_register(lpm4_bits + GIE); // Dummy read to generate first INT pin Lo to Hi // transition in all situations, also while debugging // Enter LPM4 w/interrupt // Port 2 interrupt service routine, INT pin #pragma vector=port_int_vector interrupt void Port_INT_ISR(void) if (PORT_INT_IN & PIN_INT) Xdata = ReadRegister(DOUTX); wait_us(44); Ydata = ReadRegister(DOUTY); wait_us(44); Zdata = ReadRegister(DOUTZ); PORT_INT_IFG &= ~PIN_INT; // Read DOUTX register // 11 * tsck // Read DOUTY register // Read DOUTZ register // Clear interrupt flag // Read a byte from the acceleration sensor unsigned char ReadRegister(unsigned char Address) unsigned char Result; Address <<= 2; PORT_CSB_OUT &= ~PIN_CSB; Result = RX_BUFFER; TX_BUFFER = Address; while (!(IRQ_REG & RX_IFG)); Result = RX_BUFFER; TX_BUFFER = 0; while (!(IRQ_REG & RX_IFG)); Result = RX_BUFFER; PORT_CSB_OUT = PIN_CSB; // Address to be shifted left by 2 and RW bit to be reset // Select acceleration sensor // Read RX buffer just to clear interrupt flag // Write address to TX buffer // Wait until new data was written into RX buffer // Read RX buffer just to clear interrupt flag // Write dummy data to TX buffer // Wait until new data was written into RX buffer // Read RX buffer // Deselect acceleration sensor // Return new data from RX buffer return Result; VTI Technologies Oy 6/14

// Write a byte to the acceleration sensor unsigned char WriteRegister(unsigned char Address, unsigned char Data) unsigned char Result; Address <<= 2; // Address to be shifted left by 2 Address = 2; // RW bit to be set PORT_CSB_OUT &= ~PIN_CSB; Result = RX_BUFFER; TX_BUFFER = Address; while (!(IRQ_REG & RX_IFG)); Result = RX_BUFFER; TX_BUFFER = Data; while (!(IRQ_REG & RX_IFG)); Result = RX_BUFFER; PORT_CSB_OUT = PIN_CSB; // Select acceleration sensor // Read RX buffer just to clear interrupt flag // Write address to TX buffer // Wait until new data was written into RX buffer // Read RX buffer just to clear interrupt flag // Write data to TX buffer // Wait until new data was written into RX buffer // Read RX buffer // Deselect acceleration sensor return Result; // wait ms void wait_ms(unsigned short ms) unsigned short a, b; for (a = ms; a > 0; a--) // outer loop takes 5 ck per round for (b = TICKSPERMS; b > 0; b--) // inner loop takes 5 ck per round asm("nop"); // wait us void wait_us(unsigned short us) unsigned short a; us *= TICKSPERUS; for (a = us; a > 0; a--) // loop takes 5 ck per round asm("nop"); VTI Technologies Oy 7/14

3.2 I2C Interface Example VTI adapter PCB VTI29631 does not support I2C use with CMA3000-D01 so to enable I2C communication with the ez430-rf2500 the PCB needs to be modified as follows: - Cut MISO/SDA trace close to J2 - Cut SCK/SCL trace close to J2 - Wire J2-4 to ground - Wire P2-15 to J2-6 - Add 10 kohm pull-up resistors from MOSI/SDA and J2-6 to +3.6V Figure 4. PCB VTI29631 modification for I2C use Cut traces Figure 5. Modified VTI29631 PCB VTI Technologies Oy 8/14

Code flowchart: Figure 6. I2C Example Code Flowchart VTI Technologies Oy 9/14

C-Code Example, I2C Interface //****************************************************************************** // MSP430F2274 Demo - USCI_B0, I2C Interface to CMA3000 Acceleration Sensor // // Uses Texas Instruments ez430-rf2500 Development Tool with VTI Adapter PCB // VTI29631A0. Wireless connection not used. Adapter PCB VTI29631 needs to be // modified for I2C to work. // //****************************************************************************** // LIBRARIES #include "msp430x22x4.h" // PORT DEFINITIONS #define PORT_INT_IN P2IN #define PORT_INT_DIR P2DIR #define PORT_INT_IE P2IE #define PORT_INT_IES P2IES #define PORT_INT_IFG P2IFG #define PORT_INT_VECTOR PORT2_VECTOR #define PORT_I2C_DIR #define PORT_I2C_SEL #define PORT_I2C_OUT P3DIR P3SEL P3OUT // REGISTER AND FLAG DEFINITIONS #define TX_BUFFER UCB0TXBUF #define RX_BUFFER UCB0RXBUF #define IRQ_REG IFG2 #define RX_IFG UCB0RXIFG #define TX_IFG UCB0TXIFG // CMA3000 Registers #define WHO_AM_I #define REVID #define CTRL #define STATUS #define RSTR #define INT_STATUS #define DOUTX #define DOUTY #define DOUTZ #define MDTHR #define MDFFTMR #define FFTHR #define I2C_ADDR 0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0A 0x0B 0x0C // Control Register setup #define G_RANGE_2 0x80 // 2g range #define INT_LEVEL_LOW 0x40 // INT active high #define MDET_NO_EXIT 0x20 // Remain in motion detection mode #define I2C_DIS 0x10 // I2C disabled #define MODE_PD 0x00 // Power Down #define MODE_100 0x02 // Measurement mode 100 Hz ODR #define MODE_400 0x04 // Measurement mode 400 Hz ODR #define MODE_40 0x06 // Measurement mode 40 Hz ODR #define MODE_MD_10 0x08 // Motion detection mode 10 Hz ODR #define MODE_FF_100 0x0A // Free fall detection mode 100 Hz ODR #define MODE_FF_400 0x0C // Free fall detection mode 400 Hz ODR #define INT_DIS 0x01 // Interrupts enabled VTI Technologies Oy 10/14

// PIN DEFINITIONS #define PIN_INT #define PIN_CSB #define PIN_MOSI #define PIN_MISO #define PIN_SCK BIT4 BIT3 BIT1 BIT2 BIT3 // FUNCTION PROTOTYPES unsigned char ReadRegister(unsigned char Address); unsigned char WriteRegister(unsigned char Address, unsigned char Data); unsigned char Data; unsigned char RevID; unsigned char Xdata; unsigned char Ydata; unsigned char Zdata; void main(void) WDTCTL = WDTPW + WDTHOLD; BCSCTL1 = CALBC1_16MHZ; DCOCTL = CALDCO_16MHZ; BCSCTL2 = DIVS_3; PORT_INT_DIR &= ~PIN_INT; PORT_INT_IE = PIN_INT; PORT_INT_IES = 0x00; PORT_INT_IFG &= ~PIN_INT; // Stop watchdog timer // Set DCO to calibrated 16MHz // SMCLK to 2 MHz // INT pin interrupt enabled // Generate interrupt on Lo to Hi edge // Clear interrupt flag // Initialize I2C interface to acceleration sensor PORT_I2C_DIR = BIT0; // Set port 3 pin 0 as output and set high. PORT_I2C_OUT = BIT0; UCB0CTL1 = UCSWRST; UCB0CTL1 = UCSSEL_2; PORT_I2C_SEL = BIT2 BIT1; UCB0CTL0 = UCMST + UCSYNC + UCMODE_3; UCB0BR0 = 20; UCB0BR1 = 0; UCB0I2CSA = 0x1C; UCB0CTL1 &= ~UCSWRST; // Put state machine in reset // SMCLK as clock source // Set port 3 pins 1 and 2 for I2C peripheral // I2C mode, master, synchronous // 2MHz/20 = 100kHz // Slave Address is 1Ch // Start I2C state machine RevID = ReadRegister(REVID); // Read REVID register Data = WriteRegister(CTRL, G_RANGE_2 MODE_400); // Activate measurement mode: 2g/400Hz Xdata = ReadRegister(DOUTX); bis_sr_register(lpm4_bits + GIE); // Dummy read to generate first INT pin Lo to Hi transition // in all situations, also while debugging // Enter LPM4 w/interrupt VTI Technologies Oy 11/14

// Port 2 interrupt service routine, INT pin #pragma vector=port_int_vector interrupt void Port_INT_ISR(void) if (PORT_INT_IN & PIN_INT) Xdata = ReadRegister(DOUTX); wait_us(110); Ydata = ReadRegister(DOUTY); wait_us(110); Zdata = ReadRegister(DOUTZ); PORT_INT_IFG &= ~PIN_INT; // Read DOUTX register // 11 * tscl // Read DOUTY register // Read DOUTZ register // Clear interrupt flag // Read a byte from the acceleration sensor unsigned char ReadRegister(unsigned char Address) unsigned char Result; // Read data from I2C slave device at the DeviceAddress specified. UCB0CTL1 = UCTR + UCTXSTT; while (!(IRQ_REG & TX_IFG)); TX_BUFFER = Address; while (!(IRQ_REG & TX_IFG)); IRQ_REG &= ~TX_IFG; // Send restart with transmit/receive bit NOT set UCB0CTL1 &= ~UCTR; UCB0CTL1 = UCTXSTT; while(ucb0ctl1 & UCTXSTT); UCB0CTL1 = UCTXSTP; while (!(IRQ_REG & RX_IFG)); Result = RX_BUFFER; while (UCB0CTL1 & UCTXSTP); IRQ_REG &= ~RX_IFG; // I2C TX, start condition // Wait for slave address transmit to complete // Load TX buffer with register address // Wait for transmit to complete // Clear USCI_B0 TX int flag // Toggle transmitter bit // I2C start condition // Wait for start to complete // I2C stop condition // Wait for receive buffer to fill // Fill receive data buffer with received byte // Wait for stop condition to complete // Clear USCI_B0 RX int flag // Return new data from RX buffer return Result; VTI Technologies Oy 12/14

// Write a byte to the acceleration sensor unsigned char WriteRegister(unsigned char Address, unsigned char Data) // Write data to I2C slave device at the DeviceAddress specified. UCB0CTL1 = UCTR + UCTXSTT; while (!(IRQ_REG & TX_IFG)); TX_BUFFER = Address; while (!(IRQ_REG & TX_IFG)); TX_BUFFER = Data; while (!(IRQ_REG & TX_IFG)); UCB0CTL1 = UCTXSTP; while (UCB0CTL1 & UCTXSTP); IRQ_REG &= ~TX_IFG; // I2C TX, start condition // Wait for slave address transmit to complete // Load TX buffer with register address // Wait for transmit to complete // Load TX buffer with data byte // Wait for transmit to complete // I2C stop condition // Wait for stop condition to complete // Clear USCI_B0 TX int flag return 0; VTI Technologies Oy 13/14

4 RESULT WAVEFORMS There is no display on the development hardware so a logic analyzer was used to verify the results. Figure 7 (SPI) and Figure 9 (I2C) show how the register reading is triggered from the CMA3000-D01 INT-pin. After the interrupt has activated, the output registers are read out in sequence, while making sure that In the case of SPI bus the communication frame spacing will be at least 11 SCK cycles. In Figure 8 (SPI) and Figure 10 (I2C) it can be seen how the interrupt takes place immediately after CMA3000-D01 has new data available for reading. It also shows how the INT pin is automatically cleared by reading the acceleration output data. Figure 7. SPI waveforms when reading DOUTX- DOUTY- and DOUTZ-registers Figure 8. Register reading is triggered by CMA3000-D01's INT signal, SPI bus Figure 9. I2C waveforms when reading DOUTX- DOUTY- and DOUTZ-registers Figure 10. Register reading is triggered by CMA3000-D01's INT signal, I2C bus VTI Technologies Oy 14/14