2377 views|1 replies

6366

Posts

4929

Resources
The OP
 

Summary of MSP430 MCU Development [Copy link]

This post was last edited by tiankai001 on 2018-12-30 12:54

1. #i nclude<> means to be in the editor setting directory, #i nclude"" means to be in the current project directory.

2. To call a function in another file, put the function file in the current project directory and add this file to the project.

3. There cannot be a - in the name, for example: byq-ee will be considered wrong, use an underscore.

4. When simulating with IAR software, you can add variables. If you need to view I/O information, just add PXIN and PXOUT.

5. When IAR processes characters, please note that it is the end mark of character processing, which is different from other editing software. For example, we often use character processing to automatically add it at the end, but IAR does not add it, so we should pay special attention to it.

6. If only the low-speed clock of LFX1 is used and 9600bit/s is transmitted, there will be problems with reception because the error is too large. It can be set to below 4800.

7. When writing FLASH, please note that its operating frequency is between 257K~476k. If it is not, an error will occur. And FLASH can only be written to 0, so there is a mode that must be erased before writing.

8. When the IO port is used as input, add resistance according to the normal state. When it is usually high, add a pull-up resistor. When it is usually low, add a pull-down resistor to increase stability.

9. Be sure to turn off external interrupts when writing to FLASH.

10.MSP430 generally does not require RC reset. Generally, just connect a 100K resistor or so. If you need to add a capacitor, its size should be selected according to the following two standards:

247)]The program will not fail to download

The program will be able to reset stably when powered on

247)]11. When using & expression as a judgment, don't forget to add brackets.

12. Don't use nested interrupts. At the same time, in order to use C language to write high-quality code for MSP430, it is necessary to pay attention to the fact that microprocessors are generally used in specific environments and for specific purposes. Considering cost, power consumption and volume, it is generally required to save resources as much as possible. In addition, since microprocessor hardware generally does not support operations on signed numbers and floating-point numbers, and the operation bits are limited, it is necessary to be careful when allocating variables. In addition, it should be noted that speed and memory consumption are often two goals that cannot be taken into account at the same time. In most cases, programmers must make trade-offs and choices based on actual conditions. The following points should be noted:

1) Under the premise of meeting the calculation requirements, try to choose a data type with fewer bytes defined for the variable. For example, the most commonly used int and char, int is 16 bits, char is 8 bits, if it is not necessary, do not use int, and it is best to use unsigned char when using char. During runtime, you can see in the variable window that variables using the unsigned char type are in hexadecimal format, while those using int are in decimal format. If char is not defined as unsigned, a minus sign will appear, and if it is not necessary, negative numbers are not required in 430.

2) Try not to use data types that are too long, such as long, long long, and double

3) The C compiler of MSP430 does not support bit addressing, so try to reduce bit operations in calculations. For variables that only have "yes" and "no", if the RAM capacity allows, they can be allocated as unsigned char type to increase the calculation speed. If it is allocated as a bit of a byte, the memory consumption can be reduced, but the calculation speed will be reduced.

4) Avoid using floating-point numbers and try to use fixed-point numbers for decimal operations. If you must use floating point numbers, try to use 32-bit float instead of 64-bit double.

5) Try to assign variables to unsigned data types.

247)]

6) For pointer variables, if their values will not change after declaration, declare them as const types so that the compiler can better optimize the generated code when compiling.

7) Use local variables instead of global variables or static variables (static) as much as possible. This will help the compiler to better optimize the generated code when compiling.

8) Avoid using the & operator to take the address of local variables. , 0)] 9) Declaring variables that are only used within a module as static is helpful for optimizing code. 247)]

10) If stack space is limited, minimize the number of function call levels and recursive calls.

247)]11) If there are too many parameters to be transmitted, the parameters can be grouped into an array or structure and then passed with a pointer

12) Some variables are used in both interrupt programs and normal level programs, so they must be protected. Declare the variable as volatile type so that the compiler will not move it during optimization and access to it will not be delayed. To ensure that volatile variables are not interrupted, you can add the __moniter declaration in front of the part that accesses it (that is, the function that accesses it).

left]11) If there are too many parameters to be passed, the parameters can be grouped into an array or structure and then passed with a pointer.

12) Some variables will be used in both interrupt programs and normal-level programs, so they must be protected. Declare the variable as volatile type, and the compiler will not move it during optimization, and access to it will not be delayed. To ensure that the volatile variable is not interrupted, you can add the __moniter declaration in front of the part that accesses it (that is, the function that accesses it).

left]11) If there are too many parameters to be passed, the parameters can be grouped into an array or structure and then passed with a pointer.

12) Some variables will be used in both interrupt programs and normal-level programs, so they must be protected. Declare the variable as volatile type, and the compiler will not move it during optimization, and access to it will not be delayed. To ensure that the volatile variable is not interrupted, you can add the __moniter declaration in front of the part that accesses it (that is, the function that accesses it).


This post is from Microcontroller MCU

Latest reply

Simple and clear, good  Details Published on 2019-1-2 09:25
 

2618

Posts

0

Resources
2
 
Simple and clear, good
This post is from Microcontroller MCU
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list