DR7808 配置笔记

CSA部分:

内部CSA可以配置为单向,或者双向,一共有两个CSA,内部CSA的GAIN可以配置,挡位有10,20,40,80四种增益选项。

也可以直接关闭内部CSA,CSA的过流保护值和过流保护滤波时间都可以单独设置。

相关寄存器:

DR7808_GENCTRL1

DR7808_HBIDIAG

DR7808_GENCTRL2

DR7808_CSA_OC_SH

寄存器相关描述:

 

 

 

相关头文件如下:


/*
    Analogysemi xutong
    2023/10/10
*/
#ifndef __DR7808_H
#define __DR7808_H
#include "bsp_lpspi.h"

/*
   DR7808 SPI每个帧是24bit数据组成
 
*/


#define DR7808_GENCTRL1 0x00
#define DR7808_GENCTRL2 0x01
#define DR7808_VDS1 0x02
#define DR7808_VDS2 0x03
#define DR7808_CCP_BLK1 0x04

#define DR7808_CCP_BLK2_ACT 0x05        //需要配置reg bank =0
#define DR7808_CCP_BLK2_FW 0x05         //需要配置reg bank =1

#define DR7808_HBMODE 0x06
#define DR7808_PWMSET 0x07
#define DR7808_TPRECHG 0x08
#define DR7808_HBIDIAG 0x09

#define DR7808_ST_ICHG 0x0A                     //需要配置reg bank =0
#define DR7808_PWM_PCHG_INIT 0x0A               //需要配置reg bank =1
#define DR7808_PWM_ICHG_ACT 0x0B                //需要配置reg bank =0
#define DR7808_PWM_ICHG_FW 0x0B                 //需要配置reg bank =1
#define DR7808_PWM_IDCHG_ACT 0x0C               //需要配置reg bank =0
#define DR7808_PWM_PDCHG_INIT 0x0C              //需要配置reg bank =1
#define DR7808_PWM_ICHGMAX_CCP_BLK3_ACT 0x0D    //需要配置reg bank =0
#define DR7808_PWM_ICHGMAX_CCP_BLK3_FW 0x0D     //需要配置reg bank =1


#define DR7808_TDON_OFF1 0x0E
#define DR7808_TDON_OFF2 0x0F
#define DR7808_TDON_OFF3 0x10
#define DR7808_GENSTAT 0x11
#define DR7808_DSOV 0x12
#define DR7808_HBVOUT_PWMERR 0x13
#define DR7808_EFF_TDON_OFF1 0x14
#define DR7808_EFF_TDON_OFF2 0x15
#define DR7808_EFF_TDON_OFF3 0x16
#define DR7808_TRISE_FALL1 0x17
#define DR7808_TRISE_FALL2 0x18
#define DR7808_TRISE_FALL3 0x19
#define DR7808_DEVID 0x1F
#define DR7808_DRV_LPWR_EN 0x1C
#define DR7808_CSA_OC_SH 0x1D
#define DR7808_MISC 0x1E

#define DR7808_GENSTAT 0x11
#define DR7808_DSOV 0x12
#define DR7808_HBVOUT_PWMERR 0x13
#define DR7808_EFF_TDON_OFF1 0x14
#define DR7808_EFF_TDON_OFF2 0x15
#define DR7808_EFF_TDON_OFF3 0x16
#define DR7808_TRISE_FALL 0x17
#define DR7808_TRISE_FALL2 0x18
#define DR7808_TRISE_FALL3 0x19
#define DR7808_GDF 0x1A
#define DR7808_DEVID 0x1F





//注意 DR7808 不同寄存器有不同Bank
//Note DR7808 has different banks for different registers


// DR7808 half bridge config
// DR7808 半桥配置
enum DR7808_HB_Mode{HighImpedance=0,LSn_ON=1,HSn_ON=2};
typedef struct{
  uint8_t HB8_Mode;
  uint8_t HB7_Mode;
  uint8_t HB6_Mode;  
  uint8_t HB5_Mode;  
  uint8_t HB4_Mode;
  uint8_t HB3_Mode;
  uint8_t HB2_Mode;
  uint8_t HB1_Mode;
}HBMODE_InitTypeDef;

