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

MSP-EXP430F5529LP与的PC通信问题

我的目标是向电脑发送AD转换后的数据,但是我的 UCA1TXBUF里始终没有数值,我是根据MSPWare里的示例进行的修改,代码如下:

#include <msp430.h>

/*
 * main.c
 */
 													//AD转换结果
//volatile float v;
int adc12()
{
//	int n; 													//AD转换结果
	P6SEL |= 0x01;				// Enable A/D channel A0
	ADC12CTL0 = ADC12ON+ADC12SHT0_8+ADC12MSC;				// Turn on ADC12, set sampling time 256ADC12CLK cycles(ADC12CLK=5MHZ)
															// set multiple sample conversion
	ADC12CTL1 = ADC12SHP+ADC12CONSEQ_2;				// use sampling timer,set repeat-single-channel
	ADC12IE = 0x01;				// Enable ADC12IFG.0
	ADC12CTL0 |= ADC12ENC;				// Enable conversions
	ADC12CTL0 |= ADC12SC;				// Start conversion

	__bis_SR_register(LPM0_bits);				// Enter LPM4, Enable interrupts
	__no_operation();				// For debugger
//	return ADC12MEM0;

}
int uscia1_uart()//UART串口通信
{
	P4DIR |= (1<<4)+(1<<5);
	P4SEL |= (1<<4)+(1<<5);// P4.4,5 = USCI_A1 TXD/RXD
//	UCA1CTL1 |= UCSWRST;// **Put state machine in reset**
	UCA1CTL1 |= UCSSEL_1;// CLK = ACLK=32768HZ
	UCA1BR0 = 0x03;// 32kHz/9600=3.41 
	UCA1BR1 = 0x00;//
	UCA1MCTL = UCBRS_3+UCBRF_0;// Modulation UCBRSx=3, UCBRFx=0
	UCA1CTL1 &= ~UCSWRST;// **Initialize USCI state machine**
	UCA1IE |= UCRXIE+UCTXIE;// Enable USCI_A1 RX interrupt
	__bis_SR_register(LPM0_bits + GIE);// Enter LPM3, interrupts enabled
//	__no_operation();// For debugger

}
int main(void) {WDTCTL = WDTPW | WDTHOLD;	// Stop watchdog timer
	adc12();
	uscia1_uart();
	__bis_SR_register(LPM4_bits+GIE);//// Enter LPM4, Enable interrupts
	return 0;
}


#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=USCI_A1_VECTOR
__interrupt void USCI_A1_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(USCI_A1_VECTOR))) USCI_A1_ISR (void)
#else
#error Compiler not supported!
#endif
{while (!(UCA1IFG&UCTXIFG));// USCI_A0 TX buffer ready?UCA1TXBUF=((long)ADC12MEM0)*(0x21)/(0xFFF);// TX -> RXed character
}

请问有什么地方不对吗?

Maka Luo:

定位一下问题先,是ADC没有采样到数据,还是UART通信不正常。谢谢!

灰小子:

建议尽量分模块单独调试,调试通了再整合在一块调试

赞(0)
未经允许不得转载:TI中文支持网 » MSP-EXP430F5529LP与的PC通信问题
分享到: 更多 (0)