1514|6

2642

帖子

6

TA的资源

五彩晶圆(初级)

楼主
 

ADX516 STM32驱动 [复制链接]

/*
    Analogysemi xutong
    2023/02/15
*/
#include "ADX516.h"
#include "cmsis_os2.h" 
static void ADX516_GPIO_Init(void);
void ADX516_READ(uint32_t len, uint8_t *wdata, uint8_t *rdata);
void ADX516_WRITE(uint32_t len, uint8_t *wdata);

// 初始化ADX516
void ADX516_Init(void)
{
//  ADX516_GPIO_Init();
  //    START_L;
  //    XTAL_H;
//    	ADX516_PWD_L;
     osDelay(1);	
//     ADX516_PWD_H;
     ADX516_REST_L;
     osDelay(150);
     ADX516_REST_H;
     osDelay(1);
     ADX516_REST_H;
}
static void ADX516_GPIO_Init(void)
{
  GPIO_InitTypeDef GPIO_InitStruct;
  __HAL_RCC_GPIOA_CLK_ENABLE();
  __HAL_RCC_GPIOB_CLK_ENABLE();
  __HAL_RCC_GPIOG_CLK_ENABLE();
  __HAL_RCC_GPIOF_CLK_ENABLE();
  __HAL_RCC_GPIOD_CLK_ENABLE();

  GPIO_InitStruct.Pin = GPIO_PIN_10 | GPIO_PIN_11;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10 | GPIO_PIN_11, GPIO_PIN_SET);

  GPIO_InitStruct.Pin = GPIO_PIN_10 | GPIO_PIN_15 | GPIO_PIN_14;
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_10 | GPIO_PIN_15 | GPIO_PIN_14, GPIO_PIN_SET);

  GPIO_InitStruct.Pin = GPIO_PIN_11 | GPIO_PIN_12;
  HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);

  HAL_GPIO_WritePin(GPIOD, GPIO_PIN_11 | GPIO_PIN_12, GPIO_PIN_SET);

  GPIO_InitStruct.Pin = GPIO_PIN_7;
  HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);

  HAL_GPIO_WritePin(GPIOF, GPIO_PIN_7, GPIO_PIN_SET);

  GPIO_InitStruct.Pin = GPIO_PIN_11 | GPIO_PIN_12;
  HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);

  GPIO_InitStruct.Pin = GPIO_PIN_9;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_PULLUP;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
}
// 获取芯片的ID号
// Adx516 default Value 0x20
uint8_t ADX516_GetChipID(void)
{
  uint8_t ID;
  ID = ADX516_GetReg(ADX516_STATUS);
  return ID;
}
// 获取芯片寄存器值
uint8_t ADX516_GetReg(uint8_t Rreg)
{
  uint8_t TxData[3];
  uint8_t RxData[3];
  // 读取命令,
  TxData[0] = ADX516_RREG | Rreg;
  // 选择要读取的寄存器
  TxData[1] = 0x00;
  // 读取单个寄存器
  TxData[2] = 0X00;
  // 开始读取
  ADX516_READ(3, TxData, RxData);
  // 返回寄存器值
  return RxData[2];
}
// 写单个芯片寄存器值
void ADX516_WriteReg(uint8_t Wreg, uint8_t Data)
{
  uint8_t TxData[3];
  // 写入命令,
  TxData[0] = ADX516_WREG | Wreg;
  // 选择要写入的的寄存器
  TxData[1] = 0x00;
  // 读取写入寄存器
  TxData[2] = Data;
  ADX516_WRITE(3, TxData);
}
// 写多个芯片寄存器值
// StartReg 起始寄存器地址
// RegNum 要写的寄存器数量
//*Data  寄存器参数传入
void ADX516_WriteMultiReg(uint8_t StartReg, uint8_t RegNum, uint8_t *Data)
{
  uint8_t TxData[32];
  uint8_t i;
  // 写入命令,
  TxData[0] = ADX516_WREG | StartReg;
  // 选择要写入的的寄存器
  TxData[1] = RegNum - 1;
  for (i = 0; i < RegNum; i++)
  {
    // 将指针数据赋值给Txdata
    TxData[2 + i] = *Data;
    // 指向下个数据地址
    Data++;
  }
  // 最终发送多少个数据
  ADX516_WRITE(2 + RegNum, TxData);
}
// 读多个芯片寄存器值
// StartReg 起始寄存器地址
// RegNum 要写的寄存器数量
//*Data  寄存器参数传出
void ADX516_ReadMultiReg(uint8_t StartReg, uint8_t RegNum, uint8_t *Data)
{
  // 读取寄存器
  uint8_t TxData[3];
  // 读取命令,
  TxData[0] = ADX516_RREG | StartReg;
  // 选择要写入的的寄存器
  TxData[1] = RegNum - 1;
  // 最终接收多少个数据
  ADX516_READ(2 + RegNum, TxData, Data);
}
// 打印所有寄存器地址
void ADX516_GetAllReg(void)
{
  uint8_t i, j;
  for (i = 0; i < 20; i++)
  {
    j = ADX516_GetReg(i);
    // 打印所有寄存器值
    //    rt_kprintf("reg addr: %d reg default Value: %x\r\n",i,j);
  }
}
// 发送ADX516 数据指令 如SDATAC或者RDATAC
// 详情见头文件command define部分
void ADX516_Command(uint8_t Com)
{
  uint8_t TxData[] = {Com};
  ADX516_WRITE(1, TxData);
}
// 设定通道并且获取adc数据
// 获取ADC的值
void ADX516_GetADC_Value(uint8_t Ch, uint32_t *Rxdata,uint32_t times)
{
  uint8_t TxData[] = {ADX516_RDATA};
  ADX516_Command(ADX516_SDATAC);
  ADX516_WriteReg(ADX516_MUX, Ch << 4 | 0X0F);
  ADX516_Command(ADX516_SYNC);
  ADX516_Command(ADX516_WAKEUP);
  // rt_thread_mdelay(1);
	osDelay(1);
	for (uint32_t i =0;i<times;i++){
		ADX516_READ(4, TxData, (uint8_t *)&Rxdata[i]);
		Rxdata[i] &=0x00FFFFFF;
		HAL_Delay(3);
	}
}