// DR7808 PWM Setting
// DR7808 PWM 设置
enum DR7808_PWM_HB{HB1=0,HB2=1,HB3=2,HB4=3,HB5=4,HB6=5,HB7=6,HB8=7};
typedef struct{
  uint8_t PWM1_HB;
  uint8_t PWM2_HB;
  uint8_t PWM3_HB;  
  uint8_t PWM1_EN;  
  uint8_t PWM2_EN;
  uint8_t PWM3_EN;
//Drain-Source monitoring in bridge passive mode
//漏源监控在桥被动模式
  uint8_t PASS_VDS;
//Settings for bridge driver passive mode
//00B: LS1-4 are always off.
//Note: Changing PASS_MOD from
//00B: to any other value requires to clear DSOV1) first before writing PASS_MOD,
//01B: LS1-4 are always on (static brake).
//10B: LS1-4 are activated if passive VM OV is detected (overvoltage brake) (default).
//11B: LS1-4 are activated if passive VM OV is detected and PWM1 = High (overvoltage brake conditioned by PWM1).
  uint8_t PASS_Mode;
}PWMSET_InitTypeDef;

// half bridge Vds threshold Setting
// 半桥Vds阈值设定
/*
    000B: 0.15V
    001B: 0.20V (default)
    010B: 0.25V
    011B: 0.30V
    100B: 0.40V
    101B: 0.50V
    110B: 0.60V
    111B: 2.0V
*/

enum DR7808_HB_VDSTh{Vdsth_15=0,Vdsth_20=1,Vdsth_25=2,Vdsth_30=3,
Vdsth_40=4,Vdsth_50=5,Vdsth_60=6,Vdsth2_0=7};
typedef struct{
  uint8_t HB8_VDSTh;
  uint8_t HB7_VDSTh;
  uint8_t HB6_VDSTh;  
  uint8_t HB5_VDSTh;  
  uint8_t HB4_VDSTh;
  uint8_t HB3_VDSTh;
  uint8_t HB2_VDSTh;
  uint8_t HB1_VDSTh;
}VDS_Vth_InitTypeDef;
// 静态电流配置
// 详情看 静态充电和放电电流表格
enum DR7808_ST_ICHG_Current{GateDriverCurrent1=0,GateDriverCurrent2=1,ICHGST1=0,ICHGST2=1,ICHGST3=2,ICHGST4=3,
ICHGST5=4,ICHGST6=5,ICHGST7=6,ICHGST8=7,ICHGST9=8,ICHGST10=9,ICHGST11=10
,ICHGST12=11,ICHGST13=12,ICHGST14=13,ICHGST15=14,ICHGST16=15,ICHGST_Default=4};
typedef struct{
  //配置是GateDriverCurrent1 还是GateDriverCurrent2
  uint8_t HB8_ICHG;
  uint8_t HB7_ICHG;
  uint8_t HB6_ICHG;  
  uint8_t HB5_ICHG;  
  uint8_t HB4_ICHG;
  uint8_t HB3_ICHG;
  uint8_t HB2_ICHG;
  uint8_t HB1_ICHG;
  //配置Gate Driver Current 2电流大小 一共16个挡位,参考Static charge and discharge currents table
  uint8_t ICHGST_2;
  //配置Gate Driver Current 1电流大小 一共16个挡位,参考Static charge and discharge currents table
  uint8_t ICHGST_1;
}ST_ICHG_InitTypeDef;


