用UCB0端口做了4线的SPI,DCO倍频至2M,赋给SMCLK,SMCLK用作SPI的时钟源,但是实际量到的SPICLK只有50HZ,还请大家帮忙看一下程序的问题出在哪?谢谢!
#include "msp430f4152.h"
#define uchar unsigned char
#define uint unsigned int
void main( void )
{
uint i;
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
FLL_CTL0 &=~XTS_FLL;
FLL_CTL0 |=XCAP11PF;
/*时钟配置*/
SCFQCTL =SCFQ_2M; //MCLK=64ACLK
FLL_CTL1 &=~SMCLKOFF; //SMCLK使能
do
{
IFG1 &=~OFIFG; //清除中断标志
for(i=0;i<0x47ff;i++);
}while((IFG1&OFIFG));
P6DIR |=BIT3;
P6OUT |=BIT3; //P6.3置高
/****模块初始化****/
_BIC_SR(GIE); //关闭总中断
/*初始化RS232*/
UCA0CTL1 |=UCSWRST; //置位SWRST
UCA0CTL0 &=~UCPEN; //无奇偶校验
UCA0CTL0 &=~UC7BIT; //8位数据
UCA0CTL0 &=~UCSPB; //1位停止位
UCA0CTL0 &=~(UCMODE1+UCMODE0+UCSYNC);//UART模式
UCA0CTL1 |=UCSSEL0; //ACLK作为时钟源
UCA0BR0 =0x03;
UCA0BR1 =0x00;
UCA0MCTL =0x06; //波特率为9600
P6SEL |=BIT5+BIT6; //P6.5,P6.6设置为UART模式
UCA0CTL1 &=~UCSWRST; //清零SWRST
/*初始化SPI*/
P6SEL |=BIT1+BIT2+BIT4; //P6.1,P6.2,P6.4设置为SPI模式
UCB0CTL1 |=UCSWRST;
UCB0CTL0 |=UCMST+UCSYNC+UCCKPH+UCCKPL+UCMSB; //采用同步方式
// UCB0CTL0 |=UCMODE1; //4线SPI,片选低有效
UCB0CTL1 |=UCSSEL_2; //SMCLK做时钟源
UCB0BR0 =0x02;
UCB0BR1 =0x00; //SPI时钟频率为4M(SMCLK)
UCB0CTL1 &=~UCSWRST; //清零SWRST
IE2 |=UCA0RXIE; //使能RS232接收中断
// IE2 |=UCB0RXIE; //使能SPI接收中断
_BIS_SR(GIE); //使能总中断
UCA0TXBUF =0x55;
while((IFG2&UCA0TXIFG)==0);
IFG2 &=~UCA0TXIFG;
//置低P6.3,SPI片选端
P6OUT &=~BIT3;
for(i=50;i>0;i--);
UCB0TXBUF =0x80; //读ADXL345ID
while((IFG2&UCB0TXIFG)==0);
IFG2 &=~UCB0TXIFG;
i=0;
while((IFG2&UCB0RXIFG)==0);
IFG2 &=~UCB0RXIFG;
i=UCB0RXBUF;
UCA0TXBUF=i;
while((IFG2&UCA0TXIFG)==0);
IFG2 &=~UCA0TXIFG;
for(i=50;i>0;i--);
P6OUT |=BIT3;
while(1);
}
#pragma vector =USCIAB0RX_VECTOR
__interrupt void UART0_RX(void)
{
uchar i;
if(IFG2&UCA0RXIFG)
{
IE2 &=~UCA0RXIE;
IFG2 &=~UCA0RXIFG;
i =UCA0RXBUF;
UCA0TXBUF =i+1;
while((IFG2&UCA0TXIFG)==0);
IFG2 &=~UCA0TXIFG;
IE2 |=UCA0RXIE;
}
else
{
IE2 &=~UCB0RXIE;
IFG2 &=~UCB0RXIFG;
UCA0TXBUF =0x77;
while((IFG2&UCA0TXIFG)==0);
IFG2 &=~UCA0TXIFG;
UCA0TXBUF =UCB0RXBUF;
while((IFG2&UCA0TXIFG)==0);
IFG2 &=~UCA0TXIFG;
IE2 |=UCB0RXIE;
}
} |