ads8329的时序和以前的spi协议时序 有所不同 小弟看不懂 求大家指点
#ifndef _AD9850_H
#define _AD9850_H
#include "msp430f2617.h"
#define CLK_1 P2OUT |= BIT0
#define CLK_0 P2OUT &= ~BIT0
#define SDI_1 P2OUT |= BIT2
#define SDI_0 P2OUT &= ~BIT2
#define CS_1 P2OUT |= BIT3
#define CS_0 P2OUT &= ~BIT3
//#define INT_1 P2OUT |= BIT4
//#define INT_0 P2OUT &= ~BIT4
#define CONVST_1 P2OUT |= BIT5
#define CONVST_0 P2OUT &= ~BIT5
#define SDO (P2IN & BIT1)
void InitADS8329()
{
CLK_0;
CONVST_1;
CS_1;
}
void WriteADS8329(unsigned int commd)
{
unsigned char i;
CS_0;
for(i = 0; i < 16; i++)
{
CLK_1;
if(commd & 0x8000)
{
SDI_1;
}
else
{
SDI_0;
}
CLK_0;
commd = commd << 1;
}
CS_1;
}
unsigned int ReadADS8329()
{
unsigned char i, commd = 13;
unsigned int ReadData = 0;
CLK_1;
for(i = 0; i < 50; i++)
{
if(i < 24)
{
CLK_0;
CLK_1;
}
else if(i < 40)
{
CS_0;
if(i < 28)
{
if(commd & 8)
{
SDI_1;
}
else
{
SDI_0;
}
commd = commd << 1;
}
if(SDO)
{
ReadData |= 0x0001;
}
ReadData = ReadData << 1;
CLK_0;
CLK_1;
}
else
{
CLK_0;
CLK_1;
CS_1;
}
}
return ReadData;
}
#endif
上边是读写时序 下边是 主函数
int main( void )
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
Init_CLK();
InitPort();
InitADS8329();
WriteADS8329(0Xe0a7);
while(1)
{
Data1 = ReadADS8329();
Data2 = ReadADS8329();
Data3 = ReadADS8329();
Data4 = ReadADS8329();
}
}