本帖最后由 Baldwin 于 2018-8-22 19:16 编辑
最近有款产品需要用到电能计量,选用了FM33A0xx+RN8302主流方案。计量模块开发也是从一知半解到懵懂,再到熟悉,酸甜苦辣因有尽有
,下面把相关资料分享给大家,尽量少走弯路;
1---------------------------------------硬件部分-------------------------------------------------------------------------
RN8302外围电路
RN8302计量单元配置寄存器.png (138.91 KB, 下载次数: 0)
下载附件
2018-8-22 12:31 上传
- uint8_t RN8302_ReadCurrentReg(uint8_t phase,uint8_t *regdata)
- {
- uint8_t regbuf[4];
- if(phase == 0){
- if(RN8302_ReadReg(0x000B,regbuf,4)==0){
- m_memcpy((uint8_t*)regdata,regbuf,4);
- }
- }
- else if(phase == 1){
- if(RN8302_ReadReg(0x000C,regbuf,4)==0){
- m_memcpy((uint8_t*)regdata,regbuf,4);
- }
- }
- else if(phase == 2){
- if(RN8302_ReadReg(0x000D,regbuf,4)==0){
- m_memcpy((uint8_t*)regdata,regbuf,4);
- }
- }
-
- return 0;
- }
- uint8_t RN8302_ReadVoltage(uint8_t phase)
- {
- uint8_t regbuf[5];
- uint32_t regtemp = 0;
- const uint16_t regArry[]={0x0007,0x0008,0x0009};
-
- if(RN8302_ReadReg(regArry[phase],regbuf,4)==0)
- {
- regtemp = (regbuf[0]<<24)+(regbuf[1]<<16)+
- (regbuf[2]<<8)+(regbuf[3]);
- #ifdef RN8302_USING_PowerCorrection
- Voltage[phase] = (uint16_t)(regtemp*10.0/ (44000000/220)); //扩大10
- #endif
- #ifdef RN8302_USING_ErrCorrection
- Voltage[phase] = (uint16_t)(regtemp*10.0*Kv); //扩大10
- #endif
- }
-
- return 0;
- }
复制代码这是电压、电流的换算,使用这个宏定义RN8302_USING_PowerCorrection
BUF2int这个函数就是将数组中的4个字节换算成uint32_t
你好,RN8209计量芯片需要先校表的;如果对要求不高,你可以串一个电表来进行校表,通过电表测量出的电压、电流来换算你自己的值
一周热门 更多>