STM32使用IO模拟读取AD5422完全没问题,但是使用SPI读取不行:
SPI_I2S_DeInit(SPI_Master1);
SPI_InitStructure.SPI_Direc
tion = SPI_Direction_2Lines_FullDuplex;
SPI_InitStructure.SPI_Mode=SPI_Mode_Master;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_256;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_Init(SPI_Master1, SPI_InitStructure);
u8 SPI_Master_RW(u8 date)
{
u8 retry=0;
while(SPI_I2S_GetFlagStatus(SPI_Master1,SPI_I2S_FLAG_TXE)==RESET)
{
retry++;
if(retry>200)
return 0;
}
SPI_I2S_SendData(SPI_Master1,date);
while(SPI_I2S_GetFlagStatus(SPI_Master1,SPI_I2S_FLAG_RXNE)==RESET)
{
retry++;
if(retry>200)
return 0;
}
return SPI_I2S_ReceiveData(SPI_Master1);
}
void AD5422_Read(u8 num,u8 *pbuf)
{
u8 i=0;
Select_DAC1();
for(i=num;i>0;i--)
{
*(pbuf+i-1)=SPI_Master_RW(AD5422_NOP);
}
NotSelect_DAC1();
}
void AD5422_Write(u8 num,u8 *pbuf)
{
u8 i=0;
Select_DAC1();
for(i=num;i>0;i--)
{
SPI_Master_RW(*(pbuf+i-1));
}
NotSelect_DAC1();
}
SPI四种模式都试过了,示波器有波形输出(CLK,CS,MOSI波形都有),但是AD5422完全没反应。也不能读取数据。这是为什么?难道只能IO模拟不能使用STM32的SPI?