void ADX516_READ(uint32_t len, uint8_t *wdata, uint8_t *rdata)
{
  uint8_t buff;
  uint16_t timeout = 10;
  uint8_t RES = 0;
  ADX516_CS_H;
  ADX516_CLK_L;
  HAL_Delay(1);
//  ADX516_CS_L;
//  while(ADX516_DRDY);
  ADX516_CS_L;
  while (timeout--)
    ;
  for (uint32_t Num = 0; Num < len; Num++)
  {
    buff = wdata[Num];
		RES = 0;
    for (int i = 7; i >= 0; i--)
    {
      ADX516_CLK_H;
      if (buff & (0x01 << i))
        ADX516_DIN_H;
      else
        ADX516_DIN_L;
			timeout = 2;
      while (timeout--)
        ;
			if(ADX516_SDO)
				RES |= (0x1 << i);
			timeout = 3;
      while (timeout--)
        ;			
      ADX516_CLK_L;
      timeout = 8;
      while (timeout--)
        ;
    }
			rdata[len-Num-1]=RES;
  }
}

void ADX516_WRITE(uint32_t len, uint8_t *wdata)
{
  uint8_t buff;
  uint16_t timeout = 10;
  uint32_t RES = 0;
  ADX516_CS_H;
  ADX516_CLK_L;
  HAL_Delay(1);
  ADX516_CS_L;
  // while(ADX516_SDO);
  // ADX516_CS_L;
  while (timeout--)
    ;
  for (uint32_t Num = 0; Num < len; Num++)
  {
    buff = wdata[Num];
    for (int i = 7; i >= 0; i--)
    {
			if (buff & (0x01 << i))
        ADX516_DIN_H;
      else
        ADX516_DIN_L;
      ADX516_CLK_H;
			timeout = 5;
      while (timeout--)
        ;     
      ADX516_CLK_L;
			timeout = 5;
      while (timeout--)
        ;
    }
  }
  HAL_Delay(1);
  ADX516_CS_H;
}
/*
    Analogysemi xutong
    2023/02/15
*/
#include "main.h"

