ADIS16465与STM32F103之间SPI通信的问题

您好!

我使用STM32F103的SPI接口与ADIS6465通信,试图读取product-ID(addr=0x72),但结果大多时候都不正确,极少数时候会得到正确结果0x4051。

错误的时候得到的结果是0x0000,0x4040, 0x5151等等。

SPI设置的工作模式:baudrate=562.5KHz, 16-bit data mode,CPOL=CPHA=1。

同时我检查了时序,看起来没什么问题。以下两个图,一个是结果正确时的波形图,一个是结果不正确时候的波形图。

绿色:CS,黄色:CLK,红色:MO,蓝色:MI

IMU返回结果正确时0x4051

IMU返回不正确时:0x4040

以下是连续读取同一个寄存器productID得到的结果:

结果很奇怪,一直没找到原因是什么。以下是SPI读取操作的代码片段:

unsigned int SPI1_Transfer_16b(unsigned short data)
{
    // Wait until SPI is not busy anymore
    while (SPI1->SR & (SPI_I2S_FLAG_BSY));
    // Write data to be transmitted to the SPI data register
    SPI1->DR = data;
    // Wait until transmit complete
    while (!(SPI1->SR & (SPI_I2S_FLAG_TXE)));
    // Wait until receive complete
    while (!(SPI1->SR & (SPI_I2S_FLAG_RXNE)));
    // Wait until SPI is not busy anymore
    while (SPI1->SR & (SPI_I2S_FLAG_BSY));
    // Return received data from SPI data register
    return SPI1->DR;
}

unsigned short read_reg_16b(unsigned char addr)
{
	unsigned short temp = 0;
	temp = (READ_IMU | addr)<<8;
        
	SPI1_CS_LOW();
	temp = SPI1_Transfer_16b(0x7200);
	SPI1_CS_HIGH();
        
	return temp;
}


unsigned short prod = 0;
void adis_test(void)
{
    while(1)
    {
        prod = read_reg_16b(PROD_ID);
        //print result to COM13
    }

}

是否有哪位能够看出一些端倪?还请帮忙指出,不胜感激!

多谢!