TI中文支持网
TI专业的中文技术问题搜集分享网站

msp430g2553,ADC10进入循环后,串口接收中断进不去了

单独的串口程序是好的,ADC10有点问题,想做个p1.4、1.5模拟输入,通道和引脚的设置出来硬件上p1.3也能输入;两个程序和一起时,串口还不能接收了。请大佬指正一下;

#include <msp430.h>
#include "string.h"

void putchar(unsigned char tx_data);
void putstr(char *s);
void Receive(char x);
void result(char *s);

float p11,p12,p13;
unsigned int a[]={0};

char RX_DATA;
char rxcnt=0;
char temp1;
char temp2;
char flag=0;
char *string1="MADE BY PengchengIT\n";
char string2[]="G2553 UART\nREADY!!!\n";
char n_feature[]={0xE5,0x05,0x09,0x58,0x44,0x31,0x30,0x30,0x30,0x31,0xFD,0xE6};
char m_ready[10]={0xE5,0x01,0x00,0x01,0xE6};
char m_start[10]={0xE5,0x06,0x01,0x01,0xE6};
char m_emulate[10]={0xE5,0x1B,0x01,0x02,0x1E,0xE6};
char m_up[10]={0xE5,0x19,0x00,0x19,0xE6};
char m_down[10]={0xE5,0x1A,0x00,0x1A,0xE6};
char m_auto[13]={0xE5,0x1B,0x01,0x01,0x1D,0xE6};
char m_end[11]={0xE5,0x1C,0x00,0x1C,0xE6};
char a_a[10]={0};

int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
if (CALBC1_1MHZ==0xFF) // If calibration constant erased
{ while(1); // do not load, trap CPU!! }
DCOCTL = 0; // Select lowest DCOx and MODx settings
BCSCTL1 = CALBC1_1MHZ; // Set DCO
DCOCTL = CALDCO_1MHZ;
P1SEL = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
P1SEL2 = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
P1DIR = BIT0; //p1.0外接LED为输出状态
P1OUT &= ~BIT0;
UCA0CTL1 |= UCSSEL_2; // SMCLK
UCA0BR0 = 104; // 1MHz 9600
UCA0BR1 = 0; // 1MHz 9600
UCA0MCTL = UCBRS0; // Modulation UCBRSx = 1
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
IE2 |= UCA0RXIE; // Enable USCI_A0 RX interrupt
putstr(string1);
putstr(string2);
__enable_interrupt();
//__bis_SR_register(LPM0_bits+GIE); // Enter LPM0, interrupts enabled
ADC10CTL1 = INCH_5 + CONSEQ_1; // A3/A2/A1, single sequence
ADC10CTL0 = ADC10SHT_2 + MSC + ADC10ON + ADC10IE;
ADC10DTC1 = 0x02; // 3 conversions
ADC10AE0|= BIT5+BIT4; // P1.3,2,1 ADC10 option select
P1DIR |= BIT0+BIT6; // Set P1.0 output
for (;;)
{
ADC10CTL0 &= ~ENC;
while (ADC10CTL1 & ADC10BUSY); // Wait if ADC10 core is active
ADC10SA = (unsigned int)a; // Data buffer start
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
__bis_SR_register(CPUOFF + GIE); // LPM0, ADC10_ISR will force exit
p12=a[1];
p13=a[0];
if (p13 < 0x1FF)
{ P1OUT &= ~0x01; } // Clear P1.0 LED off
else
{ P1OUT |= 0x01; } // Set P1.0 LED on
if (p12 < 0x1FF)
{ P1OUT &= ~BIT6;
} // Clear P1.0 LED off
else
{ P1OUT |= BIT6; } // Set P1.0 LED on
}}

void Receive(char x)
{
temp1=x;
if(temp1==0xE5)
{
flag=1;
rxcnt=0;
}
if(temp1==0xE6)
{
flag=0;
a_a[rxcnt]=0xE6;
char b_b[10]={0};
strncpy(b_b,a_a,rxcnt+1);
// putstr(b_b);
result(b_b);
}
if(flag==1)
{
a_a[rxcnt]=x;
rxcnt++;
}
}

void result(char *s)
{
int a=strcmp(s,m_ready);
int b=strcmp(s,m_end);
int c=strcmp(s,m_up);
int d=strcmp(s,m_down);
int e=strcmp(s,m_start);
int f=strcmp(s,m_emulate);
int g=strcmp(s,m_auto);
if(a==0)
{
putstr(n_feature);
}
if(b==0)
{
putstr("End of the test");
}
if(c==0)
{
putstr("The lights have been turned on");
}
if(d==0)
{
putstr("The lights have been dimmed");
}
if(e==0)
{
putstr("Begin to test\n");
putstr("E51101 A FCS+E6\n…");
}
if(f==0)
{
putstr("Enter simulation mode");
}
if(g==0)
{
putstr("Enter auto mode");
}
}

void putchar(unsigned char tx_data) //发送字符函数
{
while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready? 等待TX buffer为空
UCA0TXBUF = tx_data;// TX -> RXed character? 发送字符c
}

void putstr(char *s)//发送字符串函数
{
IE2 &= ~UCA0RXIE;//发送时先关闭接收中断,不接收
//如果没有发完,就继续循环发送
while((*s)!='\0')
{
putchar(*s);
s++;
}
IE2 |= UCA0RXIE; //发送完了打开接收中断
}

// Echo back RXed character, confirm TX buffer is ready first
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(USCIAB0RX_VECTOR))) USCI0RX_ISR (void)
#else
#error Compiler not supported!
#endif
{
while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready? 等待TX buffer为空
//UCA0TXBUF = UCA0RXBUF; // TX -> RXed character? 发送接收到的数据
RX_DATA=UCA0RXBUF;
Receive(RX_DATA);}

// ADC10 interrupt service routine
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(ADC10_VECTOR))) ADC10_ISR (void)
#else
#error Compiler not supported!
#endif
{
__bic_SR_register_on_exit(CPUOFF); // Clear CPUOFF bit from 0(SR)
}

Susan Yang:

从您发布的内容有些难推断。您能否分享更多详细信息:

请问您使用的是官方的开发板?串口通信的对象是PC还是其他芯片?

我明天去公司拿板子来测试一下

pengcheng wu:

回复 Susan Yang:

漏掉了,哈哈哈,我找到了问题,基本上解决了!

Susan Yang:

回复 pengcheng wu:

非常抱歉,前几天帖子有些多,邮箱里邮件太多,漏掉了您的回复….

赞(0)
未经允许不得转载:TI中文支持网 » msp430g2553,ADC10进入循环后,串口接收中断进不去了
分享到: 更多 (0)