1821 views|0 replies

1668

Posts

0

Resources
The OP
 

MSP430F5529 general I/O port settings [Copy link]

In the first chapter, learn I/O first. I/O operation is the most basic, and these registers must be firmly mastered. The difficulty of MSP430 is that it has a large number of registers that need to be set. Although not every register must be mastered, I/O control registers must be remembered. This is too basic-_'

  You should always have a schematic diagram (PCB diagram) on hand to facilitate line checking and pin configuration.

1. Simple operation (setting) of general I/O

1.1 Introduction to I/O

Features: ① Multiple multiplexing and settings (i.e., whether to input, whether to output, whether to connect a pull-up resistor, whether to connect a pull-down resistor, and whether to accept interrupts);

② In general, both P1 and P2 have interrupt capabilities. Interrupts introduced from the various I/O pins of the P1 and P2 interfaces can be independently enabled and set to be triggered by the rising edge or falling edge. The corresponding interrupt vector tables are P1IV and P2IV, which can only perform word operations, and the PAIV register does not exist at all.

③P1 and P2 can be combined into PA, P3 and P4 can be combined into PB, ... PC, PD. So P1 is 8-bit BCD 0x00, and PA is 16-bit BCD 0x0000. When a word operation is performed to write to the PA port, all 16 bits are written to this port; when a byte operation is used to write to the low byte of the PA port, the high byte remains unchanged;

④Since 430 has many I/O and peripheral circuit connections, bit operations are often used here. If you define BIT0=0X01, BIT1=0X02, BIT3=0X04…BIT7=0X80 in advance (it will be used later, so declare it here first), then when the output of P1.1 and P1.3 is set to 1, you can do this: P1OUT|=(BIT1+BIT3). This is very clear.

⑤ It is better to pull down the unused I/O. In addition, when the length of the read data is less than the maximum length of the port, those unused bits will be regarded as zero.

1.2 Simple I/O Configuration

The configuration of 430 I/O is implemented by software, which is realized through the corresponding configuration register. (When using a certain I/O, you must configure the I/O first, otherwise it is easy to make mistakes)

1.2.1 I/O direction setting register PXDIR

If P1.1 and P1.2 are set to output state, the operation is: P1DIR |= (BIT1+BIT2) is equivalent to PADIR |= (BIT1+BIT2) and is also equivalent to PADIR_L|= (BIT1+BIT2.

    Pull high to set it as output, pull low to set it as input (default).

1.2.2 I/O input setting register PXIN

If the input of P1.1 and P1.2 is set to low level, the operation is: P1IN &=~(BIT1+BIT2).

1.2.3 I/O output setting register PXOUT

    ① When only used for simple output: such as setting P1.1 and P1.2 to output high level, the operation is: P1OUT |= (BIT1+BIT2).

② If the pin is a normal I/O function and is currently set to input direction, and the pull-up/pull-down resistor register is valid, then PXOUT can be used to configure the pull-up and pull-down resistors:

Low level is pull-down resistor;

The high level is the pull-up resistor;

1.2.4 Pull-up/pull-down resistor enable register PXREN

The register is in an invalid state when the level is low.

The register is in a valid state when the level is high;

1.2.5 Output drive capability setting register PXDS

Weak drive can reduce electromagnetic interference EMI, and full drive will increase electromagnetic interference. The default is to weaken the drive.

A low level indicates reduced drive (default);

A high level indicates full-force drive;

1.2.6 Function Selection Register PXSEL

Used to declare that the port is a special function to be applied to the peripheral circuit (does not determine the input and output direction), the default is low level.

Low level indicates normal I/O (default);

A high level indicates that the pin will have a special purpose of connecting to peripheral circuits;

For example, there is a line in the development board initialization function HAL_Board.c:

P5SEL |=(BIT2+BIT3)(=00001100);

This sentence means that P5.2 and P5.3 will have special uses. In fact, these two I/Os are connected to external high-frequency clock crystal oscillators (which must be set to input status later).

In addition, it should be noted that once the PXSEL of an I/O is set high, the pin can no longer be used as an interrupt pin.

Summary, simple program application:

/*Realize LED flashing*/The LED is located under each touch button. Please refer to the schematic diagram for the specific interface.

#include <msp430.h> This header file contains the configuration of each register of 430

void main(void)

{

WDTCTL=WDTPW+WDTHOLD; //Turn off the watchdog

P1DIR|=(BIT0+BIT1+BIT2+BIT3+BIT4+BIT5); //P1.0-P1.5 is output, BITX is defined in msp430.h

P1OUT&=~(BIT0+BIT1+BIT2+BIT3+BIT4+BIT5); //Clear

/*P1SEL=0X00;

  PXDS=0X00;Default*/

int i=0,j=0;

while(1)

{

if(i>5)

i=0;

else

{

switch(i)

{

case 0:P1OUT=0x01;break;

case 1:P1OUT=0x02;break;

case 2:P1OUT=0x04;break;

case 3:P1OUT=0x08;break;

case 4:P1OUT=0x10;break;

case 5:P1OUT=0x20;break;

}

}

i++;

for(j=20000;j>0;j--); //delay

}

}

This post is from Microcontroller MCU
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

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