#ifndef __ADX516_H
#define __ADX516_H
/*
    device 需要先写入SDTAC 启动寄存器写入才可以对寄存器进行操作
    在此之前需要检查PWDN以及Reset引脚的状态是否为 高
    在操作完寄存器后,需要发送RDATAC 才能连续 读取数据
    bsp_lpspi 的接口函数如下:
    Lpspi_Write(uint8_t datasize,uint8_t *data);
    Lpspi_Read(uint8_t datasize,uint8_t *data,uint8_t *Rxdata);


    注意:
        Lpspi的时序并不一定满足ADX516的配置,以下配置经过验证
        
        lpspi_master_config_t config;
        LPSPI_MasterGetDefaultConfig(&config);
        config.whichPcs=kLPSPI_Pcs0;
        config.baudRate=50000;
        config.betweenTransferDelayInNanoSec = 1000000000 /500;
        config.pcsToSckDelayInNanoSec=1000000000 /500;
        config.lastSckToPcsDelayInNanoSec=1000000000 /500;
        config.cpha=kLPSPI_ClockPhaseSecondEdge;
        LPSPI_MasterInit(LPSPI3, &config, LPSPI3_CLOCK_FREQ);

*/

/*command define*/
#define ADX516_REF 2.5
#define ADX516_PGA 1
#define ADX516_LSB (2*ADX516_REF)/(ADX516_PGA*8388607)

#define ADX516_WAKEUP 0x00
#define ADX516_RDATA   0x01
#define ADX516_RDATAC  0x03
#define ADX516_SDATAC  0x0F
#define ADX516_RREG    0x10
#define ADX516_WREG    0X50
#define ADX516_SELFCAL 0XF0
#define ADX516_SELFOCAL 0XF1
#define ADX516_SELFGCAL 0XF2
#define ADX516_SYSOCAL 0XF3
#define ADX516_SYSGCAL 0XF4
#define ADX516_SYNC     0XFC
#define ADX516_STANDBY 0xFD
#define ADX516_RESET   0xFE



//RREG Read n nnnn registers starting at address r rrrr 
//First Byte 001r rrrr (2xh)
//Second Byte 000n nnnn 
//n nnnn = number of registers to be read or written – 1. For example, to read or write three registers, set n nnnn = 0 (0010). r rrrr = the
//starting register address for read and write commands
//WREG 同上




/*
    寄存器定义
*/
#define  ADX516_STATUS 0x00
#define  ADX516_MUX 0x01
#define  ADX516_ADCON 0x02
#define  ADX516_DRATE 0x03
#define  ADX516_IO 0x04
#define  ADX516_OFC0 0x05
#define  ADX516_OFC1 0x06
#define  ADX516_OFC2 0x07
#define  ADX516_FSC0 0x08
#define  ADX516_FSC1 0x09
#define  ADX516_FSC2 0x0A
#define  ADX516_CFG0 0x0B
#define  ADX516_CFG1 0x0C
#define  ADX516_CFG2 0x0D
#define  ADX516_CFG3 0x0E
#define  ADX516_CFG4 0x0F
#define  ADX516_CFG5 0x10
#define  ADX516_DEV_CFG 0x11
#define  ADX516_MOD_STAT 0x12
#define  ADX516_DEV_STAT 0x13
#define  ADX516_CMD_STAT 0x14