// CSA 相关配置
enum DR7808_CSA_Config{
//  CSA1_Gain and CSA2_Gain
  Gain10=0,Gain20=1,Gain40=2,Gain80=3,
//  CSA1_Direction and CSA2_Direction
CSA_Unidirectional=0,CSA_Bidirectional=1,
// OCTH1 and OCTH2
OCThLevel1=0,OCThLevel2=1,
OCThLevel3=2,OCThLevel4=3,
// CSA1_SEL and CSA2_SEL
Con2HB1=0,Con2HB2=1,Con2HB3=2,Con2HB4=3,
Con2HB5=4,Con2HB6=5,Con2HB7=6,Con2HB8=7};
typedef struct{
  //配置CSA方向 CSA_Bidirectional 或者 CSA_Unidirectional
  //配置双向或者单向
  uint8_t CSA1_Direction;
  uint8_t CSA2_Direction;
  // 配置 CSA Gain的大小 10,20,40,80
  uint8_t CSA1_Gain;  
  uint8_t CSA2_Gain;  
  // 配置OCP是否开启
  uint8_t OverCurrentProtect;
  //配置CSA 在高边或者底边
  //Configure CSA on the high-side or the low-side
  uint8_t CSA1_Level;
  uint8_t CSA2_Level;
  //配置过流滤波时间
  //Overcurrent filter time
  uint8_t OC1FILT;
  uint8_t OC2FILT;
  //关闭CSA
  //DisEnable CSA 设置为1
  //Enable CSA 设置为0
  uint8_t CSA1_OFF;
  uint8_t CSA2_OFF;
  // Overcurrent detection threshold
  // 过流检测阈值设置
  uint8_t OCTH1;
  uint8_t OCTH2;
//  Overcurrent detection threshold of SO1 with CSD1 = 0
//00B: VSO1 > VDD / 2 (default)
//01B: VSO1 > VDD / 2 + VDD / 10
//10B: VSO1 > VDD / 2 + 2 x VDD / 10
//11B: VSO1 > VDD / 2 + 3x VDD / 10
//Overcurrent detection threshold of SO1 with CSD1 = 1
//00B: VSO1 > VDD / 2+2 x VDD / 20 or VCSOx < VDD / 2 – 2 × VDD / 20 (default)
//01B: VSO1 > VDD / 2+ 4x VDD / 20 or VCSOx < VDD / 2 – 4 × VDD / 20
//10B: VSO1 > VDD / 2+ 5 x VDD / 20 or VCSOx < VDD / 2 ? 5 × VDD / 20
//11B: VSO1 > VDD / 2+ 6x VDD / 20 or VCSOx < VDD / 2 – 6 × VDD / 20
  uint8_t CSA_BLK_SEL;
//1: CSA1 and CSA2 hold blank time is tccp + tblank/2
//0:CSA1 and CSA2 hold blank time is tccp + tblank(default)
// blank time 用于PWM 抑制功能时间设置
  uint8_t CSA2_SH_EN;
  uint8_t CSA1_SH_EN;
//选择是否使用PWM 抑制功能
//Select whether to use PWM suppression
  uint8_t OC_SEP_EN;
// 选择 OCEN情况下只有CSA连接的半桥turn off 还是所有半桥Turn off
  uint8_t CSA2_SEL;
  uint8_t CSA1_SEL;
// CSA SEL根据CSA连接的半桥选择
 
}CSA_InitTypeDef;


// 获取寄存器信息
void DR7808_Read_Reg(uint8_t Reg,uint8_t *RData);
// 读取并且清除寄存器
void DR7808_Read_Clear_Reg(uint8_t Reg,uint8_t *RData);
// 写入寄存器信息
void DR7808_Write_Reg(uint8_t Reg,uint16_t WData,uint8_t *RData);
// 退出FS Mode
void DR7808_Quit_FS(void);
// 禁用看门狗
void DR7808_Dis_WD(void);
// DR7808 延时
void DR7808_delay(uint32_t count);
// 桥壁设置
void DR7808_Half_Bridge_Mode(HBMODE_InitTypeDef* config,uint8_t *RData);
// PWM设置通道和DS监控被动模式配置
void DR7808_PWMSET_Channel(PWMSET_InitTypeDef* config,uint8_t *RData);
// HB VDS 监控阈值设定
// HB VDS monitoring threshold Setting
// 设置 VDS1 和 VDS2 寄存器
void DR7808_VDS_Monitoring_1_4(VDS_Vth_InitTypeDef* config,uint8_t *RData);
void DR7808_VDS_Monitoring_5_8(VDS_Vth_InitTypeDef* config,uint8_t *RData);
// 内部CSA配置
void DR7808_CSA_Conifg(CSA_InitTypeDef* config,uint8_t *RData);
// 静态充放电电流设置
void DR7808_ST_ICHG_Conifg(ST_ICHG_InitTypeDef* config,uint8_t *RData);
// DR7808 喂狗
void DR7808_Feed_Dog(uint8_t *RData);
// 获取DR7808 ID
uint8_t DR7808_GetChipID(void);
// 获取所有寄存器的值
void Get_All_Reg(uint8_t* RData);

#endif

 

#include "DR7808.h"


