This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] CCS/MSP430G2553:中断事件正在中断我的 ADC 读数

Guru**** 2582405 points


请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/607484/ccs-msp430g2553-interrupt-event-is-interrupting-my-adc-reading

器件型号:MSP430G2553

工具/软件:Code Composer Studio

您好!

我有一个将键盘(4x4)和外部 ADC 组合在一起的程序。

当我按下某个键时、会触发中断以查看按下哪个键、这很好。

当我运行该程序而不按任何键时、ADC 会显示我需要的内容。

但是、当我按下任何键(曲折触发中断)时。 ADC 显示0 (错误值)、并且即使在中断结束时也保持这种状态

如何使中断不破坏我的 ADC 读取?

谢谢你

更新:

我要添加一个更轻的代码样本、ADC 可以正常工作、但当我触发中断时、ADC 不显示值

主要内容如下:

#include 
#include "includes/DCL.h"
#include "includes/ADC_HX711.h"
#include "include/Keypad.h"

/*
main.c
*/
void main (void){
WDTCTL = WDTPW | WDTHOLD;//停止看门狗计时器
DCOCTL = 0;//选择最低 DCOx 和 MODx 设置<
BCSCTL1 = CALBC1_1MHz;//设置 DCO
DCOCTL = CALDCO_1MHz;
InitADC();
InitKeypad();

_bis_SR_register (GIE);

while (1)
{
WT_ZERO =(long) bitbang_data_in ();
}

}

#pragma vector=Port1_vector
__interrupt void port_1 (void)
{
key = ScanKey ();
SetOutputLow ();
ClearFlags ();

} 

这是 ADC 部件:

inline void InitADC()









~clock_out_port &=~clock_out_PIN;clock_out_DIR |= clock_out_PIN;__delay_out_cycles (6000);}inline void ReenableClock (){ clock_out_port |= clock_out_PIN;clock_out_port &= clock_out_pin;
{= nsigned





I chat_out_bytes;{= nat_1&I byte_dateout_out_out_date();{= unsigned



I char <= nat_out_out_out_dateout_out_out_date();
if (IsReady ())
data |= 0x01;
clock_out_port 和=~clock_out_PIN;

}

返回数据;
}

long bitbang_data_in()
{
//unsigned char data[3]、I;
long data;

while (IsReady ());
__delay_cycles (1);

data =(long)(((long)(<=GetByte2*0);GetByte2<=GetByte[e2]<|/GetByte0]<=e2]<=e2]<=eData<|/GetByte*(<)|[e&GetByte&GetByte&=1)<=(<)<=e&GetByte&GetByte&GetByte*(<)<)<=(<)<=







返回数据;//(long)(((long) data[2]<< 16)|((long) data[1]<< 8)|((long) data[0]<< 0);
}

内联 int IsReady ()
{
return data_in_PIN & data_in_port;
} 

和键盘部件:

unsigned char matrix [LEN][LEN]={'1'、'2'、'3'、'N'、
'4'、'5'、'6'、'T'、
'7'、'8'、'9'、'Z'、
'C'、'0'、'F'};

inline Initpin +
pin (+ out_pin_pin +)+ pin_pin +(in_pin_pin_pin_pin_pin_pin_pin_pin_pin_pin_pin_pin_pin_pin_pin_pin_pin+


~ //输入方向 p1.3、p1.4、p1.5、p1.7
P1REN |=(PIN_IN_1 + PIN_IN_2 + PIN_IN_2
+ PIN_IN_4);//使能电阻器 p1.3、p1.4、p1.5、p1.7 P1OUT |=(PIN_IN_1 + PIN_IN_2 + PIN_IN_IN_4 + PIN_IN_IN_IN_IN_4);PIN_IN_IN_IN_IN_IN_IN_IN_IN_IN_4 + PIN_IN_IN_IN_IN_IN_IN_IN_4 + PIN_IN_IN_IN_IN_IN_IN_IN_IN_IN_IN_IN_4 + PIN_IN_IN_IN_IN_IN_IN_IN_IN_IN_IN_IN_IN_IN_IN_IN_4

//启用 interupt


ClearFlags ();
}

unsigned char ScanKey ()
{
unsigned char row_SEL=0;
unsigned char Keyrow=0;
unsigned char i=0;
unsigned char j=0;

//DIR_OUT_PORT &=~(PIN_OUT_5 + PIN_OUT_6 + PIN_OUT_7 + PIN_OUT_8);/DIR_OUT
I = 0
;
= 0 (针对每个


条件 I = 0);= 0 + LE0+ IN_OUT = 0+(IN_OUT = 0)
dir_out_port |= PIN_out_5;//输出 p2.0为高
中断;
情形1:
dir_out_port |= PIN_out_6;//输出 p2.1为高
中断;
情形2:
dir_out_port |= PIN_out_7;//输出 p2.2为高
中断;
情形3:
dir_out_port |= PIN_out_8;

//输出为高中断。}


if ((IN_PORT & PIN_IN_1)=0)//找到按下的按钮行
ROW_SEL|=0x08;
if (IN_PORT & PIN_IN_2)=0)
ROW_SEL|=0x04;
if (IN_PORT & PIN_IN_3)=0)
ROW_SEL|=0x02;
if (IN_TRU=0=0=0=0



;IN_IN_PIN_EN=0=0;IN_IN_IN_ENTRU=0=0=0=0=0;IN_PIN_IN_IN_IN_IN_IN_IN_ENTRU=0=0=0=0=0=0=0= j++)
{
if ((ROW_SEL 和 keyrow))
{
return matrix [i][j];
}

keyrow = keyrow >> 1;
}
switch (i)
{
case 0:
dir_out_port &=~PIN_out_5;//输出 p2.0为高
中断;
case 1:
dir_out_port &=~


~PIN_out_port;p2.2为高中断/输出 pout_2;pout_out_pout;case://输出 pout_out_out_out_2:pout 为高中断/p2.2;pout_out_out_out_out_out_out2;out_out_out_out

案例3:
dir_out_port &&~PIN_out_8;//输出 p2.3为高
中断;
}
ROW_SEL=0;

}
返回 NONEKEY;
}

内联 int IsKeyPressed()
{
return (P1IFG & IN_PORT);
}

void ClearFlags ()
{
P1IFG = 0;//清除 Port1 IFG =
0;



}Vout_out_p2_out_pin
(+p2_out_out_out_pin) //输出方向 p2.0、p2.1、p2.2、p2.3
out_port = 0;//将输出设置为低
电平} 

dcl.h 只是参数。

谢谢你

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    您好!

    一个建议是在读取 ADC 时禁用中断。

    BR、
  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    Joe、您好!

    问题是否已解决?

    此致、
  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    我认为查看 DIR_OUT_PORT、DIR_IN_PORT、DATA_IN_PIN 等的定义也会有所帮助、以便我们知道它们如何映射到实际的 GPIO 寄存器。