哪位用STM32F103控制过AD7792,NSS、SCK、MOSI上都有波形,MISO上就是没数! /* SPI1 Master */ 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_High; SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; 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(SPI1, &SPI_InitStructure); SPI_Cmd(SPI1, ENABLE); GPIO_SetBits(GPIOA, GPIO_Pin_4); Delay(500);//90uS GPIO_ResetBits(GPIOA, GPIO_Pin_4); // Wait for SPI1 Tx buffer empty while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET); // Send SPI1 ReadId for read AD7792 ID register SPI_I2S_SendData(SPI1,ReadID); while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET); SPI_I2S_SendData(SPI1, 0xA5); while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET); SPI1_Rx = SPI_I2S_ReceiveData(SPI1); GPIO_SetBits(GPIOA, GPIO_Pin_4); 高人指点指点! |
RE:SPI控制AD7792
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
// Send SPI1 ReadId for read ID register
SPI_I2S_SendData(SPI1,ReadID);
Delay(500);
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
// Send SPI1 Dummy for SCK
SPI_I2S_SendData(SPI1, 0xF0);
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET);
SPIRx1 = SPI_I2S_ReceiveData(SPI1);
SPI时序过快,添加Delay(500)后可以稳定工作!
回复:SPI控制AD7792
QQ121293523