void DR7808_delay(uint32_t count)
{ 
    volatile uint32_t i = 0;
    for (i = 0; i < count; ++i)
    {
        __asm("NOP"); /* 调用nop空指令 */
         __asm("NOP"); /* 调用nop空指令 */
          __asm("NOP"); /* 调用nop空指令 */
           __asm("NOP"); /* 调用nop空指令 */
            __asm("NOP"); /* 调用nop空指令 */
    }
}
//获取寄存器信息
void DR7808_Read_Reg(uint8_t Reg,uint8_t *RData)
{
  uint8_t TxData[3]={0X00,0X00,0X00};
  //读取寄存器
  TxData[0]=(Reg<<1)|0xC0;
  Lpspi_Read(3,TxData,RData);
}
//读取与清除寄存器信息
void DR7808_Read_Clear_Reg(uint8_t Reg,uint8_t *RData)
{
  uint8_t TxData[3]={0X00,0X00,0X00};
  //读取寄存器
  TxData[0]=(Reg<<1)|0xC1;
  Lpspi_Read(3,TxData,RData);
}
//写寄存器信息
void DR7808_Write_Reg(uint8_t Reg,uint16_t WData,uint8_t *RData)
{
  uint8_t TxData[3]={0X00,0X00,0X00};
  //读取寄存器&写入寄存器
  TxData[0]=(Reg<<1)|0xC1;
  TxData[1]=WData>>8;
  TxData[2]=WData&0x00FF;
  Lpspi_Read(3,TxData,RData);
}
// dr7808 退出FS Mode
void DR7808_Quit_FS(void)
{
  uint8_t Data[3]={0X00,0X00,0X00};
  //读取并且清除Gensata
  DR7808_Read_Clear_Reg(DR7808_GENSTAT,Data);
  DR7808_delay(2000);
  //看门狗位置1
  DR7808_Write_Reg(DR7808_GENCTRL1,0x0027,Data);
  DR7808_delay(2000);
  //看门狗位置0
  DR7808_Write_Reg(DR7808_GENCTRL1,0x0000,Data);
  DR7808_delay(2000);
}
// dr7808 禁用看门狗
void DR7808_Dis_WD(void)
{
  uint8_t Data[3];
  DR7808_delay(2000);
  //看门狗Unlock 置1
  DR7808_Write_Reg(DR7808_GENCTRL1,0x00A7,Data);
  DR7808_delay(2000);
  //禁用看门狗
  DR7808_Write_Reg(DR7808_GENCTRL2,0x4380,Data);
}
// dr7808桥壁配置
void DR7808_Half_Bridge_Mode(HBMODE_InitTypeDef* config,uint8_t *RData)
{
  uint16_t WData=0;
  WData|=(config->HB8_Mode)<<14;
  WData|=(config->HB7_Mode)<<12;
  WData|=(config->HB6_Mode)<<10;
  WData|=(config->HB5_Mode)<<8;
  WData|=(config->HB4_Mode)<<6;
  WData|=(config->HB3_Mode)<<4;
  WData|=(config->HB2_Mode)<<2;
  WData|=(config->HB1_Mode);
  DR7808_Write_Reg(DR7808_HBMODE,WData,RData);
}
// 未测试
// dr7808 PWM 通道配置
void DR7808_PWMSET_Channel(PWMSET_InitTypeDef* config,uint8_t *RData)
{
  uint16_t WData=0;
  WData|=(config->PWM1_HB)<<1;
  WData|=(config->PWM2_HB)<<5;
  WData|=(config->PWM3_HB)<<9;
  WData|=(config->PWM1_EN);
  WData|=(config->PWM2_EN)<<4;
  WData|=(config->PWM3_EN)<<8;
  WData|=(config->PASS_VDS)<<14;
  WData|=(config->PASS_Mode)<<12;
  DR7808_Write_Reg(DR7808_PWMSET,WData,RData);
  
}
//未测试
//VDS Monitor threshold setting HB1~HB4
void DR7808_VDS_Monitoring_1_4(VDS_Vth_InitTypeDef* config,uint8_t *RData)
{
  uint16_t WData=0;
  WData|=(config->HB1_VDSTh);
  WData|=(config->HB2_VDSTh)<<3;
  WData|=(config->HB3_VDSTh)<<6;
  WData|=(config->HB4_VDSTh)<<9;
  DR7808_Write_Reg(DR7808_VDS1,WData,RData);
}
//未测试
//VDS Monitor threshold setting HB5~HB8
void DR7808_VDS_Monitoring_5_8(VDS_Vth_InitTypeDef* config,uint8_t *RData)
{
  uint16_t WData=0;
  WData|=(config->HB5_VDSTh);
  WData|=(config->HB6_VDSTh)<<3;
  WData|=(config->HB7_VDSTh)<<6;
  WData|=(config->HB8_VDSTh)<<9;
  DR7808_Write_Reg(DR7808_VDS2,WData,RData);
}
// dr7808喂狗操作
void DR7808_Feed_Dog(uint8_t *RData)
{
  uint16_t WData=0;
  uint8_t Data[3];
  //读取看门狗位
  DR7808_Read_Reg(DR7808_GENCTRL1,Data);
  DR7808_delay(20);
  //如果看门狗位为1
  if((Data[2]&0x01)==1)
  {
    //看门狗位置0并写入
    Data[2]&=0XFE;
    WData|=Data[1]<<8;
    WData|=Data[2];
    DR7808_Write_Reg(DR7808_GENCTRL1,WData,RData);
  }
  else
  {
    //看门狗位置1并写入
    Data[2]|=0X01;
    WData|=Data[1]<<8;
    WData|=Data[2];
    DR7808_Write_Reg(DR7808_GENCTRL1,WData,RData);
  }
}
// dr7808 csa相关配置
void DR7808_CSA_Conifg(CSA_InitTypeDef* config,uint8_t *RData)
{
  uint16_t WData=0;
  uint8_t Data[3];
  //读取GENCTRL1配置
  DR7808_Read_Reg(DR7808_GENCTRL1,Data);
  WData|=(config->CSA2_Direction)<<15;
  WData|=(config->CSA2_Gain)<<13;
  WData|=(config->CSA1_Direction)<<12;
  WData|=(config->CSA1_Gain)<<10;
  //接收值后十位不变
  WData|=(Data[1]&0x03)<<8;
  WData|=Data[2];
  DR7808_Write_Reg(DR7808_GENCTRL1,WData,RData);
  //清空WData
  WData=0;
  DR7808_delay(20);
  DR7808_Read_Reg(DR7808_HBIDIAG,Data);
  WData|=Data[2];
  WData|=(config->CSA2_Level)<<15;
  WData|=(config->CSA1_Level)<<14;
  WData|=(config->OC2FILT)<<12;
  WData|=(config->OC1FILT)<<10;
  WData|=(config->CSA2_OFF)<<9;
  WData|=(config->CSA1_OFF)<<8;
  DR7808_Write_Reg(DR7808_HBIDIAG,WData,RData);
    //清空WData
  WData=0;
  DR7808_delay(20);
   //读取GENCTRL2配置
  DR7808_Read_Reg(DR7808_GENCTRL2,Data);
  //清空后四位
  Data[2]&=0XF0;
  //高8位不变
  WData|=Data[1]<<8;
  WData|=Data[2];
  WData|=(config->OCTH2)<<2;
  WData|=(config->OCTH1);
  DR7808_Write_Reg(DR7808_GENCTRL2,WData,RData);
  //清空WData
  WData=0;
  DR7808_delay(20);
  //读取GENCTRL2配置
  DR7808_Read_Reg(DR7808_CSA_OC_SH,Data);
  WData=0;
  //最高位PWM不变
  WData=(Data[1]&0X80)<<8;
  WData|=(config->CSA_BLK_SEL)<<9;
  WData|=(config->CSA2_SH_EN)<<8;
  WData|=(config->CSA1_SH_EN)<<7;
  WData|=(config->OC_SEP_EN)<<6;
  WData|=(config->CSA2_SEL)<<3;
  WData|=(config->CSA1_SEL);
  //写入过流数据
  DR7808_Write_Reg(DR7808_CSA_OC_SH,WData,RData);
}
// 需要配置Reg Bank
// 静态充放电电流设置
void DR7808_ST_ICHG_Conifg(ST_ICHG_InitTypeDef* config,uint8_t *RData)
{
  uint16_t WData=0;
  uint8_t Data[3];
 // 读取DR7808_GENCTRL1配置 并将REG BANK 其配置为0
  DR7808_Read_Reg(DR7808_GENCTRL1,Data);
  Data[1]=Data[1]&0xfd;
  WData=Data[1]<<8;
  WData|=Data[2];
  //写入reg bank
  DR7808_Write_Reg(DR7808_GENCTRL1,WData,RData);
  DR7808_delay(20);
  WData=0;
  //设置是电流1还是电流2
  WData|=(config->HB8_ICHG)<<15;
  WData|=(config->HB7_ICHG)<<14;
  WData|=(config->HB6_ICHG)<<13;
  WData|=(config->HB5_ICHG)<<12;
  WData|=(config->HB4_ICHG)<<11;
  WData|=(config->HB3_ICHG)<<10;
  WData|=(config->HB2_ICHG)<<9;
  WData|=(config->HB1_ICHG)<<8;
  //设置电流挡位2
  WData|=(config->ICHGST_2)<<4;
  //设置电流挡位1
  WData|=(config->ICHGST_1);
  //写入电流挡位
  DR7808_Write_Reg(DR7808_ST_ICHG,WData,RData);
}
// dr7808 ID获取
uint8_t DR7808_GetChipID(void)
{
  uint8_t Data[3];
  DR7808_Read_Reg(DR7808_DEVID,Data);
  return Data[2];
}
//读取所有寄存器
void Get_All_Reg(uint8_t* RData)
{
  uint8_t i=0;
  for(i=0;i<0x1f;i++)
  {
    DR7808_Read_Reg(i,RData);
    RData++;
    DR7808_delay(330);
  }
  
}

 

 

 

