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.

MSP430 SPI不用中断接收数据错误

Other Parts Discussed in Thread: ADS1256

已经搜索论坛没有找到答案。。。

问题如下,测试SPI的程序,利用示波器可以看到已经接收到数据(如附件 ),

可是中断查看接收程序错误,一直输出都是零,利用单步调试可以接收到数据。系统的连线如下:

采用UCA1将数据传入上位机,利用UCB0进行SPI通信,主要的部分程序如下:

#include "msp430x54x.h"
#include "ADS1256.h"
#include "Init_SYS.h"

unsigned char i = 0;
unsigned char rzyj = 0;

int main(void) {
WDTCTL = WDTPW + WDTHOLD; //关闭看门狗

Clk_Init(); //时钟初始化
ADC_spi_init() ; //SPI初始化
Uart_Init(); //串口初始化

while (1) {

delay_ms(50); //

UCB0TXBUF = 0x10;
while (!(UCB0IFG & UCTXIFG)); //读命令 0x10
delay_us(6);

UCB0TXBUF = 0x00;
while (!(UCB0IFG & UCTXIFG)); //字节数为1
delay_us(14); //

UCB0TXBUF = 0x00;
while (!(UCB0IFG & UCTXIFG)); //发送 0x00读取数据
delay_us(6);

UCB0TXBUF = i ;    // Transmit first character
while (!(UCB0IFG & UCTXIFG));      // SPI 测试
while(!(UCB0IFG & UCRXIFG)) rzyj = UCB0RXBUF;
rzyj = UCB0RXBUF;
i++;

while (!(UCA1IFG & UCTXIFG)); //接收到的数据发送至上位机
UCA1TXBUF = rzyj;

}

//****************************** SPI 设置部分程序************************/

}

///**************************

void ADC_spi_init() //zyj
{
P3SEL |= 0x0E; // P3.1,2,3 option select
P3DIR |= BIT1 + BIT3; //P3.1 SIMO,P3.3 SCLK
P3DIR &= ~ BIT2; //P3.2 SOMI.输入
P6DIR |= BIT5; //P6.5 输出
P1DIR &= ~ BIT0; //P1.0 输入,DRDY引脚

UCB0CTL1 |= UCSWRST; // **Put state machine in reset**
UCB0CTL0 |= UCMST + UCSYNC + UCMSB; // 3-pin, 8-bit SPI master + UCCKPL +UCCKPH
// Clock polarity high, MSB
UCB0CTL1 |= UCSSEL_2; // SMCLK,选择系统时钟
UCB0BR0 = 0x10; // /2
UCB0BR1 = 0; //
// UCB0MCTL = 0; // No modulation
UCB0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
// UCB0IE |= UCRXIE; // Enable USCI_A0 RX interrupt

}

如上,黑体部分,单步调试时候能够接收到变量i的值,但是连续运行时输出为0000,求高手指导!