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.

ADS1255读写寄存器问题

Other Parts Discussed in Thread: ADS1255

这是我初始化ADS1255函数 和 读写寄存器函数。SPI速度设置为最低速300KHZ左右。请问各位和TI工程师,这是怎么回事。谢谢!

经过串口,首先把ADS1255寄存器的缺省值显示出来,再写进去再经串口显示出来。但是无论是读ADS1255寄存器的初始值也不对,读经过写之后的值也不对。

无论是第一次读,还是写后再读,都是显示一些255 63 253等等的数值(255居多)。

SPI_SendByte函数就是STM32库函数中SPI发送Byte函数
/////////////////////////////////////
//ADS1255硬件reset函数
/////////////////////////////////////
void ADS1255_ResetHard(void)
{
	ADS_RESET_LOW();
	delay_us(5);
	ADS_RESET_HIGH();
	delay_us(5);
}

///////////////////////////////////
///ADS1255写寄存器函数
//////////////////////////////////
void ADS1255_WREG(unsigned char regaddr,unsigned char databyte)
{
	ADS_CS_LOW();
	while(ADS_DRDY);
	SPI_SendByte(ADS1255_CMD_WREG | (regaddr & 0x0F));
	SPI_SendByte(0);
	delay_us(100);		//
	SPI_SendByte(databyte);
	ADS_CS_HIGH();
}

//////////////////////////////////////////////
///ADS1255读寄存器函数
//////////////////////////////////////////////
unsigned char ADS1255_RREG(unsigned char regaddr)
{
	unsigned char r=0;
	ADS_CS_LOW();
	while(ADS_DRDY);
	SPI_SendByte(ADS1255_CMD_RREG | (regaddr & 0x0F ));
	SPI_SendByte(0);
	delay_us(10);		//t6
	r=SPI_SendByte(0);
	ADS_CS_HIGH();
	return r;
}

//////////////////////////////////////////////
//ADS1255初始化函数
///////////////////////////////////////////////
void ADS1255_Init(void)
{
	u8 i=0;
	unsigned char tab1[4];
	ADS1255_ResetHard();
	ADS_CS_LOW();
	tab1[0]=ADS1255_RREG(0);	//x1h
	tab1[1]=ADS1255_RREG(1);	//01h=1d	
	tab1[2]=ADS1255_RREG(2);	//20h=32d
	tab1[3]=ADS1255_RREG(3);	//f0h=240d
	//tab1[4]=ADS1255_RREG(4);	//e0h=224d
	ADS_CS_HIGH();
	for(i=0;i<4;i++)
	{
		printf("o:%d\r\n",(u8)tab1[i]);
		delay_ms(100);
	}
	
	ADS_CS_LOW();
	while(ADS_DRDY);
	SPI_SendByte(ADS1255_CMD_WREG | ADS1255_STATUS);
	SPI_SendByte(3);
	SPI_SendByte(0x06);		//status
	SPI_SendByte(0x10);		//mux
	SPI_SendByte(0x00);		//adcon
	SPI_SendByte(0x03);		//drate
	//SPI_SendByte(0xD0);		//io
	ADS_CS_HIGH();
	
	delay_us(100);
	tab1[0]=ADS1255_RREG(0);
	tab1[1]=ADS1255_RREG(1);
	tab1[2]=ADS1255_RREG(2);
	tab1[3]=ADS1255_RREG(3);
	//tab1[4]=ADS1255_RREG(4);
	for(i=0;i<4;i++)
	{
		printf("a:%d\r\n",(u8)tab1[i]);
		delay_ms(100);
	}
}