DR7808退出Fail Safe:

 

// dr7808 退出FS Mode 经过验证
void DR7808_Quit_FS(void)
{
  uint8_t Data[3]={0X00,0X00,0X00};
  //读取并且清除Gensata
  DR7808_Read_Clear_Reg(DR7808_GENSTAT,Data);
  DR7808_delay(2000);
  //看门狗位置1
  DR7808_Write_Reg(DR7808_GENCTRL1,0x0027,Data);
  DR7808_delay(2000);
  //看门狗位置0
  DR7808_Write_Reg(DR7808_GENCTRL1,0x0000,Data);
  DR7808_delay(2000);
}

 

DR7808关闭看门狗:

 

// dr7808 禁用看门狗 经过验证
void DR7808_Dis_WD(void)
{
  uint8_t Data[3];
  DR7808_delay(2000);
  //看门狗Unlock 置1
  DR7808_Write_Reg(DR7808_GENCTRL1,0x00A7,Data);
  DR7808_delay(2000);
  //禁用看门狗
  DR7808_Write_Reg(DR7808_GENCTRL2,0x4380,Data);
}

 

DR7808设置HBMode:

HBMODE_InitTypeDef HBinit;
HBinit.HB8_Mode=HSn_ON;
HBinit.HB7_Mode=HighImpedance;
HBinit.HB6_Mode=HSn_ON;
HBinit.HB5_Mode=HighImpedance;
HBinit.HB4_Mode=LSn_ON;
HBinit.HB3_Mode=HighImpedance;
HBinit.HB2_Mode=LSn_ON;
HBinit.HB1_Mode=HighImpedance;
DR7808_Half_Bridge_Mode(&HBinit,RegData);