#define ADX516_CLK_PORT GPIOB
#define ADX516_CLK_PIN GPIO_PIN_15

#define ADX516_REST_PORT GPIOD
#define ADX516_REST_PIN GPIO_PIN_12

//#define ADX516_SYN_PORT GPIOB
//#define ADX516_SYN_PIN GPIO_PIN_14

#define ADX516_CS_PORT GPIOB
#define ADX516_CS_PIN GPIO_PIN_14

#define ADX516_DIN_PORT GPIOD
#define ADX516_DIN_PIN GPIO_PIN_11

#define ADX516_DRDY_PORT GPIOA
#define ADX516_DRDY_PIN GPIO_PIN_11

#define ADX516_DO_PORT GPIOG
#define ADX516_DO_PIN GPIO_PIN_9

#define ADX516_SDO   (ADX516_DO_PORT->IDR & ADX516_DO_PIN)
#define ADX516_DRDY   HAL_GPIO_ReadPin(ADX516_DRDY_PORT,ADX516_DRDY_PIN)
#define ADX516_PWD_H  HAL_GPIO_WritePin(ADX516_SYN_PORT,ADX516_SYN_PIN,GPIO_PIN_SET)
#define ADX516_PWD_L  HAL_GPIO_WritePin(ADX516_SYN_PORT,ADX516_SYN_PIN,GPIO_PIN_SET)

#define ADX516_CS_H   HAL_GPIO_WritePin(ADX516_CS_PORT,ADX516_CS_PIN,GPIO_PIN_SET)
#define ADX516_CLK_H  HAL_GPIO_WritePin(ADX516_CLK_PORT,ADX516_CLK_PIN,GPIO_PIN_SET)
#define ADX516_SYN_H  HAL_GPIO_WritePin(ADX516_SYN_PORT,ADX516_SYN_PIN,GPIO_PIN_SET)
#define ADX516_DIN_H  HAL_GPIO_WritePin(ADX516_DIN_PORT,ADX516_DIN_PIN,GPIO_PIN_SET)
#define ADX516_REST_H HAL_GPIO_WritePin(ADX516_REST_PORT,ADX516_REST_PIN,GPIO_PIN_SET)

#define ADX516_CS_L   HAL_GPIO_WritePin(ADX516_CS_PORT,ADX516_CS_PIN,GPIO_PIN_RESET)
#define ADX516_CLK_L  HAL_GPIO_WritePin(ADX516_CLK_PORT,ADX516_CLK_PIN,GPIO_PIN_RESET)
#define ADX516_SYN_L  HAL_GPIO_WritePin(ADX516_SYN_PORT,ADX516_SYN_PIN,GPIO_PIN_RESET)
#define ADX516_DIN_L  HAL_GPIO_WritePin(ADX516_DIN_PORT,ADX516_DIN_PIN,GPIO_PIN_RESET)
#define ADX516_REST_L HAL_GPIO_WritePin(ADX516_REST_PORT,ADX516_REST_PIN,GPIO_PIN_RESET)
/*
  通道配置
  channel config
*/
#define ADX516_ADC_CH0
#pragma anon_unions
typedef  union
{
	uint32_t data;
	struct 
	{
		uint8_t BYTE;
		uint8_t B_W_R;
	  uint8_t ADDR;
		uint8_t A_W_R;
	};
}ADX516_RCOMMAND_TYPE;
typedef  union
{
	uint32_t data[2];
	struct 
	{
		uint16_t IO_DATA;
		uint16_t DATA;
		uint8_t BYTE;
		uint8_t B_W_R;
	  uint8_t ADDR;
		uint8_t A_W_R;
	};
}ADX516_WCOMMAND_TYPE;

//写命令
void ADX516_Command(uint8_t Com);
//获取芯片的ID号
extern uint8_t ADX516_GetChipID(void);

