/*
Analogysemi xutong
2023/02/15
*/
#include "ADX3208.h"
#include "board.h"
#include "bsp_lpspi.h"
#include "rtthread.h"
//初始化ADX3208
void ADX3208_Init(void)
{
// START_L;
// XTAL_H;
// PWDN_H;
// RST_H;
// rt_thread_mdelay(150);
// RST_L;
// rt_thread_mdelay(1);
// RST_H;
}
//獲取芯片的ID號
uint8_t ADX3208_GetChipID(void)
{
uint8_t ID;
ID=ADX3208_GetReg(ADX3208_ID);
return ID;
}
//獲取芯片寄存器值
uint8_t ADX3208_GetReg(uint8_t Rreg)
{
uint8_t TxData[3];
uint8_t RxData[3];
//讀取命令,
TxData[0]=ADX3208_RREG|Rreg;
//選擇要讀取的寄存器
TxData[1]=0x00;
//讀取單個寄存器
TxData[2]=0X00;
//開始讀取
Lpspi_Read(3,TxData,RxData);
//返回寄存器值
return RxData[2];
}
//寫單個芯片寄存器值
void ADX3208_WriteReg(uint8_t Wreg,uint8_t Data)
{
uint8_t TxData[3];
//寫入命令,
TxData[0]=ADX3208_WREG|Wreg;
//選擇要寫入的的寄存器
TxData[1]=0x00;
//讀取寫入寄存器
TxData[2]=Data;
Lpspi_Write(3,TxData);
}
//寫多個芯片寄存器值
//StartReg 起始寄存器地址
//RegNum 要寫的寄存器數(shù)量
//*Data 寄存器參數(shù)傳入
void ADX3208_WriteMultiReg(uint8_t StartReg,uint8_t RegNum,uint8_t *Data)
{
uint8_t TxData[32];
uint8_t i;
//寫入命令,
TxData[0]=ADX3208_WREG|StartReg;
//選擇要寫入的的寄存器
TxData[1]=RegNum-1;
for(i=0;i< RegNum;i++)
{
//將指針數(shù)據(jù)賦值給Txdata
TxData[2+i]=*Data;
//指向下個數(shù)據(jù)地址
Data++;
}
//最終發(fā)送多少個數(shù)據(jù)
Lpspi_Write(2+RegNum,TxData);
}
//讀多個芯片寄存器值
//StartReg 起始寄存器地址
//RegNum 要寫的寄存器數(shù)量
//*Data 寄存器參數(shù)傳出
void ADX3208_ReadMultiReg(uint8_t StartReg,uint8_t RegNum,uint8_t *Data)
{
//讀取寄存器
uint8_t TxData[3];
//讀取命令,
TxData[0]=ADX3208_RREG|StartReg;
//選擇要寫入的的寄存器
TxData[1]=RegNum-1;
//最終接收多少個數(shù)據(jù)
Lpspi_Read(2+RegNum,TxData,Data);
}
//打印所有寄存器地址
void ADX3208_GetAllReg(void)
{
uint8_t i,j;
for(i=0;i< 24;i++)
{
j=ADX3208_GetReg(i);
//打印所有寄存器值
//rt_kprintf("reg addr: %d reg default Value: %xrn",i,j);
}
}
//發(fā)送ADX3208 數(shù)據(jù)指令 如SDATAC或者RDATAC
//詳情見頭文件command define部分
void ADX3208_Command(uint8_t Com)
{
uint8_t TxData[]={Com};
Lpspi_Write(1,TxData);
}
//獲取ADC的值
//數(shù)據(jù)一共216位 / 152位
//24位狀態(tài)位 1100 FaultStatusP[7:0] FaultStatusN[7:0] GPIO[7:4]
//8通道*ADC位數(shù) 數(shù)據(jù)
void ADX3208_GetADC_Value(uint8_t ADC_Resolution,uint8_t *Rxdata)
{
if (ADC_Resolution==16)
{
Lpspi_Read(152,NULL,Rxdata);
}
else
{
Lpspi_Read(216,NULL,Rxdata);
}
}
以上是.c文件
/*
Analogysemi xutong
2023/02/15
*/
#ifndef __ADX3208_H
#define __ADX3208_H
#include "bsp_lpspi.h"
/*
device 需要先寫入SDTAC 啟動寄存器寫入才可以對寄存器進行操作
在此之前需要檢查PWDN以及Reset引腳的狀態(tài)是否為 高
在操作完寄存器后,需要發(fā)送RDATAC 才能連續(xù) 讀取數(shù)據(jù)
bsp_lpspi 的接口函數(shù)如下:
Lpspi_Write(uint8_t datasize,uint8_t *data);
Lpspi_Read(uint8_t datasize,uint8_t *data,uint8_t *Rxdata);
注意:
Lpspi的時序并不一定滿足ADX3208的配置,以下配置經(jīng)過驗證
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 ADX3208_WAKEUP 0x20
#define ADX3208_STANDBY 0x04
#define ADX3208_RESET 0x06
#define ADX3208_START 0x08
#define ADX3208_STOP 0x0a
#define ADX3208_OFFSETCAL 0x1a
#define ADX3208_RDATAC 0x10
#define ADX3208_SDATAC 0x11
#define ADX3208_RDATA 0x12
//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 ADX3208_RREG 0x20
#define ADX3208_WREG 0X40
/*
寄存器定義
*/
#define ADX3208_ID 0x00
#define ADX3208_CONFIG1 0x01
#define ADX3208_CONFIG2 0x02
#define ADX3208_CONFIG3 0x03
#define ADX3208_LOFF 0x04
#define ADX3208_CH1SET 0x05
#define ADX3208_CH2SET 0x06
#define ADX3208_CH3SET 0x07
#define ADX3208_CH4SET 0x08
#define ADX3208_CH5SET 0x09
#define ADX3208_CH6SET 0x0A
#define ADX3208_CH7SET 0x0B
#define ADX3208_CH8SET 0x0C
#define ADX3208_OPAMP_SENSP 0x0D
#define ADX3208_OPAMP_SENSN 0x0E
#define ADX3208_LOFF_SENSP 0x0F
#define ADX3208_LOFF_SENSN 0x10
#define ADX3208_LOFF_FLIP 0x11
#define ADX3208_LOFF_STATP 0x12
#define ADX3208_LOFF_STATN 0x13
#define ADX3208_GPIO 0x14
/*
寄存器Deafult 值
寄存器地址10進制:寄存器值16進制:
reg addr: 0 reg default Value: 0e
reg addr: 1 reg default Value: 91
reg addr: 2 reg default Value: e0
reg addr: 3 reg default Value: 40
reg addr: 4 reg default Value: 00
reg addr: 5 reg default Value: 10
reg addr: 6 reg default Value: 10
reg addr: 7 reg default Value: 10
reg addr: 8 reg default Value: 10
reg addr: 9 reg default Value: 10
reg addr: 10 reg default Value: 10
reg addr: 11 reg default Value: 10
reg addr: 12 reg default Value: 10
reg addr: 13 reg default Value: 00
reg addr: 14 reg default Value: 00
reg addr: 15 reg default Value: 00
reg addr: 16 reg default Value: 00
reg addr: 17 reg default Value: 00
reg addr: 18 reg default Value: 00
reg addr: 19 reg default Value: 00
reg addr: 20 reg default Value: 0f
reg addr: 21 reg default Value: 00
reg addr: 22 reg default Value: 00
reg addr: 23 reg default Value: 00
*/
#define ADX3208_ADC_Resolution_16 16
#define ADX3208_ADC_Resolution_24 24
//寫命令
void ADX3208_Command(uint8_t Com);
//獲取芯片的ID號
uint8_t ADX3208_GetChipID(void);
//獲取寄存器值
uint8_t ADX3208_GetReg(uint8_t Rreg);
//獲取多個寄存器值
void ADX3208_ReadMultiReg(uint8_t StartReg,uint8_t RegNum,uint8_t *Data);
//寫入寄存器值
void ADX3208_WriteReg(uint8_t Wreg,uint8_t Data);
//寫多個寄存器的值
void ADX3208_WriteMultiReg(uint8_t StartReg,uint8_t RegNum,uint8_t *Data);
//獲取所有寄存器值
void ADX3208_GetAllReg(void);
//獲取ADC的值
void ADX3208_GetADC_Value(uint8_t ADC_Resolution,uint8_t *Rxdata);
//初始化ADX3208
void ADX3208_Init(void);
#endif
以上是.h文件
評論
查看更多