DR7808设置PWM SET:

 

// PWM 设置桥壁
PWMSET_InitTypeDef PWMinit;
// PWM2 和 PWM3 同样的设置方法
PWMinit.PWM1_EN=1;
PWMinit.PWM1_HB=HB6;
DR7808_PWMSET_Channel(&PWMinit,RegData);

 

DR7808设置VDS 监控阈值:

 

//设置VDS监控阈值
// half bridge Vds threshold Setting
// 半桥Vds阈值设定
/*
    000B: 0.15V
    001B: 0.20V (default)
    010B: 0.25V
    011B: 0.30V
    100B: 0.40V
    101B: 0.50V
    110B: 0.60V
    111B: 2.0V
*/
VDS_Vth_InitTypeDef VDS_ThInit;
VDS_ThInit.HB1_VDSTh=Vdsth2_0;
VDS_ThInit.HB2_VDSTh=Vdsth2_0;
VDS_ThInit.HB3_VDSTh=Vdsth2_0;
VDS_ThInit.HB4_VDSTh=Vdsth2_0;
VDS_ThInit.HB5_VDSTh=Vdsth2_0;
VDS_ThInit.HB6_VDSTh=Vdsth2_0;
VDS_ThInit.HB7_VDSTh=Vdsth2_0;
VDS_ThInit.HB8_VDSTh=Vdsth2_0;
DR7808_VDS_Monitoring_1_4(&VDS_ThInit,RegData);
DR7808_VDS_Monitoring_5_8(&VDS_ThInit,RegData);

 

DR7808读取所有寄存器:

 

Get_All_Reg(RData);

 

DR7808 CSA相关配置:

 

//关闭CSA
CSA_InitTypeDef CSA_Init;
 // 关闭CSA1  和CSA2
CSA_Init.CSA1_OFF=1;
CSA_Init.CSA2_OFF=1;