//获取寄存器值
uint8_t ADX516_GetReg(uint8_t Rreg);
//获取多个寄存器值
void ADX516_ReadMultiReg(uint8_t StartReg,uint8_t RegNum,uint8_t *Data);
//写入寄存器值
extern void ADX516_WriteReg(uint8_t Wreg,uint8_t Data);
//写多个寄存器的值
extern void ADX516_WriteMultiReg(uint8_t StartReg,uint8_t RegNum,uint8_t *Data);
//获取所有寄存器值
extern void ADX516_GetAllReg(void);
//设定通道并且获取ADC的值
extern void ADX516_GetADC_Value(uint8_t Ch, uint32_t *Rxdata,uint32_t times);
//初始化ADX516
extern void ADX516_Init(void);
#endif

ADX516的驱动,eeworld备份

此帖出自stm32/stm8论坛

最新回复

用STM32的驱动SDK就可以了啊 何必那么麻烦呢?哈哈   详情 回复 发表于 2023-9-7 19:41
点赞 关注(1)
个人签名

希望做一些大家觉得好用的东西!

 

回复
举报

2642

帖子

6

TA的资源

五彩晶圆(初级)

来自 7楼
 
本帖最后由 xutong 于 2024-3-20 17:27 编辑

简要说明:

 

ADX51X 读取数据时候 CS 必须全程拉低

 

 

驱动更新:

/*
  analogysemi
  xutong 2024/1/23
*/
#ifndef __BSP_LPSPI_H
#define __BSP_LPSPI_H

#include "config.h"
#define SPI_SCLK(x)		P25=(x)
#define SPI_MOSI(x)		P23=(x)
#define SPI_MISO			P24
#define SPI_CS1(x)		P22=(x)                                                                                                                                                                                             
#define SPI_CS2(x)		P21=(x) 

void LPSPI_Init(void);
void Lpspi_Write(uint8_t datasize,uint8_t *datas);
void Lpspi_Read(uint8_t datasize,uint8_t *datas,uint8_t *Rxdata);

#endif /* __BSP_LPSPI_H */

#include "bsp_lpspi.h"
#include	"STC8xxxx.H"

void LPSPI_Init(void)
{
	//设置除了MISO为输入外,其他为输出模式
    P2M0 = 0xEF;  //设置P2.0~P2.7为推挽输出模式
    P2M1 = 0x10;
		
}

void SPI_Transmit_Data_mode1(uint8_t *TXData ,uint8_t Size)   //SCLK low  second edge
{
	uint8_t i,a=0,datas=0;
	for(a=0;a<Size;a++)
	{
		datas = TXData[a];
		for(i = 0;i < 8;i++)
		{
			SPI_SCLK(1);
			if(datas&(0x80))//data bit = 1
			{
					SPI_MOSI(1);//MOSI SET 1
			}
			else
			{
				SPI_MOSI(0);//MOSI SET 1
			}
			datas <<=1;
			SPI_SCLK(0);
		}
	}
}
void SPI_Receive_Data_mode1( uint8_t *TXData,uint8_t *Rxdata ,uint8_t Size)   //SCLK low  second edge
{
	uint8_t i,a,datas;
	
	for(a=0;a<Size;a++)
	{
		datas = TXData[a];
		Rxdata[a]=0;
		for(i = 0;i < 8;i++)
		{
			SPI_SCLK(1);
			if(datas&(0x80))//data bit = 1
			{
					SPI_MOSI(1);//MOSI SET 1	
			}
			else
			{
					SPI_MOSI(0);//MOSI SET 0	
			}
			datas <<=1;
 			SPI_SCLK(0);
			
			if(SPI_MISO==1)
			{
				Rxdata[a]|=(0x80 >>i);
			}
		}
	}
}

void Lpspi_Write(uint8_t datasize,uint8_t *datas)
{
  SPI_Transmit_Data_mode1(datas,datasize);
}
void Lpspi_Read(uint8_t datasize,uint8_t *datas,uint8_t *Rxdata)
{
  SPI_Receive_Data_mode1(datas,Rxdata,datasize);
}



 

 

