2024-12-27 18:16:23 +08:00
|
|
|
|
#ifndef _RN8209_H
|
|
|
|
|
#define _RN8209_H
|
2024-12-10 20:11:28 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "user.h"
|
2024-12-27 18:16:23 +08:00
|
|
|
|
//----------------------start RN8209 <20><>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>---------------------------------------------------//
|
|
|
|
|
#define ADSYSCON 0x00 //ϵͳ<CFB5><CDB3><EFBFBD>ƼĴ<C6BC><C4B4><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD>
|
|
|
|
|
#define ADEMUCON 0x01 //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƼĴ<C6BC><C4B4><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD>
|
|
|
|
|
#define ADHFConst 0x02 //<2F><><EFBFBD><EFBFBD>Ƶ<EFBFBD>ʼĴ<CABC><C4B4><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD>
|
|
|
|
|
#define ADPStart 0x03 //<2F>й<EFBFBD><D0B9><EFBFBD><F0B6AFB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD>
|
|
|
|
|
#define ADDStart 0x04 //<2F>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><F0B6AFB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD> д<><D0B4><EFBFBD><EFBFBD>
|
|
|
|
|
#define ADGPQA 0x05 //ͨ<><CDA8> A <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><D0A3><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD> д<><D0B4><EFBFBD><EFBFBD>
|
|
|
|
|
#define ADGPQB 0x06 //ͨ<><CDA8> B <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><D0A3><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD> д<><D0B4><EFBFBD><EFBFBD>
|
|
|
|
|
#define ADPhsA 0x07 //ͨ<><CDA8> A <20><>λУ<CEBB><D0A3><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD> д<><D0B4><EFBFBD><EFBFBD>
|
|
|
|
|
#define ADPhsB 0x08 //ͨ<><CDA8> B <20><>λУ<CEBB><D0A3><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD> д<><D0B4><EFBFBD><EFBFBD>
|
|
|
|
|
#define ADQPHSCAL 0x09 //<2F><EFBFBD><DEB9><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD> д<><D0B4><EFBFBD><EFBFBD>
|
|
|
|
|
#define ADAPOSA 0x0a //ͨ<><CDA8> A <20>й<EFBFBD><D0B9><EFBFBD><EFBFBD><EFBFBD> Offset У<><D0A3><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD>
|
|
|
|
|
#define ADAPOSB 0x0b //ͨ<><CDA8> B <20>й<EFBFBD><D0B9><EFBFBD><EFBFBD><EFBFBD> Offset У<><D0A3><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD>
|
|
|
|
|
#define ADRPOSA 0x0c //ͨ<><CDA8> A <20><EFBFBD><DEB9><EFBFBD><EFBFBD><EFBFBD> Offset У<><D0A3><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD>
|
|
|
|
|
#define ADRPOSB 0x0d //ͨ<><CDA8> B <20><EFBFBD><DEB9><EFBFBD><EFBFBD><EFBFBD> Offset У<><D0A3><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD>
|
|
|
|
|
#define ADIARMSOS 0x0e //<2F><><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8> A <20><>Чֵ Offset <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> д<><D0B4><EFBFBD><EFBFBD>
|
|
|
|
|
#define ADIBRMSOS 0x0f //<2F><><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8> B <20><>Чֵ Offset <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> д<><D0B4><EFBFBD><EFBFBD>
|
|
|
|
|
#define ADIBGain 0x10 //<2F><><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8> B <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD> д<><D0B4><EFBFBD><EFBFBD>
|
|
|
|
|
#define ADD2FPL 0x11 //<2F>Զ<EFBFBD><D4B6>幦<EFBFBD>ʼĴ<CABC><C4B4><EFBFBD> D2FP <20>ĵ<EFBFBD> 16bit<69><74>д<EFBFBD><D0B4><EFBFBD><EFBFBD>
|
|
|
|
|
#define ADD2FPH 0x12
|
|
|
|
|
#define ADDCIAH 0x13
|
|
|
|
|
#define ADDCIBH 0x14
|
|
|
|
|
#define ADDCUH 0x15
|
|
|
|
|
#define ADDCL 0x16
|
|
|
|
|
#define ADEMUCON2 0x17
|
|
|
|
|
#define ADCLKCON 0x1A //ģ<><C4A3>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>üĴ<C3BC><C4B4><EFBFBD>
|
|
|
|
|
#define ADPFCnt 0x20
|
|
|
|
|
#define ADDFcnt 0x21
|
|
|
|
|
#define ADIARMS 0x22
|
|
|
|
|
#define ADIBRMS 0x23
|
|
|
|
|
#define ADURMS 0x24 //<2F><>ѹ<EFBFBD><D1B9>Чֵ
|
|
|
|
|
#define ADUFreq 0x25 //<2F><>ѹƵ<D1B9><C6B5>
|
|
|
|
|
#define ADPowerPA 0x26 //<2F>й<EFBFBD><D0B9><EFBFBD><EFBFBD><EFBFBD>Pa
|
|
|
|
|
#define ADPowerPB 0x27
|
|
|
|
|
#define ADREPower 0x28
|
|
|
|
|
#define ADEnergyP 0x29
|
|
|
|
|
#define ADEnergyP2 0x2a
|
|
|
|
|
#define ADEnergyD 0x2b
|
|
|
|
|
#define ADEnergyD2 0x2c
|
|
|
|
|
#define ADEMUStatus 0x2d
|
|
|
|
|
#define ADSPL_IA 0x30
|
|
|
|
|
#define ADSPL_IB 0x31
|
|
|
|
|
#define ADSPL_U 0x32
|
|
|
|
|
#define ADIE 0x40
|
|
|
|
|
#define ADIF 0x41
|
|
|
|
|
#define ADRIF 0x42
|
|
|
|
|
#define ADSysStatus 0x43
|
|
|
|
|
#define ADRData 0x44
|
|
|
|
|
#define ADWData 0x45
|
|
|
|
|
#define WAVE_IF 0x46 //<2F><><EFBFBD>λ<EFBFBD><CEBB><EFBFBD>״̬<D7B4>Ĵ<EFBFBD><C4B4><EFBFBD>
|
|
|
|
|
#define WAVE_IE 0x47 //<2F><><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD>жϼĴ<CFBC><C4B4><EFBFBD>
|
|
|
|
|
#define ADDeviceID 0x7f
|
|
|
|
|
#define ADDeviceID2 0x7e
|
|
|
|
|
#define WriteEn 0xea
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define SPI_TIMEOUT 10
|
|
|
|
|
|
|
|
|
|
extern float IA;
|
|
|
|
|
extern float IB;
|
|
|
|
|
extern float Vol;
|
|
|
|
|
extern float PA;
|
|
|
|
|
extern float PB;
|
|
|
|
|
extern float EA;
|
|
|
|
|
extern float Fr;
|
|
|
|
|
|
|
|
|
|
extern float Kv;
|
|
|
|
|
extern float Ki;
|
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
unsigned short I_Curr;
|
|
|
|
|
unsigned short Voltage;
|
|
|
|
|
unsigned short Active_Power;
|
|
|
|
|
unsigned short Reactive_Power;
|
|
|
|
|
unsigned short Apparent_Power;
|
|
|
|
|
unsigned char Factor;
|
|
|
|
|
unsigned long int Apparent_Energy;
|
|
|
|
|
}MeterData;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define SPI_CS_HIGH() HAL_GPIO_WritePin(CS_GPIO_Port,CS_Pin,GPIO_PIN_SET)
|
|
|
|
|
#define SPI_CS_LOW() HAL_GPIO_WritePin(CS_GPIO_Port,CS_Pin,GPIO_PIN_RESET)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
extern MeterData Pre_MeterData;
|
|
|
|
|
extern unsigned int CurrentElectric; //<2F>ܵ<EFBFBD><DCB5><EFBFBD>
|
|
|
|
|
|
|
|
|
|
void EMU_init(void);
|
|
|
|
|
void rn8209_Init(void);
|
|
|
|
|
void rn8209_ReadData(void);
|
|
|
|
|
void Write_SPI(unsigned char Address,uint32_t dwData, unsigned char Date_len);
|
|
|
|
|
uint32_t READ_SPI(unsigned char Address, unsigned char Data_len);
|
|
|
|
|
|
|
|
|
|
void rn8209d_Init(void);
|
|
|
|
|
void EMU_init_xlq(void);
|
|
|
|
|
void rn8209d_cal(void);
|
|
|
|
|
void rn8209_ReadAll(void);
|
|
|
|
|
void Start_Wave();
|
2024-12-10 20:11:28 +08:00
|
|
|
|
#endif
|