DR7808_CSA_Conifg(&CSA_Init,RegData);
/*
// CSA 结构体
typedef struct{
  //配置CSA方向 CSA_Bidirectional 或者 CSA_Unidirectional
  //配置双向或者单向
  uint8_t CSA1_Direction;
  uint8_t CSA2_Direction;
  // 配置 CSA Gain的大小 10,20,40,80
  uint8_t CSA1_Gain;  
  uint8_t CSA2_Gain;  
  // 配置OCP是否开启
  uint8_t OverCurrentProtect;
  //配置CSA 在高边或者底边
  //Configure CSA on the high-side or the low-side
  uint8_t CSA1_Level;
  uint8_t CSA2_Level;
  //配置过流滤波时间
  //Overcurrent filter time
  uint8_t OC1FILT;
  uint8_t OC2FILT;
  //关闭CSA
  //DisEnable CSA 设置为1
  //Enable CSA 设置为0
  uint8_t CSA1_OFF;
  uint8_t CSA2_OFF;
  // Overcurrent detection threshold 
  // 过流检测阈值设置
  uint8_t OCTH1;
  uint8_t OCTH2;
//  Overcurrent detection threshold of SO1 with CSD1 = 0
//00B: VSO1 > VDD / 2 (default)
//01B: VSO1 > VDD / 2 + VDD / 10
//10B: VSO1 > VDD / 2 + 2 x VDD / 10
//11B: VSO1 > VDD / 2 + 3x VDD / 10
//Overcurrent detection threshold of SO1 with CSD1 = 1
//00B: VSO1 > VDD / 2+2 x VDD / 20 or VCSOx < VDD / 2 – 2 × VDD / 20 (default)
//01B: VSO1 > VDD / 2+ 4x VDD / 20 or VCSOx < VDD / 2 – 4 × VDD / 20
//10B: VSO1 > VDD / 2+ 5 x VDD / 20 or VCSOx < VDD / 2 ? 5 × VDD / 20
//11B: VSO1 > VDD / 2+ 6x VDD / 20 or VCSOx < VDD / 2 – 6 × VDD / 20
  uint8_t CSA_BLK_SEL;
//1: CSA1 and CSA2 hold blank time is tccp + tblank/2
//0:CSA1 and CSA2 hold blank time is tccp + tblank(default)
// blank time 用于PWM 抑制功能时间设置
  uint8_t CSA2_SH_EN;
  uint8_t CSA1_SH_EN;
//选择是否使用PWM 抑制功能
//Select whether to use PWM suppression
  uint8_t OC_SEP_EN;
// 选择 OCEN情况下只有CSA连接的半桥turn off 还是所有半桥Turn off
  uint8_t CSA2_SEL;
  uint8_t CSA1_SEL;
// CSA SEL根据CSA连接的半桥选择
  
}CSA_InitTypeDef;
*/

 

 BSP_LPSPI相关代码STM32:

 

/*
  analogysemi
  xutong 2023/10/19
*/
#ifndef __BSP_LPSPI_H
#define __BSP_LPSPI_H

#include "stm32h7xx_hal.h"


#define SPIx                             SPI1
#define SPIx_CLK_ENABLE()                __HAL_RCC_SPI1_CLK_ENABLE()
#define SPIx_SCK_GPIO_CLK_ENABLE()       __HAL_RCC_GPIOB_CLK_ENABLE()
#define SPIx_MISO_GPIO_CLK_ENABLE()      __HAL_RCC_GPIOB_CLK_ENABLE()
#define SPIx_MOSI_GPIO_CLK_ENABLE()      __HAL_RCC_GPIOB_CLK_ENABLE()

#define SPIx_CS_GPIO_CLK_ENABLE()      __HAL_RCC_GPIOB_CLK_ENABLE()
/* Definition for SPIx Pins */
#define SPIx_SCK_PIN                     GPIO_PIN_3
#define SPIx_SCK_GPIO_PORT               GPIOB
#define SPIx_SCK_AF                      GPIO_AF5_SPI1
#define SPIx_MISO_PIN                    GPIO_PIN_4
#define SPIx_MISO_GPIO_PORT              GPIOB
#define SPIx_MISO_AF                     GPIO_AF5_SPI1
#define SPIx_MOSI_PIN                    GPIO_PIN_5
#define SPIx_MOSI_GPIO_PORT              GPIOB
#define SPIx_MOSI_AF                     GPIO_AF5_SPI1

#define SPIx_CS_PIN                      GPIO_PIN_6
#define SPIx_CS_GPIO_PORT                GPIOB




void LPSPI_Init(void);

void Lpspi_Write(uint8_t datasize,uint8_t *data);
void Lpspi_Read(uint8_t datasize,uint8_t *data,uint8_t *Rxdata);

#endif /* __BSP_LPSPI_H */

 

#include "bsp_lpspi.h"
SPI_HandleTypeDef SpiHandle;