/*
    Analogysemi xutong
    2024/03/06
*/
#include "ADX51X.h"
#include "bsp_lpspi.h"
//初始化ADX51X
void ADX51X_Init(void)
{
  GPIO_InitTypeDef  GPIO_InitStruct;
  ADX51X_PWDN_PORT_CLK_EN;
  ADX51X_RESET_PORT_CLK_EN;
  GPIO_InitStruct.Pin       = ADX51X_RESET_PIN;
  GPIO_InitStruct.Mode      = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Speed     = GPIO_SPEED_FREQ_HIGH;
  HAL_GPIO_Init(ADX51X_RESET_PORT, &GPIO_InitStruct);
  GPIO_InitStruct.Pin       = ADX51X_PWDN_PIN;
  GPIO_InitStruct.Mode      = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Speed     = GPIO_SPEED_FREQ_HIGH;
  HAL_GPIO_Init(ADX51X_PWDN_PORT, &GPIO_InitStruct);
  ADX51X_PWDN_H;
  ADX51X_RESET_H;
  //拉PWDN和RST
}
//获取芯片的ID号
//ADX51X default Value 0x20
uint8_t ADX51X_GetChipID(void)
{
    uint8_t ID;
    ID=ADX51X_GetReg(ADX51X_STATUS);
    return ID;
}
//获取芯片寄存器值
uint8_t ADX51X_GetReg(uint8_t Rreg)
{
   uint8_t TxData[3];
   uint8_t RxData[3];
    //读取命令,
    TxData[0]=ADX51X_RREG|Rreg;
    //选择要读取的寄存器
    TxData[1]=0x00;
    //读取单个寄存器
    TxData[2]=0X00;
    //开始读取
    Lpspi_Read(3,TxData,RxData);
    //返回寄存器值
    return RxData[2];
}
//写单个芯片寄存器值
void ADX51X_WriteReg(uint8_t Wreg,uint8_t Data)
{
    uint8_t TxData[3];
    //写入命令,
    TxData[0]=ADX51X_WREG|Wreg;
    //选择要写入的的寄存器
    TxData[1]=0x00;
    //读取写入寄存器
    TxData[2]=Data;
    Lpspi_Write(3,TxData);
}
//写多个芯片寄存器值
//StartReg 起始寄存器地址
//RegNum 要写的寄存器数量
//*Data  寄存器参数传入
void ADX51X_WriteMultiReg(uint8_t StartReg,uint8_t RegNum,uint8_t *Data)
{
    uint8_t TxData[32];
    uint8_t i;
    //写入命令,
    TxData[0]=ADX51X_WREG|StartReg;
    //选择要写入的的寄存器
    TxData[1]=RegNum-1;
    for(i=0;i<RegNum;i++)
    {
       //将指针数据赋值给Txdata
       TxData[2+i]=*Data;
       //指向下个数据地址
       Data++;
    }
    //最终发送多少个数据
    Lpspi_Write(2+RegNum,TxData);
}
//读多个芯片寄存器值
//StartReg 起始寄存器地址
//RegNum 要写的寄存器数量
//*Data  寄存器参数传出
void ADX51X_ReadMultiReg(uint8_t StartReg,uint8_t RegNum,uint8_t *Data)
{
    //读取寄存器
    uint8_t TxData[3];
    //读取命令,
    TxData[0]=ADX51X_RREG|StartReg;
    //选择要写入的的寄存器
    TxData[1]=RegNum-1;
    //最终接收多少个数据
     Lpspi_Read(2+RegNum,TxData,Data);
}
//打印所有寄存器地址
void ADX51X_GetAllReg(void)
{
  uint8_t i,j;
  for(i=0;i<20;i++)
  { 
    j=ADX51X_GetReg(i);
  }
}
//发送ADX51X 数据指令 如SDATAC或者RDATAC
//详情见头文件command define部分
void ADX51X_Command(uint8_t Com)
{
    uint8_t TxData[1];
		TxData[0]=Com;
    Lpspi_Write(1,TxData);
}
//设定通道并且获取adc数据
//获取ADC的值 
//ADC负接在AIN1上
void ADX51X_GetADC_Value(uint8_t AIN_P,uint8_t AIN_N,uint8_t *Rxdata)
{
  uint8_t TxData[]={0,0,0};
  // 可以在这里加DRDY的判断
  ADX51X_Command(ADX51X_SDATAC);
  ADX51X_WriteReg(ADX51X_MUX,AIN_P<<4|AIN_N);
  ADX51X_Command(ADX51X_SYNC);
  ADX51X_Command(ADX51X_WAKEUP);
  ADX51X_Command(ADX51X_RDATA);
  Lpspi_Read(3,TxData,Rxdata);  
  Lpspi_Stop();
}
/*
    Analogysemi xutong
    2023/03/06
*/
#ifndef __ADX51X_H
#define __ADX51X_H

