这是我的程序
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
电池检测部分的电压值一个都不对
没有用过AD7280,不好说。不过楼主先确认下器件和MCU的SPI通讯没问题,器件和MCU都能接受到正确的数据,可以先用示波器或者逻辑分析仪采集下通讯的波形,保证SPI链路上采集到的数据值跟你MCU上读取到的数据是一致的。很多人调试中各种莫名其妙的问题,很多情况下就是SPI通讯上的问题引起的。粗粗看了下PDF,貌似AD7280里面有个自测模式,不知道你自测模式下的结果是否跟预期相一致。还有就是是否试过写配置寄存器然后再读取相应的设置是否能一致。
如果天空是黑暗的,那就摸黑生存;如果发出声音是危险的,那就保持沉默...但不要习惯了黑暗就为黑暗辩护;不要为自己的苟且而得意;不要嘲讽那些比自己更勇敢热情的人们。人可以卑微如尘土,不可扭曲如蛆虫。
我已经测过了,SPI通讯是没问题的,但是我觉的应该是读电压数据的时候有问题,因为我在测试时发现我的辅助ADC是随着采样电压的变化而变化,但是具体测得值不对。还有电池电压测得一个都不对
我已经测过了,SPI通讯是没问题的,但是我觉的应该是读电压数据的时候有问题,因为我在测试时发现我的辅助ADC是随着采样电压的变化而变化,但是具体测得值不对。还有电池电压测得一个都不对
你好,我也在弄这个芯片,可以一起交流吗?我qq2356650387