void Spi_delay(uint32_t count)
{ 
    volatile uint32_t i = 0;
    for (i = 0; i < count; ++i)
    {
        __asm("NOP"); /* 调用nop空指令 */
         __asm("NOP"); /* 调用nop空指令 */
          __asm("NOP"); /* 调用nop空指令 */
           __asm("NOP"); /* 调用nop空指令 */
            __asm("NOP"); /* 调用nop空指令 */
    }
}
void LPSPI_Init(void)
{
    
    GPIO_InitTypeDef  GPIO_InitStruct;
    /* Enable SPI1 clock */
    SPIx_CLK_ENABLE();
    SPIx_SCK_GPIO_CLK_ENABLE();
    SPIx_MISO_GPIO_CLK_ENABLE();
    SPIx_MOSI_GPIO_CLK_ENABLE();
    SPIx_CS_GPIO_CLK_ENABLE();
    
    

    /* 初始化GPIO 配置*/
    /*##-1- Configure peripheral GPIO ##########################################*/
    /* SPI SCK GPIO pin configuration  */
    GPIO_InitStruct.Pin       = SPIx_SCK_PIN;
    GPIO_InitStruct.Mode      = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull      = GPIO_PULLDOWN;
    GPIO_InitStruct.Speed     = GPIO_SPEED_FREQ_HIGH;
    GPIO_InitStruct.Alternate = SPIx_SCK_AF;
    HAL_GPIO_Init(SPIx_SCK_GPIO_PORT, &GPIO_InitStruct);

    /* SPI MISO GPIO pin configuration  */
    GPIO_InitStruct.Pin = SPIx_MISO_PIN;
    GPIO_InitStruct.Alternate = SPIx_MISO_AF;
    HAL_GPIO_Init(SPIx_MISO_GPIO_PORT, &GPIO_InitStruct);

    /* SPI MOSI GPIO pin configuration  */
    GPIO_InitStruct.Pin = SPIx_MOSI_PIN;
    GPIO_InitStruct.Alternate = SPIx_MOSI_AF;
    HAL_GPIO_Init(SPIx_MOSI_GPIO_PORT, &GPIO_InitStruct);
    
   /* SPI CS GPIO pin configuration  */
    GPIO_InitStruct.Pin = SPIx_CS_PIN;
    GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
    GPIO_InitStruct.Pull      = GPIO_PULLDOWN;
    GPIO_InitStruct.Speed     = GPIO_SPEED_FREQ_HIGH;
    HAL_GPIO_Init(SPIx_CS_GPIO_PORT, &GPIO_InitStruct);
    
      /* 初始化SPI 配置*/
     /*##-2- Configure the SPI peripheral #######################################*/
    /* Set the SPI parameters */
    SpiHandle.Instance               = SPIx;
    SpiHandle.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_256;
    SpiHandle.Init.Direction         = SPI_DIRECTION_2LINES;
    SpiHandle.Init.CLKPhase          = SPI_PHASE_1EDGE;
    SpiHandle.Init.CLKPolarity       = SPI_POLARITY_HIGH;
    SpiHandle.Init.DataSize          = SPI_DATASIZE_8BIT;
    SpiHandle.Init.FirstBit          = SPI_FIRSTBIT_MSB;
    SpiHandle.Init.TIMode            = SPI_TIMODE_DISABLE;
    SpiHandle.Init.CRCCalculation    = SPI_CRCCALCULATION_DISABLE;
    SpiHandle.Init.CRCPolynomial     = 7;
    SpiHandle.Init.NSS               = SPI_NSS_SOFT;
    SpiHandle.Init.Mode              = SPI_MODE_MASTER;
    //初始化SPI
    HAL_SPI_Init(&SpiHandle);
    //默认拉高CS引脚
    HAL_GPIO_WritePin(SPIx_CS_GPIO_PORT,SPIx_CS_PIN,GPIO_PIN_SET);

}
void Lpspi_Write(uint8_t datasize,uint8_t *data)
{
  
  //写数据
  HAL_GPIO_WritePin(SPIx_CS_GPIO_PORT,SPIx_CS_PIN,GPIO_PIN_RESET);
  HAL_SPI_Transmit(&SpiHandle,data, datasize, 5000);
  Spi_delay(30);
  HAL_GPIO_WritePin(SPIx_CS_GPIO_PORT,SPIx_CS_PIN,GPIO_PIN_SET);
}
void Lpspi_Read(uint8_t datasize,uint8_t *data,uint8_t *Rxdata)
{
//  读写数据
  HAL_GPIO_WritePin(SPIx_CS_GPIO_PORT,SPIx_CS_PIN,GPIO_PIN_RESET);
  HAL_SPI_TransmitReceive(&SpiHandle,data,Rxdata, datasize, 5000);
  Spi_delay(30);
  HAL_GPIO_WritePin(SPIx_CS_GPIO_PORT,SPIx_CS_PIN,GPIO_PIN_SET);
}

 

 

 

 

 

  需要注意的是,在故障安全模式下,控制寄存器被冻结为其默认值,WDTRIG、PASS_VDS、PASS_MOD、CSA1L、CSA2L除外。在此模式下,任何写命令(WDTRIG 位除外)或清除命令(GENSTAT除外)都将被丢弃并设置SPIE位(全局状态字节)。
在故障安全模式下对GENSTAT的清除命令不会重置该状态寄存器报告的任何故障标志。在退出序列开始之前,可以在此模式下读取控制和状态寄存器,而不会设置SPIE位。通常Fail Safe和 关闭看门狗可以一起使用

  注意:以上有些代码未经过验证

 

posted @ 2023-10-12 14:40  xuyuntong  阅读(430)  评论(2编辑  收藏  举报