#include "bsp_lpspi.h"


/*command define*/

#define ADX51X_WAKEUP 0x00
#define ADX51X_RDATA   0x01
#define ADX51X_RDATAC  0x03
#define ADX51X_SDATAC  0x0F
#define ADX51X_RREG    0x10
#define ADX51X_WREG    0X50
#define ADX51X_SELFCAL 0XF0
#define ADX51X_SELFOCAL 0XF1
#define ADX51X_SELFGCAL 0XF2
#define ADX51X_SYSOCAL 0XF3
#define ADX51X_SYSGCAL 0XF4
#define ADX51X_SYNC     0XFC
#define ADX51X_STANDBY 0xFD
#define ADX51X_RESET   0xFE

/*ADX51X Pin Define*/
#define ADX51X_PWDN_PORT_CLK_EN                __HAL_RCC_GPIOB_CLK_ENABLE()
#define ADX51X_RESET_PORT_CLK_EN               __HAL_RCC_GPIOB_CLK_ENABLE()

#define ADX51X_PWDN_PIN                GPIO_PIN_5
#define ADX51X_PWDN_PORT               GPIOB
#define ADX51X_RESET_PIN               GPIO_PIN_6
#define ADX51X_RESET_PORT              GPIOB

#define ADX51X_PWDN_H   HAL_GPIO_WritePin(ADX51X_PWDN_PORT,ADX51X_PWDN_PIN,GPIO_PIN_SET);
#define ADX51X_PWDN_L   HAL_GPIO_WritePin(ADX51X_PWDN_PORT,ADX51X_PWDN_PIN,GPIO_PIN_RESET);

#define ADX51X_RESET_H  HAL_GPIO_WritePin(ADX51X_RESET_PORT,ADX51X_RESET_PIN,GPIO_PIN_SET);
#define ADX51X_RESET_L  HAL_GPIO_WritePin(ADX51X_RESET_PORT,ADX51X_RESET_PIN,GPIO_PIN_RESET);

//RREG Read n nnnn registers starting at address r rrrr 
//First Byte 001r rrrr (2xh)
//Second Byte 000n nnnn 
//n nnnn = number of registers to be read or written – 1. For example, to read or write three registers, set n nnnn = 0 (0010). r rrrr = the
//starting register address for read and write commands
//WREG 同上




