MSP430 programming development considerations and requirements[Copy link]
The following are some summaries in using MSP430: 1. System clock problem: The system uses DCO by default. When using external high-speed crystal oscillator XT2, you must turn on XT2 yourself, delay 50us to wait for XT2 to start oscillating, and then manually clear the OFIFG bit in IFG1!!!! Be sure to pay attention to the operation sequence: turn on XT2-> wait for XT2 to stabilize-> switch the system clock to XT2. If the latter two steps are reversed, there will be no problem under normal circumstances, but in the case of unstable voltage and frequent MCU reset, it is very easy to cause the MCU to die, and it can only be reliably reset after powering off and then powering on again. 2. In the early version of IAR development environment, the DDF file of the corresponding device must be selected in Project->Option->C-Spy, otherwise there will be no SFR window during debugging. 3. During Flash writing, be sure to turn off interrupts, and the CPU cannot execute the program at this time. 4. When debugging, do not select "Release JTAG on Go" 5. When debugging, you need to turn off the watchdog, otherwise when the watchdog is turned on, every time the breakpoint is executed, the program will jump to the entry point and execute from the beginning. Or, when the program is paused or stopped at a breakpoint, when it needs to continue running, the program will no longer execute, but "synchronous JTAG" must be used to continue running (run from the beginning?) 6. IAR EWB identifiers are case-sensitive 7. There are alignment requirements inside the structure variables, which are usually aligned at 2-byte positions. P93 of the "C/EC++ Compiler Reference Guide" has the following example: struct { short s; /* stored in byte 0 and 1 */ char c; /* stored in byte 2 */ long l; /* stored in byte 4, 5, 6, and 7 */ char c2; /* stored in byte 8 */ } s; sizeof(s) is 10, not 8. You can use #pragma pack to change this alignment, but it will result in the structure being accessible only in byte mode 8. MSP430 IAR C/EC++ Compiler supports two runtime libraries 1. IAR CLIB: It is mainly used for 8-bit or 16-bit processors. It is not fully compatible with ISO/ANSI C, nor does it fully support IEEE 754 floating point numbers, and does not support Embedded C++. 2. IAR CLIB: Supports ISO/ANSI C and Embedded C++. 9. Customization of cstartup (1). Add code in __low_level_init(). This function can be used to initialize I/O registers and determine whether the data segment is initialized in cstartup. The file 430\src\lib\lowinit.c provides a framework. Copy it to the project directory for use. The file contains certain instructions for use. (2) If the code added in __low_level_init() does not meet the requirements, copy 430\src\lib\cstartup.s43 to your own working directory and modify the required code; then add the file to the project and select Ignore CSTARTUP in library on the include page of XLINK in the project selection. 10. Use #include "io430x14x.h" and #include "in430.h" instead of #include
You can use the defined bit variables. You can use the following method to define bit variables, but the compiler will eventually convert them to byte operations: struct { unsigned char WDTIE : 1; unsigned char OFIE : 1; unsigned char : 2; unsigned char NMIIE : 1; unsigned char ACCVIE : 1; unsigned char URXIE0 : 1; unsigned char UTXIE0 : 1; } IE1_bit; It is not recommended to use bitfields, as they are very inefficient. 11. The index value of an array is most efficient when using int type, and char type is slightly less efficient. Array type: char type array is the most efficient. When indexing other types of arrays, multiplication is used.