给个简单的代码仅供参考;
struct
{
u8 AD7190_SendData[4];
u8 AD71901_ReveiceData[4];
}AD7190_TempData;
void SPI1_Send_ReveiceFull(u8 * data,u8 len)
{
u8 temp,i;
// CS_ON1();
for(i = 0;i < len;i++)
{
while(SPI_I2S_GetFlagStatus(SPI1,SPI_I2S_FLAG_TXE)==RESET);
SPI_I2S_SendData(SPI1,*(data + i));
while(SPI_I2S_GetFlagStatus(SPI1,SPI_I2S_FLAG_RXNE)==RESET);
temp = SPI_I2S_ReceiveData(SPI1);
*(AD7190_TempData.AD71901_ReveiceData + len - i - 1 ) = temp;
}
// CS_OFF1();
}
//AD7190芯片初始化(仅供参考)
void AD71901Init(void)
{
u8 i;
for(i = 0 ;i < 4;i ++)
{
AD7190_TempData.AD7190_SendData[i] = 0xff;
}
SPI1_Send_ReveiceFull(AD7190_TempData.AD7190_SendData,4);
SPI1_Send_ReveiceFull(AD7190_TempData.AD7190_SendData,1);
for(i = 0 ;i < 4;i ++)
{
AD7190_TempData.AD7190_SendData[i] = 0x00;
}
delay_us(700);
//读模式寄存器
AD7190_TempData.AD7190_SendData[0] = 0x48;
SPI1_Send_ReveiceFull(AD7190_TempData.AD7190_SendData,1);
for(i = 0 ;i < 4;i ++)
{
AD7190_TempData.AD7190_SendData[i] = 0x00;
}
SPI1_Send_ReveiceFull(AD7190_TempData.AD7190_SendData,3);
// printf("AD71901数据:%x_%x_%x\r\n",AD7190_TempData.AD71901_ReveiceData[3] + buf[2],buf[1],buf[0]);
//读配置寄存器
AD7190_TempData.AD7190_SendData[0] = 0x50;
SPI1_Send_ReveiceFull(AD7190_TempData.AD7190_SendData,1);
for(i = 0 ;i < 4;i ++)
{
AD7190_TempData.AD7190_SendData[i] = 0x00;
}
SPI1_Send_ReveiceFull(AD7190_TempData.AD7190_SendData,3);
// printf("AD7190数据1:%x_%x_%x\r\n",buf[2],buf[1],buf[0]);
AD7190_TempData.AD7190_SendData[0] = 0x10;
SPI1_Send_ReveiceFull(AD7190_TempData.AD7190_SendData,1);
// SPI2_Send_ReveiceFull(AD7190_TempData.AD7190_SendData,1);
AD7190_TempData.AD7190_SendData[0] = 0;
AD7190_TempData.AD7190_SendData[1] = 0x03;
AD7190_TempData.AD7190_SendData[2] = 0;
SPI1_Send_ReveiceFull(AD7190_TempData.AD7190_SendData,3);
// SPI2_Send_ReveiceFull(AD7190_TempData.AD7190_SendData,3);
//设置模式寄存器
AD7190_TempData.AD7190_SendData[0] = 0x08;
SPI1_Send_ReveiceFull(AD7190_TempData.AD7190_SendData,1);
// SPI2_Send_ReveiceFull(AD7190_TempData.AD7190_SendData,1);
AD7190_TempData.AD7190_SendData[0] = 0x18;
AD7190_TempData.AD7190_SendData[1] = 0x00;
AD7190_TempData.AD7190_SendData[2] = 0x01;
SPI1_Send_ReveiceFull(AD7190_TempData.AD7190_SendData,3);
// SPI2_Send_ReveiceFull(AD7190_TempData.AD7190_SendData,3);
//读模式寄存器
AD7190_TempData.AD7190_SendData[0] = 0x48;
SPI1_Send_ReveiceFull(AD7190_TempData.AD7190_SendData,1);
// buf[0] = 0x48;
for(i = 0 ;i < 4;i ++)
{
AD7190_TempData.AD7190_SendData[i] = 0x00;
}
SPI1_Send_ReveiceFull(AD7190_TempData.AD7190_SendData,3);
// printf("AD7190数据1:%x_%x_%x\r\n",buf[2],buf[1],buf[0]);
//读配置寄存器
AD7190_TempData.AD7190_SendData[0] = 0x50;
SPI1_Send_ReveiceFull(AD7190_TempData.AD7190_SendData,1);
for(i = 0 ;i < 4;i ++)
{
AD7190_TempData.AD7190_SendData[i] = 0x00;
}
SPI1_Send_ReveiceFull(AD7190_TempData.AD7190_SendData,3);
// printf("AD7190数据1:%x_%x_%x\r\n",buf[2],buf[1],buf[0]);
AD7190_TempData.AD7190_SendData[0] = 0x5c;
SPI1_Send_ReveiceFull(AD7190_TempData.AD7190_SendData,1);
// SPI2_Send_ReveiceFull(AD7190_TempData.AD7190_SendData,1);
for(i = 0 ;i < 4;i ++)
{
AD7190_TempData.AD7190_SendData[i] = 0x00;
}
}
|