/*
    寄存器定义
*/
#define  ADX51X_STATUS 0x00
#define  ADX51X_MUX 0x01
#define  ADX51X_ADCON 0x02
#define  ADX51X_DRATE 0x03
#define  ADX51X_IO 0x04
#define  ADX51X_OFC0 0x05
#define  ADX51X_OFC1 0x06
#define  ADX51X_OFC2 0x07
#define  ADX51X_FSC0 0x08
#define  ADX51X_FSC1 0x09
#define  ADX51X_FSC2 0x0A
#define  ADX51X_CFG0 0x0B
#define  ADX51X_CFG1 0x0C
#define  ADX51X_CFG2 0x0D
#define  ADX51X_CFG3 0x0E
#define  ADX51X_CFG4 0x0F
#define  ADX51X_CFG5 0x10
#define  ADX51X_DEV_CFG 0x11
#define  ADX51X_MOD_STAT 0x12
#define  ADX51X_DEV_STAT 0x13
#define  ADX51X_CMD_STAT 0x14


#define ADX51X_AIN0 0
#define ADX51X_AIN1 1
#define ADX51X_AIN2 2
#define ADX51X_AIN3 3
#define ADX51X_AIN4 4
#define ADX51X_AIN5 5
#define ADX51X_AIN6 6
#define ADX51X_AIN7 7
#define ADX51X_AIN_COM 8



/*
  通道配置
  channel config
*/
#define ADX51X_ADC_CH(x)	x	
#define DRDY_PIN	P00
//写命令
void ADX51X_Command(uint8_t Com);
//获取芯片的ID号
uint8_t ADX51X_GetChipID(void);

//获取寄存器值
uint8_t ADX51X_GetReg(uint8_t Rreg);
//获取多个寄存器值
void ADX51X_ReadMultiReg(uint8_t StartReg,uint8_t RegNum,uint8_t *Data);
//写入寄存器值
void ADX51X_WriteReg(uint8_t Wreg,uint8_t Data);
//写多个寄存器的值
void ADX51X_WriteMultiReg(uint8_t StartReg,uint8_t RegNum,uint8_t *Data);
//获取所有寄存器值
void ADX51X_GetAllReg(void);
//设定通道并且获取ADC的值

void ADX51X_GetADC_Value(uint8_t AIN_P,uint8_t AIN_N,uint8_t *Rxdata);
//初始化ADX51X
void ADX51X_Init(void);
#endif

 

此帖出自stm32/stm8论坛
 
个人签名

希望做一些大家觉得好用的东西!

 

回复

7046

帖子

11

TA的资源

版主

沙发
 

楼主可以分享一下ADX516的基本参数,在.H中的宏定义可以标注寄存器的具体定义,这样拿到驱动后就会知道为什么这样做了。

此帖出自stm32/stm8论坛

点评

下次写的时候更新下,现在先把这些东西搬运过来  详情 回复 发表于 2023-9-7 13:44
 
 

回复

2642

帖子

6

TA的资源

五彩晶圆(初级)

板凳
 
lugl4313820 发表于 2023-9-7 12:52 楼主可以分享一下ADX516的基本参数,在.H中的宏定义可以标注寄存器的具体定义,这样拿到驱动后就会知道为什 ...

下次写的时候更新下,现在先把这些东西搬运过来

此帖出自stm32/stm8论坛
 
个人签名

希望做一些大家觉得好用的东西!

 
 

回复

119

帖子

0

TA的资源

一粒金砂(中级)

4
 

用STM32的驱动SDK就可以了啊

此帖出自stm32/stm8论坛
 
 
 

回复

119

帖子

0

TA的资源

一粒金砂(中级)

5
 

用STM32的驱动SDK就可以了啊 何必那么麻烦呢?哈哈

此帖出自stm32/stm8论坛

点评

还有很多人用的不是STM32 方便移植  详情 回复 发表于 2023-9-7 21:01
 
 
 

回复

2642

帖子

6

TA的资源

五彩晶圆(初级)

6
 
wang12011201 发表于 2023-9-7 19:41 用STM32的驱动SDK就可以了啊 何必那么麻烦呢?哈哈

还有很多人用的不是STM32 方便移植

此帖出自stm32/stm8论坛
 
个人签名

希望做一些大家觉得好用的东西!

 
 

回复
您需要登录后才可以回帖 登录 | 注册

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/7 下一条

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表