• 大小: 2KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-12
  • 语言: 其他
  • 标签: STM32F103  AD7091  

资源简介

本示例基于stm32f103外设固件库开发的AD7091驱动程序,内涵初始化和AD获取操作代码。
在项目中亲测可以正常运行和使用,适合参考作为二次开发。

资源截图

代码片段和文件信息

#include “ad7091.h“
#include “delay.h“
/**
  * @brief  Select AD7091: Chip Select pin low
  */
#define AD7091_CS_LOW()       GPIO_ResetBits(AD7091_CS_GPIO_PORT AD7091_CS_PIN)
/**
  * @brief  Deselect AD7091: Chip Select pin high
  */
#define AD7091_CS_HIGH()      GPIO_SetBits(AD7091_CS_GPIO_PORT AD7091_CS_PIN)   

/**
  * @brief  Select AD7091: Chip CONVST pin low
  */
#define AD7091_CONVST_LOW()       GPIO_ResetBits(AD7091_CONVST_GPIO_PORT AD7091_CONVST_PIN)
/**
  * @brief  Deselect AD7091: Chip CONVST pin high
  */
#define AD7091_CONVST_HIGH()      GPIO_SetBits(AD7091_CONVST_GPIO_PORT AD7091_CONVST_PIN)  


#define AD7091_DUMMY_BYTE 0xffff



uint16_t AD7091_SendByte(uint16_t byte)
{
  /*!< Loop while DR register in not emplty */
  while (SPI_I2S_GetFlagStatus(AD7091_SPI SPI_I2S_FLAG_TXE) == RESET);

  /*!< Send byte through the SPI1 peripheral */
  SPI_I2S_SendData(AD7091_SPI byte);

  /*!< Wait to receive a byte */
  while (SPI_I2S_GetFlagStatus(AD7091_SPI SPI_I2S_FLAG_RXNE) == RESET);

  /*!< Return the byte read from the SPI bus */
  return SPI_I2S_ReceiveData(AD7091_SPI);
}

uint16_t AD7091_ReadByte(void)
{
  return (AD7091_SendByte(AD7091_DUMMY_BYTE));
}

void AD7091_LowLevel_Init(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;

  /*!< AD7091_SPI_CS_GPIO AD7091_SPI_MOSI_GPIO AD7091_SPI_MISO_GPIO 
       and AD7091_SPI_SCK_GPIO Periph clock enable */
  RCC_APB2PeriphClockCmd(AD7091_CS_GPIO_CLK | AD7091_SPI_MOSI_GPIO_CLK | AD7091_SPI_MISO_GPIO_CLK |
                         AD7091_SPI_SCK_GPIO_CLK | AD7091_CONVST_GPIO_CLK ENABLE);

  /*!< AD7091_SPI Periph clock enable */
  RCC_APB2PeriphClockCmd(AD7091_SPI_CLK ENABLE);
  
  /*!< Configure AD7091_SPI pins: SCK */
  GPIO_InitStructure.GPIO_Pin = AD7091_SPI_SCK_PIN;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_Init(AD7091_SPI_SCK_GPIO_PORT &GPIO_InitStructure);

  /*!< Configure AD7091_SPI pins: MOSI */
  GPIO_InitStructure.GPIO_Pin = AD7091_SPI_MOSI_PIN;
  GPIO_Init(AD7091_SPI_MOSI_GPIO_PORT &GPIO_InitStructure);

  /*!< Configure AD7091_SPI pins: MISO */
  GPIO_InitStructure.GPIO_Pin = AD7091_SPI_MISO_PIN;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;  
  GPIO_Init(AD7091_SPI_MISO_GPIO_PORT &GPIO_InitStructure);
  
  /*!< Configure AD7091_CS_PIN pin: AD7091 Card CS pin */
  GPIO_InitStructure.GPIO_Pin = AD7091_CS_PIN;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_Init(AD7091_CS_GPIO_PORT &GPIO_InitStructure);

  /*!< Configure AD7091_CONVST_PIN pin: AD7091 Card CONVST pin */
  GPIO_InitStructure.GPIO_Pin = AD7091_CONVST_PIN;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_Init(AD7091_CONVST_GPIO_PORT &GPIO_InitStructure);  
}

uint16_t AD7091_GetSmpNormal(void)
{
#if 1
uint16_t adc_smp;
AD7091_CONVST_HIGH();
AD7091_CONVST_LOW();
AD7091_CONVST_HIGH();
//delay<=650ns
delay_us(1);
AD7091

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       4409  2018-06-29 06:46  AD7091\ad7091.c

     文件       1430  2018-05-06 21:55  AD7091\ad7091.h

     目录          0  2018-06-29 06:46  AD7091

----------- ---------  ---------- -----  ----

                 5839                    3


评论

共有 条评论