项目开发三 电力终端抄表之电力数据(未调通) 前面一期把蓝牙和串口抄表功能实现了,最重要的电力数据还没得到,有专门的计量芯片来完成,此处借由V9203来实现,它的特性如下: 敲击ls /dev/spidev*,RZ/G2L返回/dev/spidev0.0说明只有一路挂载了一路spi,板子J20的19/21/23/24脚刚好接到V9203的spi: 它的主要代码为: - #define V9203CMD_WRDATAL 0x08
- #define V9203CMD_WRDATAH 0x0a
- #define V9203CMD_WRADDRDST 0x0c
- #define V9203CMD_RDADDRDST 0x10
- #define V9203CMD_RDDATAL 0x12
- #define V9203CMD_RDDATAH 0x14
- #define V9203CMD_LASTADDR 0x0e
- #define V9203CMD_LASTDATAL 0x16
- #define V9203CMD_LASTDATAH 0x18
- #define V9203_ANCtrl0 0x8000
- #define V9203_ANCtrl1 0x8001
- #define V9203_ANCtrl2 0x8002
- #define V9203_ANCtrl3 0x8003
- uint8_t V9203_spifcs(uint8_t *dat,uint8_t len)
- {
- if(len==0||dat==NULL)
- return 0;
- uint8_t i=0,fcs=0;
- for(i=0;i<len;i++)
- fcs+=dat[i];
- return fcs^0xff;
- }
- uint8_t tx[] = {
- 0x80|V9203CMD_RDADDRDST,0,0,0,
- 0x80|V9203CMD_RDDATAL,0xFF,0xFF,0xFF,
- 0x80|V9203CMD_RDDATAH,0xFF,0xFF,0xFF, };
- tx[0]= V9203_ANCtrl2>>8;
- tx[1]= V9203_ANCtrl2>>8;
- for(int i=1;i<4;i++)
- tx[4*i-1]=V9203_spifcs(tx+4*(i-1),3);
- uint8_t rx[ARRAY_SIZE(tx)] = {0, };
- struct spi_ioc_transfer tr = {
- .tx_buf = (unsigned long)tx,
- .rx_buf = (unsigned long)rx,
- .len = ARRAY_SIZE(tx),
- .delay_usecs = delay,
- .speed_hz = speed,
- .bits_per_word = bits,
- };
复制代码
通过电压互感器接上220V家庭用电,由于对Linux不很熟,运行结果要么是数据不对要么时钟错误,在STM32上跑是正常的:
时间有限,调了几次没调通。先这样
|