DSP28335通过GPIO模拟SPI配置并采集AD2S1210数据

首先让我们先看看大概流程

以下是相关代码:

//---------------------------------
//void WriteToAD2S(unsigned char count,unsigned char *buf);
//---------------------------------
//Function that writes to the AD2S via the SPI port. 
//--------------------------------------------------------------------------------
void AD2S1210Initiate()
{
//RESET->0 initially  
	CLR_RESET();  
	SET_SPL();
	delay(1);
	SET_RESET(); 
	delay(2);
	CLR_SPL();
	delay(1);
	SET_SPL();
}

void AD2S1210SelectMode(unsigned char mode)
{
	if (mode==POSITION)
	{
		CLR_A0();
		CLR_A1();
		delay(1);		//Normal Mode position output
	}
	else if (mode==VELOCITY)
	{
		CLR_A0();
		SET_A1();
		delay(1);		//Normal Mode velocity output
	}
	else if (mode==CONFIG)
	{
		SET_A0();
		SET_A1();
		delay(1);		//Configuration Mode
	}
}

void WriteToAD2S1210(unsigned char address, unsigned char data)
{
	unsigned	char	buf;

	//write control register address
	buf = address;

	SET_SCLK();
	delay(1);//24ns
	SET_CS();
	delay(1);
	CLR_CS();
	delay(1);
	
	SET_WR();
	delay(1);
	CLR_WR();
	delay(1);

	SPIWrite(1,&buf);	  	 
	
	SET_WR();
	delay(1);	
	SET_CS();	
	//write control register address

	//write control register data
	buf = data;

	SET_SCLK();
	delay(1);
	SET_CS();
	delay(1);
	CLR_CS();
	delay(1);
	
	SET_WR();
	delay(1);
	CLR_WR();
	delay(1);

	SPIWrite(1,&buf);	  	 

	SET_WR();
	delay(1);	
	SET_CS();
	//write control register data
}

void ReadFromAD2S1210(unsigned char mode, unsigned char address, unsigned char * buf)
{

	if (mode==CONFIG)
	{
		
		//write control register address
		buf[0] = address;

		SET_SCLK();
		delay(1);
		SET_CS();
		delay(1);
		CLR_CS();
		delay(1);
		
		SET_WR();
		delay(1);
		CLR_WR();
		delay(1);

		SPIWrite(1,buf);

		SET_WR();
		delay(1);	
		SET_CS();
		//write control register address


		//read 1-byte register
		SET_SCLK();
			
		SET_CS();
		SET_WR();
		delay(1);
	
		CLR_CS();
		delay(1);
	
		CLR_SCLK();	
		delay(1);
		
		CLR_WR();
		delay(1);

		SPIRead(1,buf);	

		SET_WR();
		delay(1);

		SET_CS();
		//read 1-byte register
	}
	else if (mode==POSITION||mode==VELOCITY)
	{
		SET_SPL();
		delay(1);
		CLR_SPL();
		delay(5);

		//read 3-byte register 
		SET_SCLK();
				
		SET_CS();
		SET_WR();
		delay(1);
		
		CLR_CS();
		delay(1);
	
		CLR_SCLK();	
		delay(1);
			
		CLR_WR();
		delay(1);
	
		SPIRead(3,buf);		//read data register
	
		SET_WR();
		delay(1);
	
		SET_CS();
		//read 3-byte register


	}
}

void AD2S1210SoftReset(void)
{
	unsigned char buf=	SOFTRESET;
	SPIWrite (1,&buf);	  	//soft reset 
	delay(10);
}

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值