读ADS1247 ,程序如下,结果全是0,
不知道为什么?
SPI_InitStructure.SPI_Direction = 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; // CPOL = 0, SCK 为高有效
SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; // CPHA = 1, 数据在SCK 的第一个时钟沿采样
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
//SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8; //15/8
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_64; //15M/64=0.23435
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; // LSBF = 0, SPI 数据传输MSB (位7)在先
SPI_InitStructure.SPI_CRCPolynomial = 7;
void ReadAllRegister(void)
{
volatile BYTE Tt;
volatile BYTE i;
ENABLESPI_CS();
ENABLESPI_CS(); //tcssc >= 6ns
Delay_1_96us();
//read from 0 to 0x0e
SPI_SendByte(0xff);
SPI_SendByte(0x20);
SPI_SendByte(15-1);
for(i=0;i<15;i++)
{
Tt=SPI_SendByte(0xff); //nop
printf("register=%1d,value=%1d.\n",i,Tt);
}
Delay_1_96us();
DISABLESPI_CS();
DISABLESPI_CS();
}
BYTE SPI_SendByte(BYTE byt)
{
/* Loop while DR register in not emplty */
while(SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE)==RESET);
/* Send byte through the SPI1 peripheral */
SPI_I2S_SendData(SPI2, byt);
/* Wait to receive a byte */
while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == RESET);
/* Return the byte read from the SPI bus */
return SPI_I2S_ReceiveData(SPI2);
} |