尝试用硬件SPI调试7818,但是关于读数的问题有点不清楚
uint Read_Data(void)
{
uint convdata_H,convdata_L,convdata;
float Voltage;
CONV_0;
TXBUF0 = 0x00;
TXBUF0 = 0x00;
while ((IFG1 & URXIFG0) == 0); // USART0 RX buffer ready?
convdata_H = RXBUF0;
while ((IFG1 & URXIFG0) == 0); // USART0 RX buffer ready?
convdata_L = RXBUF0;
CONV_1;
convdata_H = convdata_H << 4;
convdata_L = convdata_L >>4;
convdata = convdata_H+convdata_L;
Voltage=convdata*4.999/4096;
Disp_float_num(1,2,Voltage);
return convdata;
}
/************主函数************/
#include <msp430x16x.h>
#include "ADS7818.h"
#include "cryfuncs.h"
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
Ini_Lcd();
ME1 |= USPIE0; // Enable USART0 SPI mode
UCTL0 |= CHAR + SYNC + MM; // 8-bit SPI Master **SWRST**
UTCTL0 |= CKPH + SSEL1 + SSEL0 + STC; // SMCLK, 3-pin mode
UBR00 = 0x02; // UCLK/2
UBR10 = 0x00; // 0
UMCTL0 = 0x00; // no modulation
UCTL0 &= ~SWRST; // Initialize USART state machine
P3SEL |= 0x0E; // P3.1-3 SPI option select
P3DIR |= 0x01; // P3.0 output direction
CONV_1;
showADS7818();
while (1) // Loop
{
volatile unsigned int i;
i = Read_Data();
}
}
这样写可以吗?运行以后有数据但是数据不对而且乱跳,不知道是哪里的问题。。