MSP430 development entry basic C language programming start

There are many books explaining 430, but most of them are detailed explanations of the underlying hardware structure. They are inevitably hollow and boring. I think understanding the operation of an MCU must first understand its basic characteristics, and then study it carefully. The function of each module.

1. First you need to know the memory structure of the msp430. There are two types of typical microprocessors: Feng. Neumann architecture - program memory and data memory unified coding; Harvard architecture - program memory and data memory; msp430 series microcontroller belongs to the former, while the commonly used mcs51 series belongs to the latter.

0-0xf special function register; 0x10-0x1ff peripheral module register; 0x200-? According to the different model address extended from low to high; 0x1000-0x107f seg_b0x1080_0x10ff seg_a for the remaining information stored in the flash from 0xffff down, depending on the capacity, for example, 149 is 60KB, 0xffff-0x1100

2. The reset signal is the starting point of the MCU operation. There are two kinds of reset signals of 430: the power-on reset signal POR and the power-on clear signal PUC. The POR signal is only set to the reset function on the power-up and RST/NMI reset pins, and the system is reset when it is low. The PUC signal is generated by the POR signal, and other errors such as watchdog timeout overflow, security key values ​​are generated. However, regardless of the kind of signal triggered reset, msp430 will be read at the address 0xffff reset interrupt vector, and then the program starts execution from the address pointed to by the interrupt vector. The state after resetting is not written. See the reference book for details.

MSP430 development basics C language programming start

3. The system clock is the commander of a program run. Timing and interrupts are also the core and central axis of the program. 430 up to three oscillators, DCO internal oscillator; LFXT1 external low-frequency oscillator, common 32768HZ, no external load capacitance; can also be connected to high frequency 450KHZ-8M, need to load capacitors; XT2 then high frequency 450KHZ-8M, plus External capacitor. (Experience found that when connecting to XT2, you need to pay attention to yourself to turn on XT2, and delay 50us waiting XT2 start-up, and then manually remove OFIFG bits in IFG1, the operation sequence is: open XT2-"waiting for XT2 stable-"switch system clock For XT2)

430 has three kinds of clock signals: MCLK system master clock, can be divided by 1 2 4 8 for cpu use, other peripheral modules can also be used under selective conditions; SMCLK system subclock for peripheral modules, optional different oscillation The clock signal generated by the device; ACLK auxiliary clock, can only be generated by the LFXT1, for peripheral modules.

4. Interruption is a major feature of the 430 processor, because almost every peripheral module can be generated, 430 can enter a low-power state when there is no task, an interrupt will wake up the CPU when there is an event, and it will enter the low-power state again after processing.

The entire interrupt response process is this, when there is an interrupt request, if the cpu is active, the current command is completed first; if it is at low power, exit first, push the pc value of the next instruction into the stack; if there are multiple Interrupt request, the first response to the high priority; After the execution, waiting for the interrupt request flag reset, it should be noted that the single interrupt source interrupt request flag bit automatically reset, and the flag of multiple interrupts need a software reset; then the total system interrupt allows The bit SR.GIE is reset and the corresponding interrupt vector value is loaded into pc, and the program continues execution from this address.

It should be noted here that the interrupt enable bit SR.GIE and the interrupt nesting problem. If you wish to respond to a higher level interrupt request while you are executing an interrupt routine, you must set SR.GIE to the first interrupt.

In fact, other peripheral module clocks are executed along the clock and interrupt this core. I don't have a specific structure, you can refer to the 430 series manuals.

C language programming start

Because the commonly used 430 programming development is c language, the following explains the overall structure of C programming language 430. Basically belongs to the framework structure, that is, the overall modular programming, in fact, this is the basic principle of hardware programming (not the rules I oh).

The first is the program header file, including #include MSP430x14x.h. This is the 14 series, because it is commonly used 149; other models can be modified. Can also include # include "data.h" and other database header files, or function variable declaration header files, are defined by you.

Next is the declaration of functions and variables void Init_Sys(void), ie system initialization. The system initialization is a whole concept. In a broad sense, it includes the initialization of all peripheral modules. You can write the subfunctions of the peripheral module initialization to Init_Sys(), or write the initialization of each module separately. However, the structure is concise. It is better to initialize the clock after initialization of the system. Other modules (including some interrupt initialization) are also initialized here.

Void Init_Sys()

{

Unsigned int i;

BCSCTL1&=~XT2OFF; //Open XT2 oscillator

Do

{

IFG1 &= ~OFIFG; // Clear oscillator failure flag

For (i = 0xFF; i ” 0; i--); // Delay, wait for XT2 to start

}

While ((IFG1 & OFIFG) != 0); // Determine if XT2 starts to vibrate

BCSCTL2 =SELM_2+SELS; //select MCLK, SMCLK to XT2

/ / The following initialization of various modules, interrupts, peripherals, etc.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

_EINT (); //Open global interrupt control

}

Here refers to the clock problem, usually we choose XT2 8M crystal oscillator, which is the system master clock MCLK is 8M, cpu execution command this clock prevail; but other peripheral modules can select other clocks in the corresponding control register, ACLK; When you have a low speed requirement and a large time interval, you can select ACLK, for example, in the timer TImea initialization.

Main program:

Void main( void )

{

WDTCTL = WDTPW + WDTHOLD ;// Turn off watchdog

InitSys(); // Initialize

// Other function functions in your own task

. . . . . . . . . . . . . . . . . . . . .

While(1);

}

After the main program, I would like to talk about the interrupt function. The interrupt is an indispensable part of your MCU task. It can also be said to be the soul (exaggeration).

/************************************************* **********************

Each interrupt function can be written in order of priority

************************************************** *********************/

Give a timed interruption example:

//initialization

Void Init_TImer_A(void)

{

TACTL = TASSEL0 + TACLR; // ACLK, clear TAR

CCTL0 = CCIE; // CCR0 interrupt enable

CCR0=32768; //time 1s

TACTL|=MC0; // up counting mode

}

// Interrupt service

#pragma vector="TIMERA0"_VECTOR

__interrupt void TImerA0()

{

// Your own request to interrupt the task

}

Of course, there are other timings and multiple interrupts, and the number of interrupt vectors for each series of chips is also different.

After learning and being able to gain knowledge, it is recommended to look at the application principles of msp430 common modules on the Microcontrol Forum.

Headphones

We've been around for over 16+ years. We make sure our sound is The Best Sound.
Our products include gaming headset, Bluetooth Earphone, Headphones Noise Cancelling, Best Wireless Earbuds, Bluetooth Mask, Headphones For Sleeping, Headphones in Headband, Bluetooth Beanie Hat, bluetooth for motorcycle helmet, etc
Manufacturing high-quality products for customers according to international standards, such as CE ROHS FCC REACH UL SGS BQB etc.
We help 200+ customers create custom Bluetooth headphones, earbuds, earphones, etc audio products design for various industries.

Customized Headphones, personalized gifts, promotional products custom , Bluetooth Earphones,Best Headphones

TOPNOTCH INTERNATIONAL GROUP LIMITED , https://www.mic11.com

This entry was posted in on