部分代码如下
while(1){LED0 = ~LED0;IRQStatusReadA = SPIRead4Bytes(RSTIRQSTATA);if((IRQStatusReadA&BIT18) == BIT18){printf("Energe: %drn",SPIRead4Bytes(AENERGYA));printf(" IRMS: %drn",SPIRead4Bytes(IRMSA));printf(" VRMS: %drn",SPIRead4Bytes(VRMS));printf(" VPEAK: %drn",SPIRead4Bytes(VPEAK));printf(" IPEAK: %drn",SPIRead4Bytes(IAPEAK));printf("PERIOD: %drn",SPIRead2Bytes(PERIOD));}}void ADE7953_Init(void){SPI1_Init();SPI1CS_Init();ADE7953CS = 0; /* 通信方式设置为 SPI */delay_ms(50);ADE7953_RST(); /* 软件复位 */delay_ms(50);ADE7953_ComLock(); /* 锁定通信方式 */delay_ms(50);/* 检测复位成功 */while((SPIRead4Bytes(RSTIRQSTATA) & BIT20) != BIT20){delay_ms(50);printf("ADE7953 resetting...rn");}{printf("ADE7953 OK!rn");}/* read the chip version number */printf("Version : %drn",SPIRead4Bytes(VERSION));/*For optimum performance, Register Address 0x120 must be configured by the user after powering up the ADE7953.*/SPIWrite1Byte(0x00FE,0xAD);SPIWrite2Bytes(0x0120,0x0030);/* 对 ADE7953 进行一些相关配置 */ADE7953Cfg();}void ADE7953Cfg(void){SPIWrite2Bytes(CONFIG,0x0004); /* HPF Enable (high pass filter) */SPIWrite4Bytes(AIGAIN,0x400000);SPIWrite4Bytes(AVGAIN,0x400000); /* 电压通道增益 */SPIWrite4Bytes(AWGAIN,0x400000);SPIWrite4Bytes(AVARGAIN,0x400000);SPIWrite4Bytes(AVAGAIN,0x400000);SPIWrite4Bytes(AIRMSOS,0x000000);SPIWrite4Bytes(AVRMSOS,0x000000); /* 电压通道有效值失调校正 */SPIWrite4Bytes(AWATTOS,0x000000);SPIWrite4Bytes(AVAROS,0x000000);SPIWrite4Bytes(AVAOS,0x000000);SPIWrite4Bytes(BIGAIN,0x400000); /* 电流通道 B 增益 */SPIWrite4Bytes(BWGAIN,0x400000); /* 电流通道 B,有功功率增益 */SPIWrite4Bytes(BVARGAIN,0x400000); /* 电流通道 B,无功功率增益 */SPIWrite4Bytes(BVAGAIN,0x400000); /* 电流通道 B,视在功率增益 */SPIWrite4Bytes(BIRMSOS,0x000000); /* 电流通道 B,有效值失调校正 */SPIWrite4Bytes(BWATTOS,0x000000); /* 电流通道 B,有功功率失调校正 */SPIWrite4Bytes(BVAROS,0x000000); /* 电流通道 B,无功功率失调校正 */SPIWrite4Bytes(BVAOS,0x000000); /* 电流通道 B,视在功率失调校正 */SPIWrite2Bytes(CFMODE,0x0000); /* CF output selection,CF1 and CF2 output is disabled */SPIWrite2Bytes(CF1DEN,0x003F); /* CF1 分频器分母 */SPIWrite2Bytes(CF2DEN,0x003F); /* CF2 分频器分母 */ SPIWrite4Bytes(OVLVL,0x4B0000); /* 311mv at the input get pead read 0x3DB88C, times 1.2 get this */SPIWrite4Bytes(OILVL,0x4FFFFF); /* 过流值 */SPIWrite1Byte(SAGCYC,0xFF); /* The SAGCYC register holds a maximum value of 255. *//* At 50 Hz, the maximum sag cycle time is 2.55 seconds */SPIWrite4Bytes(SAGLVL,0x200000); /* 骤降电压 */SPIWrite2Bytes(ZXTOUT,0xFFFF); /* the maximum programmable timeout period is 4.58 seconds to zero-cross */SPIWrite1Byte(LCYCMODE,0x4F); /* 电流通道 A、B 有、无功线周期累计模式,所有寄存器读后复位 */SPIWrite2Bytes(LINECYC,0x00C8); /* 在线周期电能累计模式下半线周期数 200 *///SPIWrite4Bytes(IRQENA,0x140000);}
部分代码如下
while(1){LED0 = ~LED0;IRQStatusReadA = SPIRead4Bytes(RSTIRQSTATA);if((IRQStatusReadA&BIT18) == BIT18){printf("Energe: %drn",SPIRead4Bytes(AENERGYA));printf(" IRMS: %drn",SPIRead4Bytes(IRMSA));printf(" VRMS: %drn",SPIRead4Bytes(VRMS));printf(" VPEAK: %drn",SPIRead4Bytes(VPEAK));printf(" IPEAK: %drn",SPIRead4Bytes(IAPEAK));printf("PERIOD: %drn",SPIRead2Bytes(PERIOD));}}void ADE7953_Init(void){SPI1_Init();SPI1CS_Init();ADE7953CS = 0; /* 通信方式设置为 SPI */delay_ms(50);ADE7953_RST(); /* 软件复位 */delay_ms(50);ADE7953_ComLock(); /* 锁定通信方式 */delay_ms(50);/* 检测复位成功 */while((SPIRead4Bytes(RSTIRQSTATA) & BIT20) != BIT20){delay_ms(50);printf("ADE7953 resetting...rn");}{printf("ADE7953 OK!rn");}/* read the chip version number */printf("Version : %drn",SPIRead4Bytes(VERSION));/*For optimum performance, Register Address 0x120 must be configured by the user after powering up the ADE7953.*/SPIWrite1Byte(0x00FE,0xAD);SPIWrite2Bytes(0x0120,0x0030);/* 对 ADE7953 进行一些相关配置 */ADE7953Cfg();}void ADE7953Cfg(void){SPIWrite2Bytes(CONFIG,0x0004); /* HPF Enable (high pass filter) */SPIWrite4Bytes(AIGAIN,0x400000);SPIWrite4Bytes(AVGAIN,0x400000); /* 电压通道增益 */SPIWrite4Bytes(AWGAIN,0x400000);SPIWrite4Bytes(AVARGAIN,0x400000);SPIWrite4Bytes(AVAGAIN,0x400000);SPIWrite4Bytes(AIRMSOS,0x000000);SPIWrite4Bytes(AVRMSOS,0x000000); /* 电压通道有效值失调校正 */SPIWrite4Bytes(AWATTOS,0x000000);SPIWrite4Bytes(AVAROS,0x000000);SPIWrite4Bytes(AVAOS,0x000000);SPIWrite4Bytes(BIGAIN,0x400000); /* 电流通道 B 增益 */SPIWrite4Bytes(BWGAIN,0x400000); /* 电流通道 B,有功功率增益 */SPIWrite4Bytes(BVARGAIN,0x400000); /* 电流通道 B,无功功率增益 */SPIWrite4Bytes(BVAGAIN,0x400000); /* 电流通道 B,视在功率增益 */SPIWrite4Bytes(BIRMSOS,0x000000); /* 电流通道 B,有效值失调校正 */SPIWrite4Bytes(BWATTOS,0x000000); /* 电流通道 B,有功功率失调校正 */SPIWrite4Bytes(BVAROS,0x000000); /* 电流通道 B,无功功率失调校正 */SPIWrite4Bytes(BVAOS,0x000000); /* 电流通道 B,视在功率失调校正 */SPIWrite2Bytes(CFMODE,0x0000); /* CF output selection,CF1 and CF2 output is disabled */SPIWrite2Bytes(CF1DEN,0x003F); /* CF1 分频器分母 */SPIWrite2Bytes(CF2DEN,0x003F); /* CF2 分频器分母 */ SPIWrite4Bytes(OVLVL,0x4B0000); /* 311mv at the input get pead read 0x3DB88C, times 1.2 get this */SPIWrite4Bytes(OILVL,0x4FFFFF); /* 过流值 */SPIWrite1Byte(SAGCYC,0xFF); /* The SAGCYC register holds a maximum value of 255. *//* At 50 Hz, the maximum sag cycle time is 2.55 seconds */SPIWrite4Bytes(SAGLVL,0x200000); /* 骤降电压 */SPIWrite2Bytes(ZXTOUT,0xFFFF); /* the maximum programmable timeout period is 4.58 seconds to zero-cross */SPIWrite1Byte(LCYCMODE,0x4F); /* 电流通道 A、B 有、无功线周期累计模式,所有寄存器读后复位 */SPIWrite2Bytes(LINECYC,0x00C8); /* 在线周期电能累计模式下半线周期数 200 *///SPIWrite4Bytes(IRQENA,0x140000);}
举报