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环境用MSP430F5529通过串口显示ADC采样

Other Parts Discussed in Thread: MSP430F5529

    按照TI官网adc还有uart这两个模块的例程,我可以在MSP430F5529正常运行。使用单通道ADC采集,采集的值放在ADC12MEM0中,我设置了变量data,data=ADC12MEM0,然后在uart的中断语句中写UCTXIFG=data。我的串口的波特率设置的也是对的,只使用串口程序是可以正常运行的。但是我电脑的串口助手显示什么都接收不到,这是为什么呢?

  • 你用错寄存器了。

    UCTXIFG是标识位,不是发送缓存寄存器。

  • 我在帖子上表述错了,是UCA0TXBUF=data,我在下一条评论里写了我的程序,麻烦您帮忙检查一下。
  • 这是我用MSP430F5529写的通过串口显示ADC采样的程序。单独运行ADC中断的时候,led是可以正常根据ADC采样来亮灭的,但是现在和串口合起来,我的ADC不管采集来什么值,led灯都会亮。

    #include <msp430.h>

    unsigned int data;
    //volatile float adc_val;


    int main(void) {
    WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer

    P6SEL |= 0x01; // P6.0 ADC option select
    P1DIR |= BIT0; // P1.0 output
    ADC12CTL0 = ADC12SHT02 + ADC12ON; // Sampling time, ADC12 on
    ADC12CTL1 = ADC12SHP; // Use sampling timer
    ADC12IE = 0x01; // Enable interrupt
    ADC12CTL0 |= ADC12ENC; //使能转换
    // ADC12MCTL0=ADC12SREF_2; //外部参考电压3.3V
    // TA0CCTL0 = CCIE; //CCR0中断允许
    // TA0CTL = TASSEL_2 + MC_1 + TACLR; //SMCLK,增计数,清除TAR计数器
    // TA0CCR2 = 256;

    while(1)
    {
    ADC12CTL0 |= ADC12SC; // 开启AD转换
    __bis_SR_register(LPM0_bits + GIE); // LPM0, ADC12_ISR will force exit
    __no_operation(); // For debugger
    }


    P3SEL |= BIT3+BIT4; // P3.3,4 = USCI_A0 TXD/RXD
    UCA0CTL1 |= UCSWRST; // **Put state machine in reset**
    UCA0CTL1 |= UCSSEL_1; // CLK = ACLK
    UCA0BR0 = 0x03; // 32kHz/9600=3.41 (see User's Guide)
    UCA0BR1 = 0x00; //
    UCA0MCTL = UCBRS_3+UCBRF_0; // Modulation UCBRSx=3, UCBRFx=0
    UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
    UCA0IE |= UCRXIE; // Enable USCI_A0 RX interrupt
    __bis_SR_register(LPM3_bits + GIE); // Enter LPM3, interrupts enabled
    __no_operation(); // For debugger
    }

    #pragma vector = ADC12_VECTOR
    __interrupt void ADC12_ISR(void)
    {
    switch(__even_in_range(ADC12IV,34))
    {
    case 0: break; // Vector 0: No interrupt
    case 2: break; // Vector 2: ADC overflow
    case 4: break; // Vector 4: ADC timing overflow
    case 6: // Vector 6: ADC12IFG0
    data = ADC12MEM0;
    if (ADC12MEM0 >= 0x7ff) // ADC12MEM = A0 > 0.5AVcc?
    P1OUT |= BIT0; // P1.0 = 1
    else
    P1OUT &= ~BIT0; // P1.0 = 0
    __bic_SR_register_on_exit(LPM0_bits); // Exit active CPU
    case 8: break; // Vector 8: ADC12IFG1
    case 10: break; // Vector 10: ADC12IFG2
    case 12: break; // Vector 12: ADC12IFG3
    case 14: break; // Vector 14: ADC12IFG4
    case 16: break; // Vector 16: ADC12IFG5
    case 18: break; // Vector 18: ADC12IFG6
    case 20: break; // Vector 20: ADC12IFG7
    case 22: break; // Vector 22: ADC12IFG8
    case 24: break; // Vector 24: ADC12IFG9
    case 26: break; // Vector 26: ADC12IFG10
    case 28: break; // Vector 28: ADC12IFG11
    case 30: break; // Vector 30: ADC12IFG12
    case 32: break; // Vector 32: ADC12IFG13
    case 34: break; // Vector 34: ADC12IFG14
    default: break;
    }
    }

    #pragma vector=USCI_A0_VECTOR
    __interrupt void USCI_A0_ISR(void)
    {
    switch(__even_in_range(UCA0IV,4))
    {
    case 0:break; // Vector 0 - no interrupt
    case 2: // Vector 2 - RXIFG
    while (!(UCA0IFG&UCTXIFG)); // USCI_A0 TX buffer ready?
    UCA0TXBUF = data; // 串口发送低八位
    while (!(UCA0IFG&UCTXIFG)); //等待数据发送完成,UCTXIFG置1跳出循环
    data = (data>>8); //穿口先转低八位,所以右移8位发送高八位
    UCA0TXBUF = data; //发送高八位
    break;
    case 4:break; // Vector 4 - TXIFG
    default: break;
    }
    }
  • 你的程序有问题啊,进入while(1)之后,就出不来了,后面的配置串口相关的代码执行不到
  • 我当时也在疑惑,但是在ADC转换结束之后,我不是退出中断了吗?那或者,我现在把while(1)放到最后?
  • 好像就算是ADC放在最后也不能解决这个问题,所以,我要把while(1)关掉?
  • 或者,我把循环关掉,LED灯也是会一直亮着吖。
  • 您可以参考下

    e2echina.ti.com/.../108147
    以及
    blog.csdn.net/.../78747159

    希望对您有所帮助!