这是我的程序
u32 spi(u32 data)
{
u32 Data_recive;
u8 temp11,temp22,temp33,temp44;
u8 temp1,temp2,temp3,temp4;
temp4=data;
temp3=data>>8;
temp2=data>>16;
temp1=data>>24;
AD7280A_NCS;
_nop_(); //delay >10ns
delay_us(10);
SPI_Tx(temp1);
//delay_us(2); //need longer wait while reading single chip at upper position
temp11=SPI_Rx();
SPI_Tx(temp2);
//delay_us(2); //need longer wait while reading single chip at upper position
temp22=SPI_Rx();
SPI_Tx(temp3);
//delay_us(2); //need longer wait while reading single chip at upper position
temp33=SPI_Rx();
SPI_Tx(temp4);
//delay_us(2); //need longer wait while reading single chip at upper position
temp44=SPI_Rx();
delay_us(10);
AD7280A_CS;
delay_us(3);
Data_recive=(temp11<<24)+(temp22<<16)+(temp33<<8)+temp44;
printf("%x %x %x %x ",temp11,temp22,temp33,temp44);
return Data_recive;
}
void initad7280_1()
{
spi(0x01c2b6e2);
delay_us(90);
AD7280A_NCS;
delay_us(15);
AD7280A_CS;
spi(0x038716ca);
}
void caiji_1()
{
u32 temp1,temp2,temp3,temp4,temp5,temp6;
u32 temp11,temp22,temp33,temp44,temp55,temp66;
spi(0x038011CA);
spi(0x01A0131A);
delay_us(90);//90us
spi(0x03A0546A);
AD7280A_CNVST;
delay_us(10); //CNVST
AD7280A_NCNVST;
delay_us(50);
AD7280A_CS;
delay_us(10); //CS
AD7280A_NCS;
temp1=spi(0xF800030A);
delay_us(90);//90us
AD7280A_CS;
delay_us(10); //CS
AD7280A_NCS;
temp2=spi(0xF800030A);
delay_us(90);//90us
AD7280A_CS;
delay_us(10); //CS
AD7280A_NCS;
temp3=spi(0xF800030A);
delay_us(90);//90us
AD7280A_CS;
delay_us(10); //CS
AD7280A_NCS;
temp4=spi(0xF800030A);
delay_us(90);//90us
AD7280A_CS;
delay_us(10); //CS
AD7280A_NCS;
temp5=spi(0xF800030A);
delay_us(90);//90us
AD7280A_CS;
delay_us(10); //CS
AD7280A_NCS;
temp6=spi(0xF800030A);
delay_us(90);//90us
AD7280A_CS;
delay_us(10); //CS
AD7280A_NCS;
temp11=spi(0xF800030A);
delay_us(90);//90us
AD7280A_CS;
delay_us(10); //CS
AD7280A_NCS;
temp22=spi(0xF800030A);
delay_us(90);//90us
AD7280A_CS;
delay_us(10); //CS
AD7280A_NCS;
temp33=spi(0xF800030A);
delay_us(90);//90us
AD7280A_CS;
delay_us(10); //CS
AD7280A_NCS;
temp44=spi(0xF800030A);
delay_us(90);//90us
AD7280A_CS;
delay_us(10); //CS
AD7280A_NCS;
temp55=spi(0xF800030A);
delay_us(90);//90us
AD7280A_CS;
delay_us(10); //CS
AD7280A_NCS;
temp66=spi(0xF800030A);
delay_us(90);//90us
AD7280A_CS;
printf("%5.4f\r\n",((float)((temp1>>11)&0x00000fff)/4096)*4+1);
printf("%5.4f\r\n",((float)((temp2>>11)&0x00000fff)/4096)*4+1);
printf("%5.4f\r\n",((float)((temp3>>11)&0x00000fff)/4096)*4+1);
printf("%5.4f\r\n",((float)((temp4>>11)&0x00000fff)/4096)*4+1);
printf("%5.4f\r\n",((float)((temp5>>11)&0x00000fff)/4096)*4+1);
printf("%5.4f\r\n",((float)((temp6>>11)&0x00000fff)/4096)*4+1);
printf("%5.4f\r\n",((float)((temp11>>11)&0x00000fff)/4096)*5);
printf("%5.4f\r\n",((float)((temp22>>11)&0x00000fff)/4096)*5);
printf("%5.4f\r\n",((float)((temp33>>11)&0x00000fff)/4096)*5);
printf("%5.4f\r\n",((float)((temp44>>11)&0x00000fff)/4096)*5);
printf("%5.4f\r\n",((float)((temp55>>11)&0x00000fff)/4096)*5);
printf("%5.4f\r\n",((float)((temp66>>11)&0x00000fff)/4096)*5);
但是结果如下
1.0000
1.2227
1.0039
1.0000
1.2510
1.4072
2.1570
2.1936
2.1436
2.1362
2.1228
2.1973
电池检测部分的电压值一个都不对