MSP430 IIC 中文手册
MSP430 单片机基础知识说明书
MSP430Microcontroller BasicsMSP430Microcontroller Basics John H.DaviesAMSTERDAM•BOSTON•HEIDELBERG•LONDONNEW YORK•OXFORD•PARIS•SAN DIEGOSAN FRANCISCO•SINGAPORE•SYDNEY•TOKYONewnes is an imprint of ElsevierNewnes is an imprint of Elsevier30Corporate Drive,Suite400,Burlington,MA01803,USALinacre House,Jordan Hill,Oxford OX28DP,UKCopyright©2008,Elsevier Ltd.All rights reserved.No part of this publication may be reproduced,stored in a retrieval system,or transmitted in any formor by any means,electronic,mechanical,photocopying,recording,or otherwise,without the prior written permission of the publisher.Permissions may be sought directly from Elsevier’s Science&Technology Rights Department in Oxford, UK:phone:(+44)1865843830,fax:(+44)1865853333,E-mail:************************.You may also complete your request online via the Elsevier homepage()by selecting “Support&Contact”then“Copyright and Permission”and then“Obtaining Permissions.”Recognizing the importance of preserving what has been written,Elsevier prints itsbooks on acid-free paper whenever possible.Library of Congress Cataloging-in-Publication DataApplication submittedBritish Library Cataloguing-in-Publication DataA catalogue record for this book is available from the British Library.ISBN:978-0-7506-8276-3For information on all Newnes publications,visit our Web site at:08091011121310987654321Printed in the United States of America“To Elizabeth.”ContentsPreface (xi)Chapter1:Embedded Electronic Systems and Microcontrollers (1)1.1What(and Where)Are Embedded Systems? (1)1.2Approaches to Embedded Systems (2)1.3Small Microcontrollers (5)1.4Anatomy of a Typical Small Microcontroller (8)1.5Memory (11)1.6Software (15)1.7Where Does the MSP430Fit? (16)Chapter2:The Texas Instruments MSP430 (21)2.1The Outside View—Pin-Out (21)2.2The Inside View—Functional Block Diagram (24)2.3Memory (25)2.4Central Processing Unit (30)2.5Memory-Mapped Input and Output (32)2.6Clock Generator (33)2.7Exceptions:Interrupts and Resets (36)2.8Where to Find Further Information (37)Chapter3:Development (43)3.1Development Environment (44)3.2The C Programming Language (46)3.3Assembly Language (55)3.4Access to the Microcontroller for Programming and Debugging (57)3.5Demonstration Boards (59)3.6Hardware (64)3.7Equipment (65)viii ContentsChapter4:A Simple Tour of the MSP430 (67)4.1First Program on a Conventional Desktop Computer (68)4.2Light LEDs in C (70)4.3Light LEDs in Assembly Language (72)4.4Read Input from a Switch (80)4.5Automatic Control:Flashing Light by Software Delay (91)4.6Automatic Control:Use of Subroutines (99)4.7Automatic Control:Flashing Light by Polling Timer_A (105)4.8Header Files and Issues Brushed under the Carpet (114)Chapter5:Architecture of the MSP430Processor (119)5.1Central Processing Unit (119)5.2Addressing Modes (125)5.3Constant Generator and Emulated Instructions (131)5.4Instruction Set (132)5.5Examples (146)5.6Reflections on the CPU and Instruction Set (153)5.7Resets (157)5.8Clock System (163)Chapter6:Functions,Interrupts,and Low-Power Modes (177)6.1Functions and Subroutines (178)6.2What Happens when a Subroutine Is Called? (178)6.3Storage for Local Variables (179)6.4Passing Parameters to a Subroutine and Returning a Result (183)6.5Mixing C and Assembly Language (185)6.6Interrupts (186)6.7What Happens when an Interrupt Is Requested? (188)6.8Interrupt Service Routines (190)6.9Issues Associated with Interrupts (196)6.10Low-Power Modes of Operation (198)Chapter7:Digital Input,Output,and Displays (207)7.1Digital Input and Output:Parallel Ports (208)7.2Digital Inputs (216)7.3Switch Debounce (225)7.4Digital Outputs (238)7.5Interface between3V and5V Systems (243)7.6Driving Heavier Loads (247)7.7Liquid Crystal Displays (252)7.8Driving an LCD from an MSP430x4xx (256)7.9Simple Applications of the LCD (264)Contents ix Chapter8:Timers (275)8.1Watchdog Timer (276)8.2Basic Timer1 (281)8.3Timer_A (287)8.4Measurement in the Capture Mode (300)8.5Output in the Continuous Mode (318)8.6Output in the Up Mode:Edge-Aligned Pulse-Width Modulation (330)8.7Output in the Up/Down Mode:Centered Pulse-Width Modulation (349)8.8Operation of Timer_A in the Sampling Mode (352)8.9Timer_B (353)8.10What Timer Where? (356)8.11Setting the Real-Time Clock:State Machines (357)Chapter9:Mixed-Signal Systems:Analog Input and Output (369)9.1Comparator_A (371)9.2Analog-to-Digital Conversion:General Issues (393)9.3Analog-to-Digital Conversion:Successive Approximation (402)9.4The ADC10Successive-Approximation ADC (407)9.5Basic Operation of the ADC10 (412)9.6More Advanced Operation of the ADC10 (424)9.7The ADC12Successive-Approximation ADC (432)9.8Analog-to-Digital Conversion:Sigma–Delta (438)9.9The SD16_A Sigma–Delta ADC (446)9.10Operation of SD16_A (459)9.11Signal Conditioning and Operational Amplifiers (475)9.12Digital-to-Analog Conversion (485)Chapter10:Communication (493)10.1Communication Peripherals in the MSP430 (495)10.2Serial Peripheral Interface (497)10.3SPI with the USI (504)10.4SPI with the USCI (513)10.5A Thermometer Using SPI in Mode3with the F2013as Master (520)10.6A Thermometer Using SPI in Mode0with the FG4618as Master (526)10.7Inter-integrated Circuit Bus (534)10.8A Simple I²C Master with the USCI_B0on a FG4618 (542)10.9A Simple I²C Slave with the USI on a F2013 (549)10.10State Machines for I²C Communication (559)10.11A Thermometer Using I²C with the F2013as Master (567)10.12Asynchronous Serial Communication (574)10.13Asynchronous Communication with the USCI_A (581)x Contents10.14A Software UART Using Timer_A (590)10.15Other Types of Communication (599)Chapter11:The Future:MSP430X (601)11.1Architecture of the MSP430X (601)11.2Instruction Set of the MSP430X (607)11.3Where Next? (614)11.4Conclusion (617)Appendix A:Kickstarting the MSP430 (619)A.1Introduction to EW430 (619)A.2Developing a Project in C (621)A.3Debugging with the Simulator (627)A.4Debugging with the Emulator (630)A.5Developing a Project in Assembly Language (633)A.6Tips for Using EW430 (636)A.7Tips for Specific Development Kits (640)Appendix B:Further Reading (645)Books and Articles (645)Newsletters,Magazines,and Journals (651)Index (655)Preface About a decade ago,I took over the teaching of afirst-year,second-semester course on digital electronics.It coveredflip-flops,counters,and state machines,all built fromsmall-scale integrated circuits.One of the projects at the end was to build a digital die.In many ways it was an excellent exercise because there were so many feasible ways in which it could be approached—simple counters,Johnson counters,or state machines.My concern was that it was very close to the project that I had experienced in myfirst course on digital electronics,which was back in the mid-1970s.The technology was close to the state of the art then,but was it still appropriate after so many years?Another feature of our course is that it is taken not only by electronic engineers but also by students from the science faculty,mostly computer scientists.I wanted these students to leave with a feeling for what can readily be done with modern programmable electronics insmaller-scale systems.I therefore replaced the material in the second half of the course with microcontrollers.(Do not worry,state machines were not abandoned—they are taught with hardware description languages in the context of programmable logic devices.) More recently,I thought that the time had come to review the choice of microcontroller. We traditionally used8-bit processors because modern devices have versatile peripherals and sophisticated embedded emulation and are quite powerful enough for most applications.Then the Texas Instruments MSP430caught my eye.A problem with8-bit microcontrollers is that8bits are too few for addresses,which are typically16bits long, and this means that data and addresses cannot be treated on an equal footing.In contrast, the MSP430has a uniform,16-bit architecture throughout:The address bus,data bus,and registers in the CPU are all16bits wide.The CPU has a modern design with plenty of registers,most of which can be used equally for data or addresses.It has a small instruction set with orthogonal addressing and an ingenious constant generator,which is used to emulate many operations that would otherwise need their own,distinct instructions.In many ways these features make the16-bit MSP430simpler than a typical8-bit processor.xii PrefaceOf course an elegant architecture does not generate many sales in the real world.More important are the range of peripherals and development tools.The MSP430offers the usual selection of peripherals plus some less common modules,including sigma–delta analog-to-digital converters and operational amplifiers.Some devices include hardware multipliers and digital-to-analog converters,which provide a complete signal chain(although,of course,Texas Instruments also offers an enormous range of digital signal processors).There is a choice of two free development environments(always an important considerationin education).One is IAR Embedded Workbench,which is available for a wide range of microcontrollers.Another,Code Composer Essentials,is produced by Texas Instruments itself.A third option is the GCC toolchain for MSP430at .I have not yet mentioned the major selling point of the MSP430,which is its low power consumption.Many microcontrollers are based on long-established designs withlow-power modes grafted onto them.This means that returning to full power from alow-power mode is often awkward and in some cases is virtually a reset operation.The MSP430is refreshingly different because it was designed from the outset for low-power operation.Entry to low-power modes and exit from them is straightforward,supported by a versatile clock system.For example,the clock module includes a digitally controlled oscillator that restarts at full speed from a low-power mode in less than1s in newer devices.In many applications the MSP430is put into a low-power mode,from which it is awakened by interrupts.These automatically restore full power for the interrupt service routine and return the processor to low power when it hasfinished.No extra code is needed for this:It is an intrinsic part of the interrupt mechanism.Most peripherals are designed for low power,although this can sometimes make them a little more complicated than would otherwise be necessary.The main point is that low-power modes are easy to use.The quality of the data sheets and user’s guides is another issue in education and those for the MSP430arefine.Unfortunately one item was missing in the area of documentation:a suitable textbook in English.I wrote this book tofill the gap.OutlineMost textbooks on microcontrollers follow one of two approaches.Thefirst is to present a sequence of projects to explore successive aspects of the device.I think that this works well for simpler architectures,notably the8-bit PICs,because it enables the reader to write functioning programs rapidly.This always feels good.Unfortunately I am not sure that it works as well for more advanced peripherals,which need considerable explanation before the reader can learn to use them fully.Preface xiii The alternative approach is to describe each module in the microcontroller fully and in turn,starting with the CPU and instruction set and working out to the peripherals.This makes for a well-organized reference book but can be tedious as a textbook.I tried to steer a course between these two.My inspiration is Kernighan and Ritchie’s The C Programming Language,which starts with a“Tutorial Introduction”before exploring the language systematically in subsequent chapters.I think that it takes rather more introduction to a microcontroller so the“simple tour,”which is my equivalent to the tutorial,does not start until Chapter4.Before that,thefirst chapter contains a general introduction to embedded systems and microcontrollers.This sets the scene for Chapter2, which focuses on the MSP430and gives a broad view of its features.I include a chapter on hardware and software for developing applications,which I hope will be particularly useful for readers who are new to microcontrollers.It also contains some reminders of features of the C language that are more prominent in programs for microcontrollers than desktop computers—bitfields for instance.This leads into the tour,which runs through some simple programs to illustrate input and output,the inevitableflashing LEDs,and an introduction to one of the timers(the MSP430has several).The remainder of the book provides a more systematic description of the MSP430.I start with the CPU and instruction set,and show how the constant generator is used to provide further“emulated”instructions.The clock system is also described in this chapter.It is followed by Chapter6on subroutines,interrupts,and low-power modes.I already mentioned that a major feature of the MSP430is the way in which low-power modes are handled automatically when interrupts are serviced.Subsequent chapters are concerned with the most widely used peripherals.Chapter7on digital input and output starts with the usual parallel ports and goes on to describe liquid crystal displays,which many MSP430s can drive directly.There is a wide selection of timers in the MSP430,which are covered in the next chapter.This is followed by a lengthy chapter on analog input and output.The MSP430offers many peripherals for analog-to-digital conversion,ranging from a simple comparator to a16-bit sigma–delta module.I do not think that you can use any of these without some understanding of their characteristics,which explains the length of this chapter.Some MSP430s include operational amplifiers and digital-to-analog converters,which I described briefly.Thefinal long chapter is on communication.I cover only three types of communication—serial peripheral interface,inter-integrated circuit bus,and asynchronous—but there are several peripherals for these in different variants of the MSP430,so there is a lot to explain.xiv PrefaceThe very last chapter provides an introduction to the MSP430X,an extended architecture with a20-bit address bus that can handle1MB of memory.There is also an appendix to take the reader through the steps of editing,building,and debugging thefirst project, which can sometimes be a frustrating experience.Ifind it annoying when books contain large chunks copied directly from data sheets and have tried to avoid this.You cannot hope to program a microcontroller without the data sheet at your side.Having said that,I start by going through each bit of the registers that control the peripherals used for the early programs.The idea is to explain how a typical peripheral is configured.After that I become more selective and concentrate on the overall function of the peripheral ually I pick out a few details that I think need extra explanation but skip the more mundane aspects.They are in the example programs inany case.I include links to many of Texas Instruments’application notes because I can see no point in repeating material that has been thoroughly explained already.Ifind that many students are strangely reluctant to use this valuable resource.There are a few reminders about code examples for the same reason.C or Assembly Language?Most small microcontrollers are now programmed using the C language so the question might seem redundant.In fact often columns in newletters on embedded systems often carry articles with titles such as“Is Assembly Language Dead?”However,the answer seems to be clearly that assembly language is not dead for small microcontrollers,such as the MSP430.Most code is written in C but you may occasionally need to write a subroutine in assembly language to perform an operation that cannot be written out directly in C.Two examples are operations that require bitwise rotations rather than shifts and calculations that can be done more efficiently by exploiting special instructions of the CPU,such as binary-coded decimal arithmetic.Intrinsic functions often avoid the need for assembly language but not always.More important,assembly language is often needed for debugging and this is the most compelling reason for describing it in a textbook.Small microcontrollers typically spend much of their time interacting with hardware by manipulating the registers that control the peripherals.Debugging may require stepping through lines of assembly language to check each step.You have to look at the manual to check the details of each instruction,but it helps to have a general idea of how the assembly language works.Preface xv From a pedagogical point of view,assembly language is useful to illustrate the architecture of the processor.In fact the MSP430is simple enough that you can explore the thinking behind the design of the instruction set.Besides,assembly language can be fun(in small doses).My approach is to develop thefirst,simple programs in Chapter4using both C and assembly language to show the relation between them.However,C dominates by the end of the chapter.Assembly language makes a strong showing in the next two chapters,which cover architecture,subroutines,and interrupts,including a section on mixing C and assembly language.Almost all remaining programs are in C,with assembly language reappearing only briefly for a function to convert numbers to binary-coded decimal.The listings in the text are read directly from the programs that I tested.Companion Web SitePlease visit the companion Web site for this book at/companions/9780750682763and download the programs used as examples in the book.These programs were read into the text of the book from the workspaces that I used for testing,which means that the downloadedfiles should match the book perfectly.Links are also provided for data sheets,user’s guides,and development tools.Solutions to the odd-numbered examples are freely available on the companion Web site but the remaining solutions are offered only to instructors. AcknowledgmentsIt is a pleasure to thank numerous people who have helped me in various ways to write this book.Many are from Texas Instruments:Bonnie Baker,Jacob Borgeson,Andreas Dannenberg,Colin Garlick,Thomas Mitnacht,and Robert Owen.I am particularly grateful to Adrian Valenzuela for his comments on thefinal draft.Several engineers from other companies were kind enough to provide advice and assistance:Edward Gibbins and Steve Duckworth from IAR,Tom Baugh of SoftBaugh,Paul Curtis of Rowley Associates,David Dyer of Ericsson and Fernando Rodriguez while he was at Texas Instruments.Finally,I am grateful to colleagues and students at Glasgow University,from whom I have learnt an enormous amount over the years.I’d like to thank Fernando Rodriguez(not the same person who was at Texas Instruments)and David Muir in particular,with both of whom I have run a wide range of projects on embedded systems and microcontrollers—from tutor boxes withflip-flops to the electronic systems of a Formula Student racing car.John Davies,Milngavie。
MSP430寄存器的中文解释,熟知这些写起程序来很方便
#define P5DIR_ sfrb P5DIR
#define P5SEL_ sfrb P5SEL
#define P6IN_ const sfrb P6IN #define P6OUT_ sfrb P6OUT
0x0034 /* P6 输入寄存器 */ = P6IN_; 0x0035 /* P6 输出寄存器*/ = P6OUT_; 0x0036 /* P6 方向选择寄存器*/ = P6DIR_; 0x0037 /* P6 功能选择寄存器*/ = P6SEL_;
#define P4DIR_ sfrb P4DIR
#define P4SEL_ sfrb P4SEL
/************************************************************ * DIGITAL I/O Port5/6 I/O口寄存器定义PORT5和6 无中断功能
************************************************************/
#define P5IN_ const sfrb P5IN #define P5OUT_ sfrb P5OUT
0x0030 /* P5 输入寄存器 */ = P5IN_; 0x0031 /* P5 输出寄存器*/ = P5OUT_; 0x0032 /* P5 方向选择寄存器*/ = P5DIR_; 0x0033 /* P5 功能选择寄存器*/ = P5SEL_;
#define MPY_
0x0130 /* 无符号乘法 */
sfrw
MPY
= MPY_; 0x0132 /* 有符号乘法*/ = MPYS_; 0x0134 /* 无符号乘加 */ = MAC_; 0x0136 /* 有符号乘加 */ = MACS_; 0x0138 /* 第二乘数 */ = OP2_; 0x013A /* 低6位结果寄存器 */ = RESLO_; 0x013C /* 高6位结果寄存器 */ = RESHI_; 0x013E /*结果扩展寄存器 */ = SUMEXT_;
MSP430寄存器中文注释18页word文档
MSP430寄存器中文注释---P1/2口(带中断功能)/************************************************************* DIGITAL I/O Port1/2 寄存器定义有中断功能************************************************************/#define P1IN_ 0x0020 /* P1 输入寄存器 */const sfrb P1IN = P1IN_;#define P1OUT_ 0x0021 /* P1 输出寄存器 */sfrb P1OUT = P1OUT_;#define P1DIR_ 0x0022 /* P1 方向选择寄存器 */sfrb P1DIR = P1DIR_;#define P1IFG_ 0x0023 /* P1 中断标志寄存器*/sfrb P1IFG = P1IFG_;#define P1IES_ 0x0024 /* P1 中断边沿选择寄存器*/ sfrb P1IES = P1IES_;#define P1IE_ 0x0025 /* P1 中断使能寄存器 */ sfrb P1IE = P1IE_;#define P1SEL_ 0x0026 /* P1 功能选择寄存器*/sfrb P1SEL = P1SEL_;#define P2IN_ 0x0028 /* P2 输入寄存器 */const sfrb P2IN = P2IN_;#define P2OUT_ 0x0029 /* P2 输出寄存器 */sfrb P2OUT = P2OUT_;#define P2DIR_ 0x002A /* P2 方向选择寄存器 */ sfrb P2DIR = P2DIR_;#define P2IFG_ 0x002B /* P2 中断标志寄存器 */sfrb P2IFG = P2IFG_;#define P2IES_ 0x002C /* P2 中断边沿选择寄存器 */ sfrb P2IES = P2IES_;#define P2IE_ 0x002D /* P2 中断使能寄存器 */ sfrb P2IE = P2IE_;#define P2SEL_ 0x002E /* P2 功能选择寄存器 */ sfrb P2SEL = P2SEL_;MSP430寄存器中文注释---P3/4口(无中断功能)/************************************************************* DIGITAL I/O Port3/4寄存器定义无中断功能************************************************************/#define P3IN_ 0x0018 /* P3 输入寄存器 */ const sfrb P3IN = P3IN_;#define P3OUT_ 0x0019 /* P3 输出寄存器 */sfrb P3OUT = P3OUT_;#define P3DIR_ 0x001A /* P3 方向选择寄存器 */ sfrb P3DIR = P3DIR_;#define P3SEL_ 0x001B /* P3 功能选择寄存器*/ sfrb P3SEL = P3SEL_;#define P4IN_ 0x001C /* P4 输入寄存器 */ const sfrb P4IN = P4IN_;#define P4OUT_ 0x001D /* P4 输出寄存器 */sfrb P4OUT = P4OUT_;#define P4DIR_ 0x001E /* P4 方向选择寄存器 */ sfrb P4DIR = P4DIR_;#define P4SEL_ 0x001F /* P4 功能选择寄存器 */ sfrb P4SEL = P4SEL_;/************************************************************* DIGITAL I/O Port5/6 I/O口寄存器定义PORT5和6 无中断功能#define P5IN_ 0x0030 /* P5 输入寄存器 */ const sfrb P5IN = P5IN_;#define P5OUT_ 0x0031 /* P5 输出寄存器*/sfrb P5OUT = P5OUT_;#define P5DIR_ 0x0032 /* P5 方向选择寄存器*/ sfrb P5DIR = P5DIR_;#define P5SEL_ 0x0033 /* P5 功能选择寄存器*/ sfrb P5SEL = P5SEL_;#define P6IN_ 0x0034 /* P6 输入寄存器 */ const sfrb P6IN = P6IN_;#define P6OUT_ 0x0035 /* P6 输出寄存器*/sfrb P6OUT = P6OUT_;#define P6DIR_ 0x0036 /* P6 方向选择寄存器*/ sfrb P6DIR = P6DIR_;#define P6SEL_ 0x0037 /* P6 功能选择寄存器*/ sfrb P6SEL = P6SEL_;MSP430寄存器中文注释--- 硬件乘法器/************************************************************硬件乘法器的寄存器定义************************************************************/#define MPY_ 0x0130 /* 无符号乘法 */ sfrw MPY = MPY_;#define MPYS_ 0x0132 /* 有符号乘法*/sfrw MPYS = MPYS_;#define MAC_ 0x0134 /* 无符号乘加 */ sfrw MAC = MAC_;#define MACS_ 0x0136 /* 有符号乘加 */sfrw MACS = MACS_;#define OP2_ 0x0138 /* 第二乘数 */sfrw OP2 = OP2_;#define RESLO_ 0x013A /* 低6位结果寄存器 */sfrw RESLO = RESLO_;#define RESHI_ 0x013C /* 高6位结果寄存器 */sfrw RESHI = RESHI_;#define SUMEXT_ 0x013E /*结果扩展寄存器 */const sfrw SUMEXT = SUMEXT_;MSP430寄存器中文注释---看门狗和定时器/************************************************************* 看门狗定时器的寄存器定义************************************************************/#define WDTCTL_ 0x0120sfrw WDTCTL = WDTCTL_;#define WDTIS0 0x0001 /*选择WDTCNT的四个输出端之一*/#define WDTIS1 0x0002 /*选择WDTCNT的四个输出端之一*/#define WDTSSEL 0x0004 /*选择WDTCNT的时钟源*/#define WDTCNTCL 0x0008 /*清除WDTCNT端: 为1时从0开始计数*/#define WDTTMSEL 0x0010 /*选择模式 0: 看门狗模式; 1: 定时器模式*/#define WDTNMI 0x0020 /*选择NMI/RST 引脚功能 0:为 RST; 1:为NMI*/#define WDTNMIES 0x0040 /*WDTNMI=1时.选择触发延 0:为上升延 1:为下降延*/#define WDTHOLD 0x0080 /*停止看门狗定时器工作 0:启动;1:停止*/#define WDTPW 0x5A00 /* 写密码:高八位*//* SMCLK= 1MHz定时器模式 */#define WDT_MDLY_32 WDTPW+WDTTMSEL+WDTCNTCL /* TSMCLK*2POWER15=32ms 复位状态 */#define WDT_MDLY_8 WDTPW+WDTTMSEL+WDTCNTCL+WDTIS0 /* TSMCLK*2POWER13=8.192ms " */#define WDT_MDLY_0_5 WDTPW+WDTTMSEL+WDTCNTCL+WDTIS1 /* TSMCLK*2POWER9=0.512ms " */#define WDT_MDLY_0_064 WDTPW+WDTTMSEL+WDTCNTCL+WDTIS1+WDTIS0 / * TSMCLK*2POWER6=0.512ms " *//* ACLK=32.768KHz 定时器模式*/#define WDT_ADLY_1000 WDTPW+WDTTMSEL+WDTCNTCL+WDTSSEL /* TACLK*2POWER15=1000ms " */#define WDT_ADLY_250 WDTPW+WDTTMSEL+WDTCNTCL+WDTSSEL+WDTIS0/* TACLK*2POWER13=250ms " */#define WDT_ADLY_16 WDTPW+WDTTMSEL+WDTCNTCL+WDTSSEL+WDTIS1 /* TACLK*2POWER9=16ms " */#define WDT_ADLY_1_9 WDTPW+WDTTMSEL+WDTCNTCL+WDTSSEL+WDTIS1+WDTIS0 /* TACL K*2POWER6=1.9ms " *//* SMCLK=1MHz看门狗模式 */#define WDT_MRST_32 WDTPW+WDTCNTCL /* TSMCLK*2POWER15=32ms 复位状态 */#define WDT_MRST_8 WDTPW+WDTCNTCL+WDTIS0 /* TSMCLK*2POWER13=8.192ms " */#define WDT_MRST_0_5 WDTPW+WDTCNTCL+WDTIS1 /* TSMCLK*2POWER9=0.512ms " */ #define WDT_MRST_0_064 WDTPW+WDTCNTCL+WDTIS1+WDTIS0 /* TSMCLK*2POWER6=0.512ms " *//* ACLK=32KHz看门狗模式 */#define WDT_ARST_1000 WDTPW+WDTCNTCL+WDTSSEL /* TACLK*2POWER15=1000ms " */#define WDT_ARST_250 WDTPW+WDTCNTCL+WDTSSEL+WDTIS0 /* TACLK*2POWER13=250ms " */#define WDT_ARST_16 WDTPW+WDTCNTCL+WDTSSEL+WDTIS1 /* TACLK*2POWER9=16ms " */#define WDT_ARST_1_9 WDTPW+WDTCNTCL+WDTSSEL+WDTIS1+WDTIS0 /* TACLK*2POWER6=1.9ms " */MSP430寄存器中文注释---A/D采样寄存器定义/************************************************************* ADC12 A/D采样寄存器定义************************************************************//*ADC12转换控制类寄存器*/#define ADC12CTL0_ 0x0;' /* ADC12 Control 0 */sfrw ADC12CTL0 = ADC12CTL0_;#define ADC12CTL1_ 0x01A2 /* ADC12 Control 1 */sfrw ADC12CTL1 = ADC12CTL1_;/*ADC12中断控制类寄存器*/#define ADC12IFG_ 0x01A4 /* ADC12 Interrupt Flag */sfrw ADC12IFG = ADC12IFG_;#define ADC12IE_ 0x01A6 /* ADC12 Interrupt Enable */sfrw ADC12IE = ADC12IE_;#define ADC12IV_ 0x01A8 /* ADC12 Interrupt Vector Word */sfrw ADC12IV = ADC12IV_;/*ADC12存贮器类寄存器*/#define ADC12MEM_ 0x0140 /* ADC12 Conversion Memory */#ifndef __IAR_SYSTEMS_ICC#define ADC12MEM ADC12MEM_ /* ADC12 Conversion Memory (for assembler) */#else#define ADC12MEM ((int*) ADC12MEM_) /* ADC12 Conversion Memory (for C) */#endif#define ADC12MEM0_ ADC12MEM_ /* ADC12 Conversion Memory 0 */sfrw ADC12MEM0 = ADC12MEM0_;#define ADC12MEM1_ 0x0142 /* ADC12 Conversion Memory 1 */sfrw ADC12MEM1 = ADC12MEM1_;#define ADC12MEM2_ 0x0144 /* ADC12 Conversion Memory 2 */sfrw ADC12MEM2 = ADC12MEM2_;#define ADC12MEM3_ 0x0146 /* ADC12 Conversion Memory 3 */sfrw ADC12MEM3 = ADC12MEM3_;#define ADC12MEM4_ 0x0148 /* ADC12 Conversion Memory 4 */sfrw ADC12MEM4 = ADC12MEM4_;#define ADC12MEM5_ 0x014A /* ADC12 Conversion Memory 5 */sfrw ADC12MEM5 = ADC12MEM5_;#define ADC12MEM6_ 0x014C /* ADC12 Conversion Memory 6 */sfrw ADC12MEM6 = ADC12MEM6_;#define ADC12MEM7_ 0x014E /* ADC12 Conversion Memory 7 */sfrw ADC12MEM7 = ADC12MEM7_;#define ADC12MEM8_ 0x0150 /* ADC12 Conversion Memory 8 */sfrw ADC12MEM8 = ADC12MEM8_;#define ADC12MEM9_ 0x0152 /* ADC12 Conversion Memory 9 */sfrw ADC12MEM9 = ADC12MEM9_;#define ADC12MEM10_ 0x0154 /* ADC12 Conversion Memory 10 */sfrw ADC12MEM10 = ADC12MEM10_;#define ADC12MEM11_ 0x0156 /* ADC12 Conversion Memory 11 */sfrw ADC12MEM11 = ADC12MEM11_;#define ADC12MEM12_ 0x0158 /* ADC12 Conversion Memory 12 */sfrw ADC12MEM12 = ADC12MEM12_;#define ADC12MEM13_ 0x015A /* ADC12 Conversion Memory 13 */sfrw ADC12MEM13 = ADC12MEM13_;#define ADC12MEM14_ 0x015C /* ADC12 Conversion Memory 14 */sfrw ADC12MEM14 = ADC12MEM14_;#define ADC12MEM15_ 0x015E /* ADC12 Conversion Memory 15 */sfrw ADC12MEM15 = ADC12MEM15_;/*ADC12存贮控制类寄存器*/#define ADC12MCTL_ 0x0080 /* ADC12 Memory Control */#ifndef __IAR_SYSTEMS_ICC#define ADC12MCTL ADC12MCTL_ /* ADC12 Memory Control (for assembler) */ #else#define ADC12MCTL ((char*) ADC12MCTL_) /* ADC12 Memory Control (for C) * /#endif#define ADC12MCTL0_ ADC12MCTL_ /* ADC12 Memory Control 0 */sfrb ADC12MCTL0 = ADC12MCTL0_;#define ADC12MCTL1_ 0x0081 /* ADC12 Memory Control 1 */sfrb ADC12MCTL1 = ADC12MCTL1_;#define ADC12MCTL2_ 0x0082 /* ADC12 Memory Control 2 */sfrb ADC12MCTL2 = ADC12MCTL2_;#define ADC12MCTL3_ 0x0083 /* ADC12 Memory Control 3 */sfrb ADC12MCTL3 = ADC12MCTL3_;#define ADC12MCTL4_ 0x0084 /* ADC12 Memory Control 4 */sfrb ADC12MCTL4 = ADC12MCTL4_;#define ADC12MCTL5_ 0x0085 /* ADC12 Memory Control 5 */sfrb ADC12MCTL5 = ADC12MCTL5_;#define ADC12MCTL6_ 0x0086 /* ADC12 Memory Control 6 */sfrb ADC12MCTL6 = ADC12MCTL6_;#define ADC12MCTL7_ 0x0087 /* ADC12 Memory Control 7 */sfrb ADC12MCTL7 = ADC12MCTL7_;#define ADC12MCTL8_ 0x0088 /* ADC12 Memory Control 8 */sfrb ADC12MCTL8 = ADC12MCTL8_;#define ADC12MCTL9_ 0x0089 /* ADC12 Memory Control 9 */sfrb ADC12MCTL9 = ADC12MCTL9_;#define ADC12MCTL10_ 0x008A /* ADC12 Memory Control 10 */sfrb ADC12MCTL10 = ADC12MCTL10_;#define ADC12MCTL11_ 0x008B /* ADC12 Memory Control 11 */sfrb ADC12MCTL11 = ADC12MCTL11_;#define ADC12MCTL12_ 0x008C /* ADC12 Memory Control 12 */sfrb ADC12MCTL12 = ADC12MCTL12_;#define ADC12MCTL13_ 0x008D /* ADC12 Memory Control 13 */sfrb ADC12MCTL13 = ADC12MCTL13_;#define ADC12MCTL14_ 0x008E /* ADC12 Memory Control 14 */sfrb ADC12MCTL14 = ADC12MCTL14_;#define ADC12MCTL15_ 0x008F /* ADC12 Memory Control 15 */sfrb ADC12MCTL15 = ADC12MCTL15_;/* ADC12CTL0 内8位控制寄存器位*/#define ADC12SC 0x001 /*采样/转换控制位*/#define ENC 0x002 /* 转换允许位*/#define ADC12TOVIE 0x004 /*转换时间溢出中断允许位*/#define ADC12OVIE 0x008 /*溢出中断允许位*/#define ADC12ON 0x010 /*ADC12内核控制位*/#define REFON 0x020 /*参考电压控制位*/#define REF2_5V 0x040 /*内部参考电压的电压值选择位 ' 0'为1.5V; '1'为2.5V*/#define MSH 0x080 /*多次采样/转换位*/#define MSC 0x080 /*多次采样/转换位*//*SHT0 采样保持定时器0 控制ADC12的结果存贮器MEM0~MEM7的采样周期*/#define SHT0_0 0*0x100 /*采样周期=TADC12CLK*4 */#define SHT0_1 1*0x100 /*采样周期=TADC12CLK*8 */#define SHT0_2 2*0x100 /*采样周期=TADC12CLK*16 */ #define SHT0_3 3*0x100 /*采样周期=TADC12CLK*32 */ #define SHT0_4 4*0x100 /*采样周期=TADC12CLK*64 */ #define SHT0_5 5*0x100 /*采样周期=TADC12CLK*96 */ #define SHT0_6 6*0x100 /*采样周期=TADC12CLK*128 */ #define SHT0_7 7*0x100 /*采样周期=TADC12CLK*192 */ #define SHT0_8 8*0x100 /*采样周期=TADC12CLK*256 */ #define SHT0_9 9*0x100 /*采样周期=TADC12CLK*384 */ #define SHT0_10 10*0x100 /*采样周期=TADC12CLK*512 */#define SHT0_11 11*0x100 /*采样周期=TADC12CLK*768 */#define SHT0_12 12*0x100 /*采样周期=TADC12CLK*1024 */ #define SHT0_13 13*0x100 /*采样周期=TADC12CLK*1024 */ #define SHT0_14 14*0x100 /*采样周期=TADC12CLK*1024 */ #define SHT0_15 15*0x100 /*采样周期=TADC12CLK*1024 */ /*SHT1 采样保持定时器1 控制ADC12的结果存贮器MEM8~MEM15的采样周期*/#define SHT1_0 0*0x100 /*采样周期=TADC12CLK*4 */#define SHT1_1 1*0x100 /*采样周期=TADC12CLK*8 */#define SHT1_2 2*0x100 /*采样周期=TADC12CLK*16 */ #define SHT1_3 3*0x100 /*采样周期=TADC12CLK*32 */ #define SHT1_4 4*0x100 /*采样周期=TADC12CLK*64 */#define SHT1_5 5*0x100 /*采样周期=TADC12CLK*96 */ #define SHT1_6 6*0x100 /*采样周期=TADC12CLK*128 */ #define SHT1_7 7*0x100 /*采样周期=TADC12CLK*192 */ #define SHT1_8 8*0x100 /*采样周期=TADC12CLK*256 */ #define SHT1_9 9*0x100 /*采样周期=TADC12CLK*384 */ #define SHT1_10 10*0x100 /*采样周期=TADC12CLK*512 */ #define SHT1_11 11*0x100 /*采样周期=TADC12CLK*768 */ #define SHT1_12 12*0x100 /*采样周期=TADC12CLK*1024 */ #define SHT1_13 13*0x100 /*采样周期=TADC12CLK*1024 */ #define SHT1_14 14*0x100 /*采样周期=TADC12CLK*1024 */ #define SHT1_15 15*0x100 /*采样周期=TADC12CLK*1024 *//* ADC12CTL1 内8位控制寄存器位*/#define ADC12BUSY 0x0001 /*ADC12忙标志位*/#define CONSEQ_0 0*2 /*单通道单次转换*/#define CONSEQ_1 1*2 /*序列通道单次转换*/#define CONSEQ_2 2*2 /*单通道多次转换*/#define CONSEQ_3 3*2 /*序列通道多次转换*/#define ADC12SSEL_0 0*8 /*ADC12内部时钟源*/#define ADC12SSEL_1 1*8 /*ACLK*/#define ADC12SSEL_2 2*8 /*MCLK*/#define ADC12SSEL_3 3*8 /*SCLK*/#define ADC12DIV_0 0*0x20 /*1分频*/#define ADC12DIV_1 1*0x20 /*2分频*/#define ADC12DIV_2 2*0x20 /*3分频*/#define ADC12DIV_3 3*0x20 /*4分频*/#define ADC12DIV_4 4*0x20 /*5分频*/#define ADC12DIV_5 5*0x20 /*6分频*/#define ADC12DIV_6 6*0x20 /*7分频*/#define ADC12DIV_7 7*0x20 /*8分频*/#define ISSH 0x0100 /*采样输入信号反向与否控制位*/#define SHP 0x0200 /*采样信号(SAMPCON)选择控制位*/#define SHS_0 0*0x400 /*采样信号输入源选择控制位 A DC12SC*/#define SHS_1 1*0x400 /*采样信号输入源选择控制位 T IMER_A.OUT1*/#define SHS_2 2*0x400 /*采样信号输入源选择控制位 T IMER_B.OUT0*/#define SHS_3 3*0x400 /*采样信号输入源选择控制位 T IMER_B.OUT1*//*转换存贮器地址定义位*/#define CSTARTADD_0 0*0x1000 /*选择MEM0首地址*/#define CSTARTADD_1 1*0x1000 /*选择MEM1首地址*/#define CSTARTADD_2 2*0x1000 /*选择MEM2首地址*/#define CSTARTADD_3 3*0x1000 /*选择MEM3首地址*/#define CSTARTADD_4 4*0x1000 /*选择MEM4首地址*/#define CSTARTADD_5 5*0x1000 /*选择MEM5首地址*/#define CSTARTADD_6 6*0x1000 /*选择MEM6首地址*/#define CSTARTADD_7 7*0x1000 /*选择MEM7首地址*/#define CSTARTADD_8 8*0x1000 /*选择MEM8首地址*/#define CSTARTADD_9 9*0x1000 /*选择MEM9首地址*/#define CSTARTADD_10 10*0x1000 /*选择MEM10首地址*/#define CSTARTADD_11 11*0x1000 /*选择MEM11首地址*/#define CSTARTADD_12 12*0x1000 /*选择MEM12首地址*/#define CSTARTADD_13 13*0x1000 /*选择MEM13首地址*/#define CSTARTADD_14 14*0x1000 /*选择MEM14首地址*/#define CSTARTADD_15 15*0x1000 /*选择MEM15首地址*//* ADC12MCTLx */#define INCH_0 0 /*选择模拟量通道0 A0 */#define INCH_1 1 /*选择模拟量通道0 A1*/#define INCH_2 2 /*选择模拟量通道0 A2*/#define INCH_3 3 /*选择模拟量通道0 A3*/#define INCH_4 4 /*选择模拟量通道0 A4*/#define INCH_5 5 /*选择模拟量通道0 A5*/#define INCH_6 6 /*选择模拟量通道0 A6*/#define INCH_7 7 /*选择模拟量通道0 A7*/#define INCH_8 8 /*VEREF+*/#define INCH_9 9 /*VEREF-*/#define INCH_10 10 /*片内温度传感器的输出*/#define INCH_11 11 /*(AVCC-AVSS)/2*/ #define INCH_12 12 /*(AVCC-AVSS)/2*/ #define INCH_13 13 /*(AVCC-AVSS)/2*/ #define INCH_14 14 /*(AVCC-AVSS)/2*/ #define INCH_15 15 /*(AVCC-AVSS)/2*/ /*参考电压源选择位*/#define SREF_0 0*0x10 /*VR+ = AVCC; VR- = AVSS*/#define SREF_1 1*0x10 /*VR+ = VREF+; VR- = AVSS*/#define SREF_2 2*0x10 /*VR+ = VEREF+; VR- = AVSS*/#define SREF_3 3*0x10 /*VR+ = VEREF+; VR- = AVSS*/#define SREF_4 4*0x10 /*VR+ = AVCC; VR- = VREF-*/#define SREF_5 5*0x10 /*VR+ = VREF+; VR- = VREF-*/#define SREF_6 6*0x10 /*VR+ = VEREF+; VR- = VREF-*/#define SREF_7 7*0x10 /*VR+ = VEREF+; VR- = VREF-*/#define EOS 0x80 /*序列结束选择位*/MSP430寄存器中文注释----串口寄存器/************************************************************* USART 串口寄存器"UCTL","UTCTL","URCTL"定义的各个位可串口1 串口2公用************************************************************//* UCTL 串口控制寄存器*/#define PENA 0x80 /*校验允许位*/#define PEV 0x40 /*偶校验为0时为奇校验*/ #define SPB 0x20 /*停止位为2 为0时停止位为1* /#define CHAR 0x10 /*数据位为8位为0时数据位为7位*/#define LISTEN 0x08 /*自环模式(发数据同时在把发的数据接收回来)*/#define SYNC 0x04 /*同步模式为0异步模式*/#define MM 0x02 /*为1时地址位多机协议(异步)主机模式(同步);为0时线路空闲多机协议(异步) 从机模式(同步)*/#define SWRST 0x01 /*控制位*//* UTCTL 串口发送控制寄存器*/#define CKPH 0x80 /*时钟相位控制位(只同步方式用)为1时时钟UCLK延时半个周期*/#define CKPL 0x40 /*时钟极性控制位为1时异步与U CLK相反;同步下降延有效*/#define SSEL1 0x20 /*时钟源选择位:与SSEL0组合为0, 1,2,3四种方式*/#define SSEL0 0x10 /*"0"选择外部时钟,"1"选择辅助时钟,"2","3"选择系统子时钟 */#define URXSE 0x08 /*接收触发延控制位(只在异步方式下用)*/#define TXWAKE 0x04 /*多处理器通信传送控制位(只在异步方式下用)*/#define STC 0x02 /*外部引脚STE选择位为0时为4线模式为1时为3线模式*/#define TXEPT 0x01 /*发送器空标志*//* URCTL 串口接收控制寄存器同步模式下只用两位:FE和OE*/#define FE 0x80 /*帧错标志*/#define PE 0x40 /*校验错标志位*/#define OE 0x20 /*溢出标志位*/#define BRK 0x10 /*打断检测位*/#define URXEIE 0x08 /*接收出错中断允许位*/#define URXWIE 0x04 /*接收唤醒中断允许位*/ #define RXWAKE 0x02 /*接收唤醒检测位*/#define RXERR 0x01 /*接收错误标志位*//************************************************************* USART 0 串口0寄存器定义************************************************************/#define U0CTL_ 0x0070 /* UART 0 Control */sfrb U0CTL = U0CTL_;#define U0TCTL_ 0x0071 /* UART 0 Transmit Control */sfrb U0TCTL = U0TCTL_;#define U0RCTL_ 0x0072 /* UART 0 Receive Control */sfrb U0RCTL = U0RCTL_;#define U0MCTL_ 0x0073 /* UART 0 Modulation Control */sfrb U0MCTL = U0MCTL_;#define U0BR0_ 0x0074 /* UART 0 Baud Rate 0 */sfrb U0BR0 = U0BR0_;#define U0BR1_ 0x0075 /* UART 0 Baud Rate 1 */sfrb U0BR1 = U0BR1_;#define U0RXBUF_ 0x0076 /* UART 0 Receive Buffer */const sfrb U0RXBUF = U0RXBUF_;#define U0TXBUF_ 0x0077 /* UART 0 Transmit Buffer */sfrb U0TXBUF = U0TXBUF_;/* Alternate register names */#define UCTL0_ 0x0070 /* UART 0 Control */sfrb UCTL0 = UCTL0_;#define UTCTL0_ 0x0071 /* UART 0 Transmit Control */sfrb UTCTL0 = UTCTL0_;#define URCTL0_ 0x0072 /* UART 0 Receive Control */ sfrb URCTL0 = URCTL0_;#define UMCTL0_ 0x0073 /* UART 0 Modulation Control */ sfrb UMCTL0 = UMCTL0_;#define UBR00_ 0x0074 /* UART 0 Baud Rate 0 */sfrb UBR00 = UBR00_;#define UBR10_ 0x0075 /* UART 0 Baud Rate 1 */sfrb UBR10 = UBR10_;#define RXBUF0_ 0x0076 /* UART 0 Receive Buffer */ const sfrb RXBUF0 = RXBUF0_;#define TXBUF0_ 0x0077 /* UART 0 Transmit Buffer */ sfrb TXBUF0 = TXBUF0_;#define UCTL_0_ 0x0070 /* UART 0 Control */sfrb UCTL_0 = UCTL_0_;#define UTCTL_0_ 0x0071 /* UART 0 Transmit Control */ sfrb UTCTL_0 = UTCTL_0_;#define URCTL_0_ 0x0072 /* UART 0 Receive Control */sfrb URCTL_0 = URCTL_0_;#define UMCTL_0_ 0x0073 /* UART 0 Modulation Control */ sfrb UMCTL_0 = UMCTL_0_;#define UBR0_0_ 0x0074 /* UART 0 Baud Rate 0 */sfrb UBR0_0 = UBR0_0_;#define UBR1_0_ 0x0075 /* UART 0 Baud Rate 1 */sfrb UBR1_0 = UBR1_0_;#define RXBUF_0_ 0x0076 /* UART 0 Receive Buffer */ const sfrb RXBUF_0 = RXBUF_0_;#define TXBUF_0_ 0x0077 /* UART 0 Transmit Buffer */sfrb TXBUF_0 = TXBUF_0_;/************************************************************* USART 1 串口1寄存器定义************************************************************/#define U1CTL_ 0x0078 /* UART 1 Control */sfrb U1CTL = U1CTL_;#define U1TCTL_ 0x0079 /* UART 1 Transmit Control */ sfrb U1TCTL = U1TCTL_;#define U1RCTL_ 0x007A /* UART 1 Receive Control */ sfrb U1RCTL = U1RCTL_;#define U1MCTL_ 0x007B /* UART 1 Modulation Control */ sfrb U1MCTL = U1MCTL_;#define U1BR0_ 0x007C /* UART 1 Baud Rate 0 */sfrb U1BR0 = U1BR0_;#define U1BR1_ 0x007D /* UART 1 Baud Rate 1 */sfrb U1BR1 = U1BR1_;#define U1RXBUF_ 0x007E /* UART 1 Receive Buffer */ const sfrb U1RXBUF = U1RXBUF_;#define U1TXBUF_ 0x007F /* UART 1 Transmit Buffer */sfrb U1TXBUF = U1TXBUF_;#define UCTL1_ 0x0078 /* UART 1 Control */sfrb UCTL1 = UCTL1_;#define UTCTL1_ 0x0079 /* UART 1 Transmit Control */ sfrb UTCTL1 = UTCTL1_;#define URCTL1_ 0x007A /* UART 1 Receive Control */ sfrb URCTL1 = URCTL1_;#define UMCTL1_ 0x007B /* UART 1 Modulation Control */ sfrb UMCTL1 = UMCTL1_;#define UBR01_ 0x007C /* UART 1 Baud Rate 0 */sfrb UBR01 = UBR01_;#define UBR11_ 0x007D /* UART 1 Baud Rate 1 */sfrb UBR11 = UBR11_;#define RXBUF1_ 0x007E /* UART 1 Receive Buffer */ const sfrb RXBUF1 = RXBUF1_;#define TXBUF1_ 0x007F /* UART 1 Transmit Buffer */ sfrb TXBUF1 = TXBUF1_;#define UCTL_1_ 0x0078 /* UART 1 Control */sfrb UCTL_1 = UCTL_1_;#define UTCTL_1_ 0x0079 /* UART 1 Transmit Control */ sfrb UTCTL_1 = UTCTL_1_;#define URCTL_1_ 0x007A /* UART 1 Receive Control */ sfrb URCTL_1 = URCTL_1_;#define UMCTL_1_ 0x007B /* UART 1 Modulation Control */ sfrb UMCTL_1 = UMCTL_1_;#define UBR0_1_ 0x007C /* UART 1 Baud Rate 0 */sfrb UBR0_1 = UBR0_1_;#define UBR1_1_ 0x007D /* UART 1 Baud Rate 1 */sfrb UBR1_1 = UBR1_1_;#define RXBUF_1_ 0x007E /* UART 1 Receive Buffer */ const sfrb RXBUF_1 = RXBUF_1_;#define TXBUF_1_ 0x007F /* UART 1 Transmit Buffer */ sfrb TXBUF_1 = TXBUF_1_;。
MSP430I2C通信
04
MSP430I2C通信模块的 应用实例
MSP430I2C通信模块与EEPROM的通信
总结词
实现数据存储与读取
详细描述
MSP430I2C通信模块通过与EEPROM进行通信,可以实现数据的存储和读取功能。在数据存储时,可以将需要 保存的数据通过I2C通信协议发送到EEPROM中;在数据读取时,可以从EEPROM中读取数据并通过I2C通信协 议返回给MSP430I2C通信模块。
要点三
解决方案
首先检查总线的负载情况,确保总线 上连接的设备数量和信号线的长度在 合理范围内。然后检查信号线的质量 ,排除信号干扰的可能性。此外,可 以尝试调整I2C通信的速率参数,以 找到最适合系统需求的通信速率。
THANKS
感谢观看
寄存器访问
通过读写寄存器的方式,实现数据的读取和 写入。
03
MSP430I2C通信模块的 使用
MSP430I2C通信模块的初始化
初始化I2C通信模块
启动I2C通信
在开始通信之前,需要先初始化I2C通 信模块,包括设置通信速率、数据位、 停止位等参数。
完成初始化后,通过发送起始信号启 动I2C通信。
I2C通信模块支持多主模式和从模式, 方便实现多机通信。
MSP430I2C通信模块具有硬件仲裁 功能,可自动处理多个主设备同时请 求的情况,保证数据传输的可靠性。
02
I2C通信协议
I2C通信协议概述
I2C通信是一种双线串行通信协 议,主要用于连接微控制器和 各种外围设备。
它由Philips公司开发,具有简 单、稳定、高速等优点,广泛 应用于各种嵌入式系统中。
模块的亮度和对比度等参数,从而实现数据显示和控制功能。
05
MSP430的I2C程序
*功能:构造待接收数据的“弹夹”
*入口参数:无
*出口参数:无
*说明:只有不BUSY且STOP已复位的情况下才允许操作“弹夹”
*范例:无
******************************************************************************************************/
RxByteCnt= num;//更新剩余接收数据个数
UCB0CTL1 &= ~UCTR;
UCB0CTL1 |= UCTXSTT;// I2C Rx位,软件start condition
_bis_SR_register(CPUOFF+GIE);//进LPM0模式,开总中断
return(1);
}
void I2C_TxFrame_ISR(void);
*名称:USCI_I2C_Tx_Init()
*功能:仅使能I2C的Tx中断
*入口参数:无
*出口参数:无
*说明:I2C通信只能半双工,只使能一个中断,可靠
*范例:无
******************************************************************************************************/
void USCI_I2C_Tx_Init()
{
_disable_interrupts();
while ((UCB0STAT & UCBUSY)||UCB0CTL1 & UCTXSTP); //确保总线空闲
IE2 &= ~UCB0RXIE;//关闭Rx中断
MSP430的I2C模块寄存器
本文为翻译的MSP430x1xx Family User's Guide家庭用户指南,且只有寄存器的翻译比较准确,其他地方阅读时请自行判断语句的准确性本文为翻译的MSP430x1xx Family User's Guide家庭用户指南,且只有寄存器的翻译比较准确,其他地方阅读时请自行判断语句的准确性本文为翻译的MSP430x1xx Family User's Guide家庭用户指南,且只有寄存器的翻译比较准确,其他地方阅读时请自行判断语句的准确性USART外围接口,I2C模式通用同步/异步接收/传输(USART)外设接口支持USART0 I2C通信。
本章介绍I2C模式。
在I2C模式在MSP430x15x和MSP430x16x器件上实现。
专题页面15.1 I2C模块简介..............................................15-215.2 I2C模块操作..............................................15-415.3 I2C模块寄存器............................................15-2015.3 I2C模块寄存器I2C模块寄存器如表15-4。
表15-4.I2C寄存器注册简称注册类型地址初始状态I2C中断使能 I2CIE 读/写 050hI2C中断标志 I2CIFG 读/写 051hI2C数据计数 I2CNDAT 读/写 052hUSART控制 U0CTL 读/写 070hI2C传输控制 I2CTCTL 读/写 071hI2C数据控制 I2CDCTL 只读 072hI2C预分频器 I2CPSC 读/写 073hI2C SCL高 I2CSCLH 读/写 074hI2C SCL低 I2CSCLL 读/写 075hI2C数据 I2CDRW/ I2CDRB 读/写 076hI2C自己的地址 I2COA 读/写 0118hI2C从地址 I2CSA 读/写 011AhI2C中断向量 I2CIV 只读 011ChU0CTL,UART0控制寄存器,I2C模式rw−0rw−0rw−0rw−0rw−0rw−0rw−0rw−1RXDMAEN 第7位接收DMA能。
MSP430F2XX中文手册(加了标签) 12.SPI 串行同步通讯模式
Page 4 of 14
MSP430 F2 系列超低功耗单片机模块原理 第 12 章 串行同步通讯模式 SPI
微控设计网
图12-2 通用串行通信接口主机和从机
图12-2说明了USCI在3线和4线模式下作为主机时的配置。当数据被送到传输数据缓冲器 UCxTXBUF时,USCI开始数据传送。当TX移位寄存器空了后,UCxTXBUF缓冲区的数据被传送到其 中, 在UCxSIMO上传送数据, 起始位是最高位还是最低位, 决定于UCMSB标志位的设置。 而UCxSOMI 上的数据在反向跳边沿下移入接收移位寄存器。当字符接收到之后,接收数据从RX移位寄存器 送入接收数据缓冲器UCxRXBUF,并且置位接收中断标志UCxRXIFG,表示接收/发送操作完成。 发送中断标志位UCxTXIFG被置位后,表明数据已从UCxTXBUF缓冲区进入TX移位寄存器, UCxTXBUF寄存器已经为发送新数据做好准备,但并不意味着传送和接收的完成。 为了在主机模式下接收USCI数据,数据必须事先写入UCxTXBUF,因为接收和发送操作不是 马上进行的。 4线SPI主机模式 在4线主机模式中,UCxSTE用来防止与其它主机相冲突并象表12-1描述的那样控制主机。当 UCxSTE处于主机不活动状态时: UCxSIMO 和 UCxCLK设置为输入,不再驱动总线。 出错位UCFE置位,表明在通讯的完整性上,使用者未按照规则操作。 内部状态被复位时,移位操作取消。 如果数据写入UCxTXBUF而主机通过UCxSTE位保持非工作状态, UCxSTE转换为主机工作状态, 数据立即被发送。如果一个正在工作的发送过程,因UCxSTE转换为主机不运行状态而取消时, 当UCxSTE转向主机运行状态时数据需要被重新写入UCxTXBUF。 UCxSTE输入信号不能应用3线主机 模式。 12.3.4 从机模式
msp430用iic方式读取数据
void iic_write_byte(uchar wdata)//函数功能:向I2C从机写入一个字节{uchar i,temp,temp1;temp1=wdata;for(i=0;i<8;i++){scl = 0;iic_delay();temp=temp1;temp=temp&0x80;if(temp==0x80)sda=1;elsesda=0;iic_delay();scl=1;iic_delay();scl=0;iic_delay();temp1=temp1<<1;}}char iic_read_byte(void) //函数功能:从I2C从机中读出一个字节{uchar x;char data_data;for(x=0;x<8;x++){data_data=data_data<<1;sda=1;iic_delay();scl=0;iic_delay();scl=1;iic_delay();if(sda==1)data_data|=0x01;}return data_data;}void iic_write(uchar byte_add,uchar wdata)//函数功能:按地址写入一字节数据{uchar t;t=(IIC_WRITE<<1);iic_write_byte(t);iic_write_byte(byte_add);iic_write_byte(wdata);}char iic_read(uchar byte_add) //函数功能:按地址读出一字节数据{uchar t;char x;t=(IIC_WRITE<<1);iic_write_byte(t);iic_write_byte(byte_add);t=((IIC_READ<<1)|0x01);iic_write_byte(t);x=iic_read_byte();return x;}#define IIC_READ 0x1D //定义读指令#define IIC_WRITE 0x1D //定义写指令void iic_write_byte(uchar wdata)//函数功能:向I2C从机写入一个字节{uchar i,temp,temp1;temp1=wdata;for(i=0;i<8;i++){scl = 0;iic_delay();temp=temp1;temp=temp&0x80;if(temp==0x80)sda=1;elsesda=0;iic_delay();scl=1;iic_delay();scl=0;iic_delay();temp1=temp1<<1;}}char iic_read_byte(void) //函数功能:从I2C从机中读出一个字节{uchar x;char data_data;for(x=0;x<8;x++){data_data=data_data<<1;sda=1;iic_delay();scl=0;iic_delay();scl=1;iic_delay();if(sda==1)data_data|=0x01;}return data_data;}void iic_write(uchar byte_add,uchar wdata)//函数功能:按地址写入一字节数据{uchar t;t=(IIC_WRITE<<1);iic_write_byte(t);iic_write_byte(byte_add);iic_write_byte(wdata);}char iic_read(uchar byte_add) //函数功能:按地址读出一字节数据{uchar t;char x;t=(IIC_WRITE<<1);iic_write_byte(t);iic_write_byte(byte_add);t=((IIC_READ<<1)|0x01);iic_write_byte(t);x=iic_read_byte();return x;}。
MSP430中文数据手册【Word版】28p
注释:x为P2口的位标示符,从0到4
注释:1.ROM版本有可供选择的上拉或下拉电阻
2.可选上拉或下拉电阻的熔丝只能在工厂编程
输入输出电路(续)
带有施密特触发器的输入输出口P2,P2.5,供基本时钟模块使用的Rosc功能
输入输出电路(续)
P2口,未连接的位P2.6和P2.7
MSP430混合信号微控制器数据手册
产品特性
●低电压范围:2.5V~5.5V
●超低功耗
——活动模式:330μA at 1M据保持):0.1μA
●从待机模式唤醒响应时间不超过6μs
●16位精简指令系统,指令周期200ns
●基本时钟模块配置
——多种内部电阻
供电电流(进入VCC)不包括外部电流
注释:所有输入连接到VSS或VCC,输出悬空。
与系统频率相对应的活动模式下的电流消耗:
与供电电压相对应的活动模式下的电流消耗:
施密特触发式输入_P1和P2口
标准输入RST/NMI,TCK,TMS,TDI
输入Px.x,Tax
注释:1.外部信号每次将中断标志置位,t int 周期和时间参数必须满足条件。即使触发信号比t int短,也可能会使标志位置位。为了确保标志可靠置位,信号周期和时间都应满足条件。
2.低功耗模式0(LPM0):CPU停止工作,外围模块继续工作,ACLK和SMCLK有效,MCLK的环路控制无效。
3.低功耗模式1(LPM1):CPU停止工作,外围模块继续工作,ACLK和SMCLK有效,MCLK的环路控制无效,如果数字控制振荡器(DCO)没有被用于活动模式,其DC发生器被关闭。
4. 低功耗模式2(LPM2):CPU停止工作,外围模块继续工作,ACLK有效,SMCLK和MCLK环路控制无效,DCO的DC发生器关闭。
MSP430F2XX中文手册(加了标签) 5.Flash块控制器
Page 1 of 18MSP430F2系列16位超低功耗单片机模块原理第5章 Flash 块控制器版本: 1.3日期: 2007.6.原文: TI MSP430x2xxfamily.pdf翻译: 余川编辑: DC 微控技术论坛版主注:以下文章是翻译TI MSP430x2xxfamily.pdf 文件中的部分内容。
由于我们翻译水平有限,有整理过程中难免有所不足或错误;所以以下内容只供参考.一切以原文为准。
详情请密切留意微控技术论坛。
第五章 Flash 存储控制器本章介绍了MSP430x2xx 系列单片机Flash 存储控制器的操作。
5.1 Flash 存储器的介绍Page 2 of 18 5.2 Flash 存储器的分段结构5.3 Flash 存储器的操作5.4 Flash 存储器的控制寄存器5.1 Flash 存储器的介绍MSP430 的F lash 存储器是可位/字节/字寻址和编程的存储器。
该模块由一个集成控制器来控制编程和擦除的操作。
控制器包括三个寄存器,一个时序发生器及一个提供编程/擦除电压的电压发生器。
MSP430 的F lash 存储器的特点有:● 产生内部编程电压● 可位/字节/字编程● 超低功耗操作● 支持段擦除和多段模块擦除F lash 存储器和控制器的结构框图如图5−1所示。
注意:F lash 写入和擦除操作期间的最小电压值V CC 应为2.2V 。
如果在操作期间V CC 低于2.2V ,写入或擦除的结果将是不确定的。
图5−1 F lash 存储器框图Page 3 of 185.2 Flash 存储器的分段结构MSP430 F lash 存储器分成多个段。
可对其进行单个位/字节/字的写入,但是最小的擦除单位是段。
F lash 存储器分为主存储器和信息存储器两部分,在操作上两者没有什么区别,程序代码和数据可以存储于任意部分。
两部分的区别在于段的大小和物理地址。
信息存储器有四个64字节的段,主存储器有两个或更多的512字节的段。
MPS430用户手册
IAR Embedded Workbench™Version3+ for MSP430™User's GuideLiterature Number:SLAU138AFJune2004–Revised June2014Contents Preface (6)1Get Started Now! (8)1.1Software Installation (9)1.2Flashing the LED (9)1.3Important MSP430Documents on the CD-ROM and Web (10)2Development Flow (11)2.1Overview (12)2.2Using KickStart (12)2.2.1Project Settings (13)2.2.2Using Math Library for MSP430(MSPMathlib)in IAR EW4305.60.1and Newer (14)2.2.3Additional Project Settings for MSP430L092and MSP430C092 (14)2.2.4Creating a Project From Scratch (16)2.2.5Additional Project Settings for Ultra-Low-Power Mode(LPMx.5)Debugging (17)2.2.6Password Protection for MSP430Devices (18)2.2.7Using an Existing IAR V1.x,V2.x,or V3.x Project (18)2.2.8Stack Management and.xcl Files (19)2.2.9How to Generate Texas Instruments.TXT(and Other Format)Files (19)2.2.10Overview of Example Programs (19)2.3Using C-SPY (19)2.3.1Breakpoint Types (19)2.3.2Using Breakpoints (22)2.3.3Using Single Step (22)2.3.4Using Watch Windows (23)3EnergyTrace™Technology (24)3.1Introduction (24)3.2Energy Measurement (24)3.3IAR Embedded Workbench®for MSP430Integration (24)3.3.1Debugging Devices With EnergyTrace++Technology Support (24)3.3.2Debugging Devices Without EnergyTrace++Technology Support (31)3.4Measuring Low-Power Currents (34)3.5EnergyTrace Technology FAQs (35)4Memory Protection Unit(MPU)and Intellectual Property Encapsulation(IPE) (37)A Frequently Asked Questions (38)A.1Hardware (39)A.2Program Development(Assembler,C-Compiler,Linker) (39)A.3Debugging(C-SPY) (41)B FET-Specific Menus (45)B.1Menus (46)B.1.1Emulator→Device Information (46)B.1.2Emulator→Release JTAG on Go (46)B.1.3Emulator→Resynchronize JTAG (46)B.1.4Emulator→Init New Device (46)B.1.5Emulator→Secure-Blow JTAG Fuse (46)B.1.6Emulator→Breakpoint Usage (46)2Contents SLAU138AF–June2004–Revised June2014Submit Documentation FeedbackCopyright©2004–2014,Texas Instruments IncorporatedB.1.7Emulator→Advanced→Clock Control (46)B.1.8Emulator→Advanced→Emulation Mode (46)B.1.9Emulator→Advanced→Memory Dump (47)B.1.10Emulator→Advanced→Breakpoint Combiner (47)B.1.11Emulator→State Storage Control (47)B.1.12Emulator→State Storage Window (47)B.1.13Emulator→Sequencer Control (47)B.1.14Emulator→"Power on"Reset (47)B.1.15Emulator→GIE on/off (47)B.1.16Emulator→Leave Target Running (47)B.1.17Emulator→Force Single Stepping (47)Revision History (48)3 SLAU138AF–June2004–Revised June2014Contents Submit Documentation FeedbackCopyright©2004–2014,Texas Instruments IncorporatedList of Figures1-1.Activate Project (9)1-2.Activate Project in Workspace Overview (10)2-1.L092Mode (14)2-2.C092Emulation Mode (15)2-3.C092Password (15)2-4.Enable Ultra-Low-Power Debug Mode (17)2-5.LPMx.5Notifications (18)2-6.JTAG Password (18)3-1.Pulse Density and Current Flow (24)3-2.Debug Session With EnergyTrace++Windows (25)3-3.Debug Options (26)3-4.Emulator Pulldown Menu With EnergyTrace++-Related Functions (27)3-5.Enabling the State Log Window (27)3-6.State Log Window With EnergyTrace++Data (28)3-7.State Log Summary With EnergyTrace++Data (28)3-8.Power Log Setup Window (28)3-9.Power Log Window With EnergyTrace++Data (29)3-10.Timeline With Power Log and State Graphs Disabled (29)3-11.Timeline With EnergyTrace++Data (30)3-12.Function Profiler With EnergyTrace++Data (30)3-13.Debug Session With EnergyTrace Windows (31)3-14.Emulator Pulldown Menu With EnergyTrace-Related Functions (32)3-15.Power Log Setup Window (32)3-16.Power Log Window With EnergyTrace Data (33)3-17.Timeline With Power Log Graph Disabled (33)3-18.Timeline With EnergyTrace Data (34)3-19.LPM3Current When Executing Under Debug Control (34)3-20.Release JTAG on Go Option in Emulator Pulldown Menu (35)3-21.LPM3Current When Executing with JTAG Signals Released (35)4-1.MPU Configuration Dialog (37)4List of Figures SLAU138AF–June2004–Revised June2014Submit Documentation FeedbackCopyright©2004–2014,Texas Instruments IncorporatedList of Tables2-1.Device Architecture,Breakpoints,and Other Emulation Features (20)5 SLAU138AF–June2004–Revised June2014List of Tables Submit Documentation FeedbackCopyright©2004–2014,Texas Instruments IncorporatedPrefaceSLAU138AF–June2004–Revised June2014Read This FirstAbout This ManualThis manual describes the use of IAR Embedded Workbench®(EW430)with the MSP430™ultra-low-power microcontrollers.How to Use This ManualRead and follow the instructions in the Get Started Now!chapter.This chapter provides instructions on installing the software,and describes how to run the demonstration programs.After you see how quick and easy it is to use the development tools,TI recommends that you read all of this manual.This manual describes only the setup and basic operation of the software development environment,but it does not fully describe the MSP430microcontrollers or the complete development software and hardware systems.For details of these items,see the appropriate TI and IAR™documents listed in RelatedDocumentation From Texas Instruments,Important MSP430Documents on the CD-ROM and Web.This manual applies to the use with Texas Instruments'MSP-FET430UIF,MSP-FET430PIF,and eZ430 development tools series.These tools contain the most up-to-date materials available at the time of packaging.For the latestmaterials(including data sheets,user's guides,software,and application information),visit the TI MSP430 web site at /msp430or contact your local TI sales office.Information About Cautions and WarningsThis book may contain cautions and warnings.CAUTIONThis is an example of a caution statement.A caution statement describes a situation that could potentially damage yoursoftware or equipment.The information in a caution or a warning is provided for your protection.Read each caution and warning carefully.MSP430,EnergyTrace are trademarks of Texas Instruments.6Read This First SLAU138AF–June2004–Revised June2014 IAR Embedded Workbench is a registered trademark of IAR Systems AB.Submit Documentation Feedback All other trademarks are the property of their respective owners.Copyright©2004–2014,Texas Instruments Incorporated Related Documentation From Texas Instruments Related Documentation From Texas InstrumentsMSP430development tools documentationMSP430Hardware Tools User's Guide,literature number SLAU278eZ430-F2013Development Tool User's Guide,literature number SLAU176eZ430-RF2480User's Guide,literature number SWRA176eZ430-RF2500Development Tool User's Guide,literature number SLAU227eZ430-RF2500-SEH Development Tool User's Guide,literature number SLAU273eZ430-Chronos Development Tool User's Guide,literature number SLAU292MSP430device data sheetsMSP430x1xx Family User's Guide,literature number SLAU049MSP430x2xx Family User's Guide,literature number SLAU144MSP430x3xx Family User's Guide,literature number SLAU012MSP430x4xx Family User's Guide,literature number SLAU056MSP430x5xx and MSP430x6xx Family User's Guide,literature number SLAU208MSP430FR57xx Family User's Guide,literature number SLAU272MSP430FR58xx,MSP430FR59xx,MSP430FR68xx,and MSP430FR69xx Family User's Guide,literature number SLAU367CC430device data sheetsCC430Family User's Guide,literature number SLAU259If You Need AssistanceSupport for the MSP430devices and the FET development tools is provided by the Texas Instruments Product Information Center(PIC).Contact information for the PIC can be found on the TI web site at/support.The Texas Instruments E2E Community support forums for the MSP430is available to provide open interaction with peer engineers,TI engineers,and other experts.Additional device-specific information can be found on the MSP430web site.NOTE:The KickStart kit is supported by Texas Instruments.Although the KickStart kit is a product of IAR,Texas Instruments provides the support for it.Therefore,please do not request support for KickStart from IAR.Consult the extensivedocumentation provided with KickStart before requesting assistance.7 SLAU138AF–June2004–Revised June2014Read This First Submit Documentation FeedbackCopyright©2004–2014,Texas Instruments IncorporatedChapter1SLAU138AF–June2004–Revised June2014Get Started Now!This chapter provides instruction on installing the software,and shows how to run the demonstration programs.Topic Page1.1Software Installation (9)1.2Flashing the LED (9)1.3Important MSP430Documents on the CD-ROM and Web (10)8Get Started Now!SLAU138AF–June2004–Revised June2014Submit Documentation FeedbackCopyright©2004–2014,Texas Instruments Incorporated Software Installation 1.1Software InstallationFollow the instructions on the supplied READ ME FIRST document to install the IAR EmbeddedWorkbench™KickStart kit.Read the file<Installation Root>\Embedded Workbenchx.x\430\doc\readme.htm from IAR for the latest information about the Workbench.The term KickStartrefers to the function-limited version of Embedded Workbench(including C-SPY™debugger).KickStart is supplied on the CD-ROM included with each FET,and the latest version is available from the MSP430 web site.The documents mentioned in the previous paragraph(and this document)can be accessed using:Start→Programs→IAR Systems→IAR Embedded Workbench KickStart for MSP430V3.KickStart is compatible with Windows2000(SP4),Windows XP(32bit and64bit),Windows Vista(32bit and64bit),and Windows7(32bit and64bit).However,the USB FET interface works with only Windows XP(32bit and64bit),Windows Vista(32bit and64bit),and Windows7(32bit and64bit).1.2Flashing the LEDThis section demonstrates on the FET the equivalent of the C-language"Hello World!"introductoryprogram.An application that flashes the LED is developed and downloaded to the FET,and then run.1.Start the Workbench(Start→Programs→IAR Systems→IAR Embedded Workbench KickStart forMSP430V3→IAR Embedded Workbench).2.Click File→Open Workspace to open the file at:<Installation Root>\Embedded Workbench x.x\430\FET_examples\Flashing the LED.eww.The workspace window opens.3.Click on the tab at the bottom of the workspace window that corresponds to the MSP430device(MSP430xxxx)and desired language(assembler or C)to set a project active(see Figure1-1).Figure1-1.Activate Project9 SLAU138AF–June2004–Revised June2014Get Started Now! Submit Documentation FeedbackCopyright©2004–2014,Texas Instruments IncorporatedImportant MSP430Documents on the CD-ROM and Web Alternatively,right click to activate a project in the Workspace Overview tab(see Figure1-2).Figure1-2.Activate Project in Workspace Overview4.Click Project→Options→FET Debugger→Setup→Connection to select the appropriate port:Texas Instruments LPT-IF for the parallel FET Interface(MSP-FET430PIF)or Texas Instruments USB-IF for the USB Interface(MSP-FET430UIF)or for the eZ430.5.Click Project→Rebuild All to build and link the source code.You can view the source code by double-clicking on the project,and then double-clicking on the displayed source file.6.Click Project→Debug to start the C-SPY debugger.C-SPY erases the device flash and thendownloads the application object file to the device flash.See FAQ Debugging#1if C-SPY is unable to communicate with the device.7.Click Debug→Go to start the application.The LED should flash.8.Click Debug→Stop Debugging to stop debugging,to exit C-SPY,and to return to the Workbench.9.Click File→Exit to exit the Workbench.Congratulations,you have just built and tested an MSP430application!1.3Important MSP430Documents on the CD-ROM and WebThe primary sources of MSP430information are the device-specific data sheet and user's guide.The most up-to-date versions of these documents that are available at the time of production are provided on the CD-ROM included with this tool.The MSP430web site(/msp430)contains the most recent version of these documents.PDF documents describing the IAR tools(Workbench and C-SPY,the assembler,the C compiler,thelinker,and the librarian)are in the common\doc and430\doc folders.Supplements to the documents(that is,the latest information)are available in HTML format in the same directories.430\doc\readme_start.htm provides a convenient starting point for navigating the IAR documentation.10Get Started Now!SLAU138AF–June2004–Revised June2014Submit Documentation FeedbackCopyright©2004–2014,Texas Instruments IncorporatedChapter2SLAU138AF–June2004–Revised June2014Development Flow This chapter describes how to use KickStart to develop application software and how to use C-SPY to debug it.Topic Page2.1Overview (12)2.2Using KickStart (12)2.3Using C-SPY (19)11 SLAU138AF–June2004–Revised June2014Development Flow Submit Documentation FeedbackCopyright©2004–2014,Texas Instruments IncorporatedOverview 2.1OverviewApplications are developed in assembler or C using the Workbench,and they are debugged using C-SPY.C-SPY is seamlessly integrated into the Workbench.However,it is more convenient to make thedistinction between the code development environment(Workbench)and the debugger(C-SPY).C-SPY can be configured to operate with the FET(that is,an actual MSP430device)or with a software simulator of the device.KickStart refers to the Workbench and C-SPY collectively.The KickStart software tools area product of IAR.Documentation for the MSP430family and KickStart is extensive.The CD-ROM supplied with this toolcontains a large amount of documentation describing the MSP430.The MSP430home page(/msp430)is another source of MSP430information.The components of KickStart(workbench and debugger,assembler,compiler,linker)are fully documented in<Installation Root>\EmbeddedWorkbench x.x\common\doc and<Installation Root>\Embedded Workbench\430\doc..htm files located throughout the KickStart directory tree contain the most up-to-date information and supplement the PDF files.In addition,KickStart documentation is available online via Help.Read Me First files from IAR and TI and this document can be accessed using Start→Programs→IAR Systems→IAR Embedded Workbench KickStart for MSP430V3.Tool User's Guide Most Up-To-Date Information Workbench,C-SPY EW430_UsersGuide.pdf readme.htm,ew430.htm,cs430.htm,cs430f.htmAssembler EW430_AssemblerReference.pdf a430.htm,a430_msg.htmCompiler EW430_CompilerReference.pdf icc430.htm,icc430_msg.htmC library CLibrary.htmLinker and Librarian xlink.pdf xlink.htm,xman.htm,xar.htm2.2Using KickStartThe KickStart edition is a special starter kit or evaluation version of IAR Embedded Workbench withlimitations both in code size and in the service and support that is provided.Limitations:•The C compiler does not generate an assembly code list file.•The code size limit of the MSP430IAR KickStart C/C++Compiler is set to4Kbytes for traditional MSP430devices and8Kbytes for MSP430X devices(see Table2-1for detailed information aboutwhich MSP430device is based on which architecture).•The IAR Assembler delivered is the full version without any restrictions.•The IAR XLINK Linker links a maximum of4Kbytes originating from C source code for traditional MSP430devices and8Kbytes for MSP430X devices(see Table2-1for detailed information aboutwhich MSP430device is based on which architecture),but an unlimited amount of code originatingfrom assembly code.•The IAR KickStart C-SPY Simulator reads a maximum of4Kbytes originating from C code for traditional MSP430devices and8Kbytes for MSP430X devices but is unlimited in the amount ofassembly code read(see Table2-1for detailed information about which MSP430device is based onwhich architecture).•MISRA C is not available.•The runtime library source code is not included.A full(that is,unrestricted)version of the software tools can be purchased from IAR.A mid-featured toolset–called Baseline,with a12Kbyte C-code size limitation and basic floating-point operations–is also available from IAR.See the IAR web site(www.iar.se)for more information.12Development Flow SLAU138AF–June2004–Revised June2014Submit Documentation FeedbackCopyright©2004–2014,Texas Instruments Incorporated Using KickStart 2.2.1Project SettingsThe settings required to configure the Workbench and C-SPY are numerous and detailed.Read andthoroughly understand the documentation supplied by IAR when dealing with project settings.Review the project settings of the supplied assembler and C examples(the project settings are accessed usingProject→Options with the project name selected).Use these project settings as templates whendeveloping your own projects.Note that if the project name is not selected when settings are made,the settings are applied to the selected file(not to the project).The following project settings are recommended or required:•Specify the target device(General Options→Target→Device).•Enable an assembler project or a C or assembler project(General Options→Target→Assembler-only project).•Enable the generation of an executable output file(General Options→Output→Output file→Executable).•To most easily debug a C project,disable optimization[C/C++Compiler→Optimizations→Size→None(Best debug support)].•Enable the generation of debug information in the compiler output(C/C++Compiler→Output→Generate debug information).•Specify the search path for the C preprocessor(C/C++Compiler→Preprocessor→Include Paths).•Enable the generation of debug information in the assembler output(Assembler→Output→Generate Debug Info).•Specify the search path for the assembler preprocessor(Assembler→Preprocessor→Include Paths).•To debug the project using C-SPY,specify a compatible format[Linker→Output→Format→Debug information for C-SPY(with runtime control modules or with I/O emulation modules)].•Specify the search path for any used libraries(Linker→Config→Search paths).•Specify the C-SPY driver.Select Project→Options→Debugger→Setup→Driver→FET Debugger to debug on the FET(that is,MSP430device).Select Simulator to debug on the simulator.If FETDebugger is selected,use Project→Options→FET Debugger→Setup→Connection to select theappropriate port:Texas Instruments LPT-IF for the parallel FET Interface(MSP-FET430PIF)or TexasInstruments USB-IF for the USB Interface(MSP-FET430UIF)or for the eZ430.•Enable the Device Description file.This file makes C-SPY"aware"of the specifics of the device it is debugging.This file corresponds to the specified target device(Debugger→Setup→Devicedescription file→Override default).•Enable the erasure of the Main and Information memories before object code download(FET Debugger→Download→Erase main and Information memory).•To maximize system performance during debug,disable Virtual Breakpoints(FET Debugger→Breakpoints→Use virtual breakpoints)and disable all System Breakpoints(FET Debugger→Breakpoints→System breakpoints on).NOTE:Use Factory Settings to quickly configure a project.Use the Factory Settings button to quickly configure a project to a usable state.The following steps can be used to quickly configure a project.Note that the General Options tab does not have a Factory Settings button.1.Specify the target device(General Options→Target→Device).2.Enable an assembler project or a C or assembler project(General Options→Target→Assembler-only project).3.Enable the generation of an executable output file(General Options→Output→Output file→Executable).4.Accept the factory settings for the compiler(C/C++Compiler→Factory Settings).5.Accept the factory settings for the assembler(Assembler→Factory Settings).13 SLAU138AF–June2004–Revised June2014Development Flow Submit Documentation FeedbackCopyright©2004–2014,Texas Instruments IncorporatedUsing KickStart 6.Accept the factory settings for the linker(Linker→Factory Settings).7.Accept the factory settings for C-SPY(Debugger→Factory Settings).8.Debug on the hardware(Debugger→Setup→Driver→FET Debugger).9.Specify the active parallel port used to interface to the FET if not LPT1(FET Debugger→Setup→Connection→Texas Instruments LPT-IF)or specify the USB port(FET Debugger→Setup→Connection→Texas Instruments USB-IF).NOTE:Avoid the use of absolute path names when referencing files.Instead,use the relative pathname keywords$TOOLKIT_DIR$and$PROJ_DIR$.See theIAR documentation for a description of these keywords.The use of relative path namespermits projects to be moved easily,and projects do not require modification when IARsystems are upgraded(for example,from KickStart or Baseline to Full).2.2.2Using Math Library for MSP430(MSPMathlib)in IAR EW4305.60.1and NewerTI's MSPMathlib is part of EW4305.60.1and newer releases.This optimized library provides up to26x better performance in applications that use floating point scalar math.For details,see the MSPMathlibweb page(/tool/mspmathlib).MSPMathlib may be enabled for new and existing projects on all supported devices.Enable or disable MSPMathlib in the project options(General Options→Library Configuration→MathLib).2.2.3Additional Project Settings for MSP430L092and MSP430C092The MSP430L092can operate in two different modes:L092mode and C092emulation mode.Thepurpose of the C092emulation mode is to behave like a C092with up to1920bytes of code at its final destination for mask generation.The operation mode is determined by EW430before starting the debugger.Two radio buttons areavailable for the mode selection.By default the L092mode is selected(see Figure2-1and Figure2-2).Figure2-1.L092Mode14Development Flow SLAU138AF–June2004–Revised June2014Submit Documentation FeedbackCopyright©2004–2014,Texas Instruments Incorporated Using KickStartFigure2-2.C092Emulation Mode2.2.3.1MSP430L092Loader CodeThe Loader Code in the MSP430L092is a ROM-code from TI that provides a series of services.It enables customers to build autonomous applications without needing to develop a ROM mask.Such an application consists of an MSP430device containing the loader(for example,MSP430L092)and an SPI memorydevice(for example,'95512or'25AA40);these and similar devices are available from variousmanufacturers.The majority of use cases for an application with a loader device and external SPI memory for native0.9-V supply voltage are late development,prototyping,and small series production.Figure2-1shows the selection for loading the application into the external SPI memory.2.2.3.2Password Protection of MSP430C092The MSP430C092is a customer-specific ROM device that is protected by a password.To start a debug session,the password must be provided to EW430.Figure2-3shows how to provide a HEX password in EW430.Figure2-3.C092Password15 SLAU138AF–June2004–Revised June2014Development Flow Submit Documentation FeedbackCopyright©2004–2014,Texas Instruments IncorporatedUsing KickStart 2.2.4Creating a Project From ScratchThis section presents step-by-step instructions to create an assembler or C project from scratch,and to download and run the application on the MSP430(see also Section2.2.1,Project Settings).The MSP430 IAR Embedded Workbench IDE User's Guide presents a more comprehensive overview of the process.1.Start the Workbench(Start→Programs→IAR Systems→IAR Embedded Workbench KickStart forMSP430V3→IAR Embedded Workbench).2.Create a new text file(File→New→File).3.Enter the program text into the file.NOTE:Use.h files to simplify your code development.KickStart is supplied with files that define the device registers and the bit names for eachdevice.These files can greatly simplify the task of developing your program.The files arelocated in<Installation Root>\Embedded Workbench x.x\430\inc.Include the.h filecorresponding to your target device in your text file(#include"msp430xyyy.h").Additionally,files io430xxxx.h are provided and are optimized to be included by C source files.4.Save the program text file(File→Save).It is recommended that assembler text files be saved with a file-type suffix of".s43"and that C text files be saved with a file-type suffix of".c".5.Create a new workspace(File→New→Workspace).6.Create a new project(Project→Create New Project).Select Tool chain:MSP430,Project Templates:Empty project and click OK.Specify a project name and click Save.7.Add the program text file to the project(Project→Add Files).Select the program text file and clickOpen.Alternatively,double-click on the file to add it to the project.NOTE:How to add assembler source files to your projectThe default file type presented in the Add Files window is"C/C++Files".To view assemblerfiles(.s43),select"Assembler Files"in the"Files of type"drop-down menu.8.Save the workspace(File→Save Workspace).Specify a workspace name and click Save.9.Configure the project options(Project→Options).For each of the subcategories(General Options,C/C++Compiler,Assembler,Linker,Debugger),accept the default Factory Settings with the followingexceptions:•Specify the target device(General Options→Target→Device).•Enable an assembler project or a C or assembler project(General Options→Target→Assembler-only project).•Enable the generation of an executable output file(General Options→Output→Output file→Executable).•To debug on the FET(that is,the MSP430),click Debugger→Setup→Driver→FET Debugger.•Specify the active port used to interface to the FET(FET Debugger→Setup→Connection).10.Build the project(Project→Rebuild All).11.Debug the application using C-SPY(Project→Debug).This starts C-SPY,and C-SPY takes control ofthe target,erases the target memory,programs the target memory with the application,and resets thetarget.See FAQ Debugging#1if C-SPY is unable to communicate with the device.12.Click Debug→Go to start the application.13.Click Debug→Stop Debugging to stop the application,to exit C-SPY,and to return to the Workbench.14.Click File→Exit to exit the Workbench.16Development Flow SLAU138AF–June2004–Revised June2014Submit Documentation FeedbackCopyright©2004–2014,Texas Instruments Incorporated Using KickStart 2.2.5Additional Project Settings for Ultra-Low-Power Mode(LPMx.5)Debugging2.2.5.1What is LPMx.5LPMx.5is an ultra-low-power mode in which the entry and exit is handled differently than the other low-power modes.LPMx.5gives the lowest power consumption available on a device.To achieve this,entry to LPMx.5disables the LDO of the PMM module,which removes the supply voltage from the core and the JTAGmodule of the device.Because the supply voltage is removed from the core,all register contents andSRAM contents are lost.Exit from LPMx.5causes a BOR event,which forces a complete reset of thesystem.NOTE:The option"RELEASE JTAG ON GO"is currently not supported in the EmbeddedWorkbench when LPMx.5debugging is active.See the MSP430device family user's guidefor additional LPMx.5and ultra-low-power debug mode details.2.2.5.2Enable Ultra-Low-Power Debug ModeTo enable the ultra-low power debug mode feature the“Enable ULP/LPMx.5debug”checkbox must be enabled by clicking FET Debugger->Setup->Enable ULP/LPMx.5debug(see Figure2-4).When the ultra-low power debug mode is enabled a notification is displayed in the Debugger log every time thetarget device enters and leaves LPMx.5mode(see Figure2-5).Press the Halt or Reset button in Embedded Workbench to wake up the target device from LPMx.5.Execution of the code is halted at the start of the program.All breakpoints that had been active beforeLPMx.5are restored and reactivated automatically.Figure2-4.Enable Ultra-Low-Power Debug Mode17 SLAU138AF–June2004–Revised June2014Development Flow Submit Documentation FeedbackCopyright©2004–2014,Texas Instruments Incorporated。
MSP430F2XX中文手册(加了标签) 4.基础时钟模块+
Page 1 of 12MSP430F2系列16位超低功耗单片机模块原理第4章 Basic Clock + 基础时钟模块+版本: 1.4日期: 2007.6.原文: TI MSP430x2xxfamily.pdf翻译: 张超 哈尔滨理工大学编辑: DC 微控技术论坛版主注:以下文章是翻译TI MSP430x2xxfamily.pdf 文件中的部分内容。
由于我们翻译水平有限,有整理过程中难免有所不足或错误;所以以下内容只供参考.一切以原文为准。
详情请密切留意微控技术论坛。
第四章 基础时钟模块+4.1基础时钟模块+介绍基础时钟模块+支持低系统消耗和超低功耗。
采用三种片内时钟信号,用户可以选择合适的性能和低功耗。
基础时钟模块只需接一个外部电阻、一个或两个外部晶体、或者用振荡器,通过软件控制。
基础时钟模块+有4个时钟源:LFXT1CLK:由低频时钟晶体或外接32768Hz时钟源产生的低频/高频振荡器或由标准晶体、振荡器,或外部400KH z~16M Hz的外部时钟源提供。
XT2CLK:可供选择的高频振荡器,由标准晶体、振荡器,或外部400KH z~16M Hz的外部时钟源提供。
DCOCLK:片内可数字控制的振荡器。
VLOCLK:片内超低功耗、12KH z的低频振荡器。
基础时钟模块可提供的三种时钟信号:ACLK:辅助时钟。
ACLK由软件选择来自LFXT1CLK和VLOCLK之一的时钟信号。
ACLK 经1,2,4,8分频后得到。
ACLK可由软件选作各个外围模块。
MCLK:主时钟。
MCLK由软件选择来自LFXT1CLK,VLOCLK,XT2CLK(如果片内提供),DCOCLK之一的时钟信号。
MCLK由1,2,4,8分频得到。
MCLK用于CPU和系统。
SMCLK:子系统时钟。
SMCLK由软件选择来自LFXT1CLK,VLOCLK,XT2CLK(片内提供),DCOCLK之一的时钟信号。
SMCLK由1,2,4,8分频得到。
基于msp430的i2c模拟总线程序讲解
//等待写操作完成
EEPROM_AckPolling();
//写入数据
EEPROM_ByteWrite(0*0003,0*78);
//等待写操作完成
EEPROM_AckPolling();
//写入数据
EEPROM_ByteWrite(0*0004,0*9A);
//等待写操作完成
EEPROM_AckPolling(); //写入数据 EEPROM_ByteWrite(0*0005,0*BC); //等待写操作完成 EEPROM_AckPolling(); //读出数据,随机读 Data[0] = EEPROM_RandomRead(0*0000); //地址自动加 1 //读出数据,当前地址读 Data[1] = EEPROM_CurrentAddressRead(); //读出数据,当前地址读 Data[2] = EEPROM_CurrentAddressRead(); //读出数据,当前地址读 Data[3] = EEPROM_CurrentAddressRead(); //读出数据,当前地址读 Data[4] = EEPROM_CurrentAddressRead(); //读出数据,当前地址读 Data[5] = EEPROM_CurrentAddressRead(); } IIC.C *include <MSP430*16*.h> *include "IIC.h" *define SLAVEADDR 0*50; int t*_count; int r*_count; unsigned char I2CBuffer[3];
//去除 I2CEN 位 U0CTL &= ~I2CEN; I2CTCTL |= I2CRM; //使能 I2C 模块 U0CTL |= I2CEN; //设置 NACKIFG 标志 I2CIFG = NACKIFG; while (NACKIFG & I2CIFG) {
MSP430单片机数据手册—英
IMPORTANT NOTICETexas Instruments Incorporated and its subsidiaries (TI) reserve the right to make corrections, modifications, enhancements, improvements, and other changes to its products and services at any time and to discontinue any product or service without notice. Customers should obtain the latest relevant information before placing orders and should verify that such information is current and complete. All products are sold subject to TI’s terms and conditions of sale supplied at the time of order acknowledgment.TI warrants performance of its hardware products to the specifications applicable at the time of sale in accordance with TI’s standard warranty. T esting and other quality control techniques are used to the extent TI deems necessary to support this warranty. Except where mandated by government requirements, testing of all parameters of each product is not necessarily performed.TI assumes no liability for applications assistance or customer product design. Customers are responsible for their products and applications using TI components. T o minimize the risks associated with customer products and applications, customers should provide adequate design and operating safeguards.TI does not warrant or represent that any license, either express or implied, is granted under any TI patent right, copyright, mask work right, or other TI intellectual property right relating to any combination, machine, or process in which TI products or services are used. Information published by TI regarding third-party products or services does not constitute a license from TI to use such products or services or a warranty or endorsement thereof. Use of such information may require a license from a third party under the patents or other intellectual property of the third party, or a license from TI under the patents or other intellectual property of TI.Reproduction of information in TI data books or data sheets is permissible only if reproduction is without alteration and is accompanied by all associated warranties, conditions, limitations, and notices. Reproduction of this information with alteration is an unfair and deceptive business practice. TI is not responsible or liable for such altered documentation.Resale of TI products or services with statements different from or beyond the parameters stated by TI for that product or service voids all express and any implied warranties for the associated TI product or service and is an unfair and deceptive business practice. TI is not responsible or liable for any such statements. Following are URLs where you can obtain information on other Texas Instruments products and application solutions:Products ApplicationsAmplifiers Audio /audioData Converters Automotive /automotiveDSP Broadband /broadbandInterface Digital Control /digitalcontrolLogic Military /militaryPower Mgmt Optical Networking /opticalnetwork Microcontrollers Security /securityTelephony /telephonyVideo & Imaging /videoWireless /wirelessMailing Address:Texas InstrumentsPost Office Box 655303 Dallas, Texas 75265Copyright 2004, Texas Instruments Incorporated。
MSP430F2XX中文手册(加了标签) 1..MSP430体系结构
MSP430F2系列16位超低功耗单片机模块原理第1章MSP430体系结构版本: 1.3日期: 2007.4.原文: TI MSP430x2xxfamily.pdf翻译: 袁德纯编辑: DC 微控论坛版主注:以下文章是翻译TI MSP430x2xxfamily.pdf 文件中的部分内容。
由于我们翻译水平有限,有整理过程中难免有所不足或错误;所以以下内容只供参考.一切以原文为准。
详情请密切留意微控技术论坛。
Page 1 of 7第一章 MSP430的体系结构本章主要描述了MSP430的体系结构本章内容目录1.1MSP430的体系结构1.2可编程时钟系统1.3嵌入式仿真环境1.4地址空间1.5MSP430X2XX系列的提高1.1MSP430的体系结构将MSP430内部的16位精简指令集的CPU通过冯.诺依曼结构的地址总线和数据总线连接到外围设备和可编程时钟系统。
由于有一个先进的CPU配合具有标准组件存储印象的模拟和数字的外围设备,使得MSP430可用于处理混合信号。
MSP430x2xx系列的主要特性如下:◆超低功耗延长了电池的使用寿命●保持RAM 0.1uA●实时时钟模式 0.8uA●MIPS运行 250uA◆理想精确的模拟信号测量●门控比较定时器测量电阻类元件◆16位的精简指令集的CPU全新应用●更大的寄存器空间消除了运行空间的瓶颈●紧凑的核结构设计减少了功耗、降低了成本●使得高水平的编程更优化●27条核心指令和7种寻址方式●强大的矢量中断能力◆系统内的可编程FLASH使改变代码、在线升级和数据载入更灵活1.2 可编程时钟系统时钟系统是为电池供电系统而特别设计的。
只需要一个32KHZ的晶振就可以直接驱动一个低频的辅助时钟(ACLK)。
ACLK可工作于实时时钟模式,并具能够自我唤醒。
内部集成了一个DCO使主时钟(MCLK)可以被CPU和其他的高速外围设备所使用。
由于有了DCO,使得一个窄脉冲在少于2US 的时间内就可以将MSP430唤醒CPU工作。
MSP430的IIC初始化、读、写
调试通过的典型的程序如下:#include "msp430x22x4.h"#include "include.h"unsigned char Uart_tx[5];unsigned char UART_data_Num;unsigned char UART_data_Num_TMAX;unsigned char Uart_Buffer[5];//UART发送缓存器,要发送的数据放入其中void IICInit(){P3SEL &= (~BIT0);P3DIR |=0x01;P3OUT |=0x01;//将CC2500使能端关闭/***************/P3SEL |= 0x06;UCB0CTL1 |= UCSWRST;UCB0CTL0 = UCMST + UCMODE_3 + UCSYNC;UCB0CTL1 = UCSSEL_2 + UCSWRST;UCB0BR0 = 10;//7是很好//一般时钟设置的为1MHz。
UCB0BR1 = 0;UCB0I2CSA = 0x34;//从机手册上说的地址为68H,在写入的时候要右移一位,所以为34H UCB0CTL1 &= ~UCSWRST;}void AMRTMControl(){UCB0I2CSA = 0x34; //slave addressUCB0CTL1 |= UCTR;//写UCB0CTL1 |= UCTXSTT; //start condition,当产生了起始信号后,UCB0TXIFG被自动置一while((IFG2 & UCB0TXIFG) != UCB0TXIFG);//检测UCB0TXBUF是否为空,为空则UCB0TXIFG为1.UCB0TXBUF = 0x00;while((UCB0CTL1 & UCTXSTT) == UCTXSTT);//检测从机ACK信号,有ACK信号,则UCTXSTT自动清零//以上顺序不能改变while((IFG2 & UCB0TXIFG) != UCB0TXIFG);//检测UCB0TXBUF是否为空,UCB0TXBUF = 0x01;while((IFG2 & UCB0TXIFG) != UCB0TXIFG);//记住操作符号必须打括号,要不然会出现不可预测的错误,比如这个(IFG2 & UCB0TXIFG) != UCB0TXIFG,括号不能省略UCB0CTL1 |= UCTXSTP;}void AMRTMRead(){UCB0I2CSA = 0X34;UCB0CTL1 |= UCTR;UCB0CTL1 |=UCTXSTT;while((IFG2 & UCB0TXIFG) != UCB0TXIFG);UCB0TXBUF = 0x00;while((UCB0CTL1 & UCTXSTT) == UCTXSTT);while((IFG2 & UCB0TXIFG) != UCB0TXIFG);UCB0I2CSA = 0X34;UCB0CTL1 &= (~UCTR);UCB0CTL1 |=UCTXSTT;while((UCB0CTL1 & UCTXSTT) == UCTXSTT);for(unsigned char IICNumCounter = 0;IICNumCounter < 5; IICNumCounter++){while((IFG2 & UCB0RXIFG) != UCB0RXIFG);//检测是否已经接收完一个byte的数据Uart_Buffer[IICNumCounter] = UCB0RXBUF;if(IICNumCounter == 3){UCB0CTL1 |= UCTXSTP;}}}void AMRReset(){UCB0I2CSA = 0x34; //slave addressUCB0CTL1 |= UCTR;//写UCB0CTL1 |= UCTXSTT; //start condition,当产生了起始信号后,UCB0TXIFG被自动置一while((IFG2 & UCB0TXIFG) != UCB0TXIFG);//检测UCB0TXBUF是否为空,为空则UCB0TXIFG为1.UCB0TXBUF = 0x00;while((UCB0CTL1 & UCTXSTT) == UCTXSTT);//检测从机ACK信号,有ACK信号,则UCTXSTT自动清零//以上顺序不能改变while((IFG2 & UCB0TXIFG) != UCB0TXIFG);//检测UCB0TXBUF是否为空,UCB0TXBUF = 0x04;//固定的0x04产生复位while((IFG2 & UCB0TXIFG) != UCB0TXIFG);//记住操作符号必须打括号,要不然会出现不可预测的错误,比如这个(IFG2 & UCB0TXIFG) != UCB0TXIFG,括号不能省略UCB0CTL1 |= UCTXSTP;}void AMRSet(){UCB0I2CSA = 0x34; //slave addressUCB0CTL1 |= UCTR;//写UCB0CTL1 |= UCTXSTT; //start condition,当产生了起始信号后,UCB0TXIFG被自动置一while((IFG2 & UCB0TXIFG) != UCB0TXIFG);//检测UCB0TXBUF是否为空,为空则UCB0TXIFG为1.UCB0TXBUF = 0x00;while((UCB0CTL1 & UCTXSTT) == UCTXSTT);//检测从机ACK信号,有ACK信号,则UCTXSTT自动清零//以上顺序不能改变while((IFG2 & UCB0TXIFG) != UCB0TXIFG);//检测UCB0TXBUF是否为空,UCB0TXBUF = 0x02;//固定的0x04产生置位while((IFG2 & UCB0TXIFG) != UCB0TXIFG);//记住操作符号必须打括号,要不然会出现不可预测的错误,比如这个(IFG2 & UCB0TXIFG) != UCB0TXIFG,括号不能省略UCB0CTL1 |= UCTXSTP;}MSP430x22x4系列单片机,系统时钟选择的为8MHz主机初始化步骤:1、配置端口:仅仅配置端口功能就可以了不用配置方向2、UCB0CTL1 |= UCSWRST;解释看MSP430x2xx Family User's Guide数据手册3、配置为主机的IIC同步模式:UCB0CTL0 = UCMST + UCMODE_3 + UCSYNC;4、选择时钟源SMCLK; UCB0CTL1 = UCSSEL_2 + UCSWRST;5、配置IIC波特率UCB0BR0 = 10;//时钟设置8MHz。
MSP430I2C通信
主机
unsigned char TXData; unsigned char TXByteCtr;
int main(void) {
WDTCTL = WDTPW + WDTHOLD; P1SEL |= BIT6 + BIT7; P1SEL2|= BIT6 + BIT7; UCB0CTL1 |= UCSWRST; UCB0CTL0 = UCMST + UCMODE_3 + UCSYNC; UCB0CTL1 = UCSSEL_2 ; UCB0BR0 = 10; UCB0BR1 = 0; UCB0I2CSA = 0x48; UCB0CTL1 &= ~UCSWRST; IE2 |= UCB0TXIE;
break;
case 12: break;
// Vector 12: TXIFG
default: break;
}
}
例2:
/|\
/|\
MSP430G2xx3
100k 100k MSP430G2xx3
slave
|
| master
-----------------
|
| -----------------
case 12:
// Vector 12: TXIFG
if (TXByteCtr)
// Check TX byte counter
{
UCB0TXBUF = TXData;
// Load TX buffer
TXByteCtr--;
// Decrement TX byte counter
}
else
{
UCB0CTL1 |= UCTXSTP;
}
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
MSP430F5系列16位超低功耗单片机模块原理第17章通用串行通讯接口IIC模式版本: 1.0日期: 2008.9.原文: TI slau208.pdf (5xxfamily User's Guide)翻译: 张明慧郑州硬件研发工程师编辑: DC 微控技术论坛版主注:以下文章是翻译TI slau208.pdf 文件中的部分内容。
由于我们翻译水平有限,有整理过程中难免有所不足或错误;所以以下内容只供参考.一切以原文为准。
文章更新详情请密切留意微控技术论坛。
Page 1 of 24第14章通用串行通讯接口IIC模式5xx系列通用串行通信接口(USCI)在同一个硬件模块下支持多种串行通信模式,本章讨论I2C 模式的操作。
主题如下:17.1 USCI 概述17.2 USCI介绍:I2C模式17.3 USCI 操作:I2C模式17.4 USCI 寄存器:I2C模式17.1 USCI 概述通用串行通信接口(USCI)模块支持多种串行通信模式。
不同的USCI模块支持不同的模式。
每一个USCI模块以不同的字母命名。
例如,USCI_A不同于USCI_B等等。
如果不止一个相同的USCI模块被安装在同一个设备上,那么这些模块将以递增的数字命名。
例如,当一个设备上有两个USCI_A模块时,它们可以用USCI_A0和USCI_A1来命名。
如有需要,可以通过查阅设备明细表来确定哪些USCI模块可以配置在哪些设备上。
USCI_Ax 模块支持:UART模式脉冲整形的IrDA通信自动波特率检测的LIN通信SPI模式USCI_Bx 模块支持:I2C模式SPI模式17.2 USCI介绍:I2C模式在I2C模式中,USCI模块利用两线式I2C串行总线给MSP430和I2C兼容设备提供了一个互联接口。
挂在I2C总线上的外扩设备通过两线式I2C接口实现与USCI模块之间串行数据的接收与发送。
I2C模块的特性包括:1)遵循Philips半导体公司的I2C规范v2.17位和10位的设备寻址方式广播模式开始/重新开始/停止多主设发送/接收模式从设备接收/发送模式支持高达100kbps的标准模式和高达400kbps的高速模式2)主设模式下UCxCLK频率可编程3)低功耗设计4)从设备检测到开始信号将自动唤醒LPMx模式5) LPM4模式下可进行从设备操作图17-1描述了USCI在I2C模式下的配置。
Page 2 of 2417.3 USCI 操作:I2C模式I2C模式支持任何从模式或主模式下的I2C兼容设备。
图17-2给出了一个I2C总线的例子。
每个I2C设备都有唯一的地址可供识别,并可以随意作为发送端或接收端对其操作。
当进行数据传输时,I2C 总线上的设备可以被视为主设备或者是从设备。
主设备开始数据发送并产生时钟信号SCL。
任一能被主设备寻址到的设备都可视为一个从设备。
I2C数据通过串行数据线(SDA)和串行时钟线(SCL)进行传输。
SDA和SCL均为双向的,它们必须通过一个上拉电阻连接到供电电源的正极。
Page 3 of 24注意:SDA 和SCL电平MSP430 的SDA和SCL引脚电平不能上拉的超过MSP430的VCC电平。
17.3.1 USCI的初始化和复位通过PUC信号或者对UCSWRST置位都可以对USCI进行复位。
一旦出现PUC信号,UCSWRST 位将自动置位,并使USCI复位。
为选择I2C操作模式,UCMODEx必须设置成11。
当完成模块初始化后,即可进行数据的发送或接收。
清除UCSWRST可以释放USCI,使其进入操作状态。
为避免不可预测行为的出现,当UCSWRST置位时应该对USCI进行配置或者重新配置。
在I2C 状态下设置UCSWRST有以下影响:I2C通信停止SDA 和SCL处于高阻态UCBxI2CSTAT的第0~6位清零UCTXIE和UCRXIE被清零UCTXIFG和UCRXIFG被清零其他位和寄存器保持不变注意:初始化或者重新配置USCI模块USCI模块初始化或者重新配置推荐步骤:1、设置UCSWRST(BIS.B #UCSWRST,&UCxCTL1)2、在UCSWRST=1时初始化所有USCI寄存器(包括UCxCTL1)3、配置端口4、软件清除UCSWRST位(BIC.B #UCSWRST,&UCxCTL1)5、通过设置UCxTXIE和UCxRXIE或二者之一来使能中断17.3.2 I2C的串行数据每传输一个数据位主设备都会产生一个时钟脉冲。
I2C模式下进行的是字节操作。
数据传输过程中最重要的起始位如图17-3所示。
每个起始位发出之后的第一个字节包含有7位从地址和一个R/W位。
当R/W=0时,主设备向从设备发送数据;=1时,主设备从从设备接收数据。
应答位ACK是接收方对应第九个SCL时钟发出的握手信号。
START起始条件和STOP停止条件都是由主设备产生,其时序如图17-3所示。
在SCL为高时将SDA由高跳变至低产生一个START起始条件。
在SCL为高时将SDA由低跳变至高产生一个STOP 停止条件。
总线忙位UCBBUSY在START出现后置位,在STOP出现后清零。
Page 4 of 24Page 5 of 24SCL 为高电平期间SDA 上的数据必须保持稳定,其时序如图17-4所示。
SDA 的高低状态只能在SCL 为低时可调,否则将会产生起始和停止条件。
17.3.3 I2C 寻址方式I2C 模式下支持7位和10位寻址方式。
7位寻址7位寻址的格式如图17-5所示,第一个字节包括7位从地址和一个R/W 读写控制位。
应答位ACK 是接收方在每个字节后发出的握手信号。
10位寻址10位寻址的格式见图17-6,第一个字节由11110b 加上10位从地址的高两位和R/W 位构成。
每个字节结束后由接收方发送ACK 应答信号。
下一个字节是10位从地址剩下的8位数据,在这之后是ACK 应答信号和8位数据。
再次起始条件主设备可以在不停止当前传输状态的情况下,通过再次发送一个起始位来改变SDA 上数据流的传输方向。
这被称为再次起始。
再次起始位产生后,从设备的地址和标示数据流方向的R/W 位需要重新Page 6 of 24 发送。
再次起始条件格式如图17-7所示。
17.3.4 I2C 模式下的操作方式在I2C 模式下USCI 模块可以工作在主发送模式,主接收模式,从发送模式,或者从接收模式。
接下来的几部分将会对这些模式进行讨论,并用时序来对这些模式进行阐明。
图17-8给出了在时序说明中会出现的一些图例。
主设备发送的数据用灰色的矩形块表示,而从设备发送的数据则用白色的矩形块表示。
USCI 模块传输的数据,和主模式或从模式一样用相应的图例表示,只不过其使用的矩形块要高一点。
USCI 模块的行为用带有指示数据流中行为发生地方的箭头的灰色矩形块表示。
必须用软件来处理的行为则用带有指向数据流中行为必定发生的地方的箭头的白色矩形块表示。
从设备模式选择 I2C 模式的同时设置UCMODEx=11,USCYNC=1,并清零UCMST 位可以使USCI 模块工作在I2C 从模式。
首先,必须清零UCTR 位使USCI 工作在接收模式下才能接收到I2C 的地址。
然后,数据的发送和接收操作就可以根据从地址和一起传输的R/W 位来自动进行。
USCI 从地址是对寄存器UCBxI2COA 进行编程得到。
当UCA10=0,选用7位寻址方式。
当UCA10=1,选用10位寻址方式。
若要响应广播可以置位UCGCEN 位。
当在总线上检测到起始信号时,USCI 模块将会接收到传送过来的地址,并将之与存储在UCBxI2C0A 中存储的本地址相比较。
若两者相匹配,则置位UCSTTIFG 位。
I2C 从设备发送模式当主机发送的从地址和其本地地址相匹配并且R/W 为1时从设备进入发送模式。
从设备根据主设Page 7 of 24备产生的时钟脉冲信号在SDA 上发送串行数据。
从设备不能产生时钟脉冲,但是当一个字节发送完需要CPU 的干预时从设备可以拉低SCL 。
如果主设备向从设备请求数据则USCI 模块将会被自动配置为发送模式并置位UCTR 和UCTXIFG 。
SCL 直到第一个数据被写入发送缓冲区UCBxTXBUF 之前会一直保持被拉低状态。
当地址被响应后,清除UCSTTIFG 标志,然后开始数据传输。
一旦数据被转移到移位寄存器之后UCTXIFG 将再次被置位。
当一个数据被主设备接收响应之后,之前被写入UCBxTXBUF 中的下一个数据开始传输,若此时缓冲区为空,则SCL 会一直保持低电平来延迟总线的应答周期来等待新的数据被写进UCBxTXBUF 。
图17-9给出了I2C 从设备发送模式的图解。
I2C 从设备接收模式当主机发送的从地址和其本地地址相匹配并且R/W 为0时从设备进入接收模式。
从设备接收模式下,从设备根据主设备产生的时钟脉冲信号在SDA 上接收串行数据。
从设备不能产生时钟脉冲,但是当一个字节接收完需要CPU的干预时从设备可以拉低SCL。
如果从设备需要从主机接收数据则USCI模块将会被自动配置为接收模式并清除UCTR位。
在接收完第一个数据字节后接收中断标志位UCRXIFG置位。
USCI模块会自动应答接收到的数据并开始接收下一个数据字节。
如果已经接收到的数据在数据接收结束时还没有从接收缓冲区UCBxRXBUF中读走,SCL会一直处于拉低状态进行总线延时。
一旦UCBxRXBUF接收到的新数据被读走,从设备会发送一个应答信号给主设,然后开始下个数据的接收。
在下一个应答周期中置位UCTXNACK会产生一个NACK发送给主设备,即使是还没有准备好接收新的数据。
如果在SCL为低时置位UCTXNACK将会释放总线,并马上发送一个NACK信号给主设,同时UCBxRXBUF将加载最后一次接收到的数据。
由于先前的数据还没有被读出,这将造成数据丢失。
所以为避免数据的丢失应在UCTXNACK置位之前读出UCBxRXBUF中的数据。
当主设备产生一个STOP停止条件时UCSTPIFG被置位。
如果主设备产生一个重复开始条件时,USCI的I2C状态机将返回地址接收状态。
Page 8 of 24图17-10给出了I2C从设备接收模式的图解。
I2C从接收模式下的10位寻址方式如图17-11所示当UCA10=1时选用10位寻址模式。
在10位寻址模式下,整个地址接收完毕后从设备处于接收模式。
此时,USCI模块将会在清零UCTR位的同时置位UCSTTIFG来标示当前状态。
若需要将从设备转换到发送模式则需要主机在发送一个重复起始条件后紧跟着发送一个字节地址并置位R/W。
若标志位UCSTTIFG之前被软件清除那么此时将会被置位,同时通过UCTR=1使USCI模块转换成发送模式。