已回答假定已回答

有没有用stm32驱动AD7124成功过的朋友?

1211996804 在 2017-7-13 詢問的問題
最後回覆由周天强於2018-7-25提供

移植了Communication.c 文件,但是就是不能成功驱动,写入寄存器和读取寄存器不一样,有没有移植成功过的发代码看看呢?

 

unsigned char SPI_Init_ad7124(unsigned char lsbFirst,

                              unsigned long clockFreq,

                              unsigned char clockPol,

                              unsigned char clockEdg)

{

 

 

  CPU_SPI_Init(1, 8, SPI_Speed_Lowest, CPU_SPI_MODE_HD);//配置SPI口

  CPU_IO_Init(IO_CPU_C, IO_Pin_8, IOMODE_OUT); //cs

  CPU_IO_WrBit(IO_CPU_C, IO_Pin_8, 0x00);

  return 1;

  /* Add your code here. */

}

 

 

/***************************************************************************//**

* @brief Reads data from SPI.

*

* @param slaveDeviceId - The ID of the selected slave device.

* @param data - Data represents the write buffer as an input parameter and the

*               read buffer as an output parameter.

* @param bytesNumber - Number of bytes to read.

*

* @return Number of read bytes.

*******************************************************************************/

unsigned char SPI_Read(unsigned char slaveDeviceId,

                       unsigned char* data,

                       unsigned char bytesNumber)

{

  CPU_IO_WrBit(IO_CPU_C, IO_Pin_8, 0x00);

 

 

  CPU_SPI_SendByte(1,data[0]);

 

 

  /* Add your code here. */

  for(int i=1; i<bytesNumber; i++)

  {

    data[i] = CPU_SPI_SendByte(1,data[i]);

  }

 

 

  CPU_IO_WrBit(IO_CPU_C, IO_Pin_8, 0x01);

  return bytesNumber;

}

 

 

/***************************************************************************//**

* @brief Writes data to SPI.

*

* @param slaveDeviceId - The ID of the selected slave device.

* @param data - Data represents the write buffer.

* @param bytesNumber - Number of bytes to write.

*

 

 

* @return Number of written bytes.

*******************************************************************************/

unsigned char SPI_Write(unsigned char slaveDeviceId,

                        unsigned char* data,

                        unsigned char bytesNumber)

{

  /* Add your code here. */

  CPU_IO_WrBit(IO_CPU_C, IO_Pin_8, 0x00);

  CPU_SPI_SendByte(1, data[0]);

 

 

  for(int i=1; i<bytesNumber; i++)

  {

    CPU_SPI_SendByte(1, data[i]);

  }

 

 

  CPU_IO_WrBit(IO_CPU_C, IO_Pin_8, 0x01);

  return bytesNumber;

}

結果