首页 ADE7758 read and write

ADE7758 read and write

举报
开通vip

ADE7758 read and writeADE7758 read and write Read and write operations on ADE7758 (processor using MSP430F449) Source: 21IC Author: leetb: home of measurement and control Read and write operations on ADE7758 (processor using MSP430F449) The program listing is as follows: //ope...

ADE7758 read and write
ADE7758 read and write Read and write operations on ADE7758 (processor using MSP430F449) Source: 21IC Author: leetb: home of measurement and control Read and write operations on ADE7758 (processor using MSP430F449) The program listing is as follows: //operating SPI PORTS --CAN #include "msp430x44x.h"" Unsigned char SPIData[3]; / / ADE7758 received data Unsigned char SPI_Num; / / receive character counter Unsigned char SPICMD[3]; / / to send command string / / ***************************************************************************** / / synchronous serial communication - delay subroutine Void SPIDelay (int DelayTimes) {while (DelayTimes > 0) DelayTimes--; } / / ***************************************************************************** / / synchronous serial communication -- initializes the 7758 communication interface module Void Init_SPI1 (void) USART1 SPI {/ / initialization mode UCTL1 &= ~SWRST; / / to the USART1 initialization UCTL1 |= CHAR; / / USART1 8 BITS data model UCTL1 |= SYNC; / / USART1 SPI communication mode UCTL1 |= MM; / / USART1 SPI main mode UTCTL1 |= STC; / / mode sent from the machine, 1 is the SPI 3 line mode, the STE pin is UTCTL1 |= SSEL1; / / selection system clock SMCLK UTCTL1 |= / / SSEL0; //UTCTL1 |= CKPL; / / UCLK1 and UCLK signals of opposite polarity UTCTL1 ~CKPL &=; UBR01 = 0x08; / / synchronous signal frequency factor 1MHz @ 8MHz UBR11 = 0x00; UMCTL1 = 0x00; / / the baud rate factor adjustment factor ME2 |= USPIE1; / / SPI module open USART1 P4SEL |= 0X3C; / / specific terminal set P4DIR 0X0C |=; IE2 |= URXIE1; / / SPI receive interrupt enable UCTL1 &= ~SWRST; / / USART1 SPI model has been set up P4OUT &= ~BIT2; / / ADE7758 often state gate } / / ***************************************************************************** / / synchronous serial communication -- ADE7758 module / / Addr for the ADE7758 module internal register address Length / / register data corresponding to the ADE7758 length / / SPICMD[0..2] information to be sent Void Write_7758 (unsigned, char, Address, unsigned, char, Length) {unsigned, char, num; Strobe / / ADE7758 While ((UTCTL1 & TXEPT); / / ==0) to determine the send buffer is empty TXBUF1 = Address | 0x80; / / write the address to send SPIDelay (10); / / delay For (Num = 0; num < Length; / / num++) cycle to send multiple bytes of information {while ((UTCTL1 & TXEPT); / / ==0) to determine the send buffer is empty TXBUF1 = SPICMD[num]; / / write the address to send SPIDelay (1); / / delay } } / / ***************************************************************************** / / synchronous serial communication - ADE7758 reading module / / Addr for the ADE7758 module internal register address Length / / register data corresponding to the ADE7758 length / / SPIData[0..2] to receive the data information Void Read_7758 (unsigned, char, Address) {/ / strobe ADE7758 While ((UTCTL1 & TXEPT); / / ==0) to determine the send buffer is empty TXBUF1 = Address; / / 发送 读地址 Spidelay (1); / / 延时 SPI _ a = 0; / / 初始化接收数据个数 } / / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / / 同步串行通讯 - 初始化ade7758模块 Void init _ 7758 (void) { / / SPCR = 0x2a; Spicmd [0] = 0x40; / / 操作模式寄存器 Write _ 7758 (0x13,1); / / measurement mode. Spidelay (10); Read _ 7758 (0x13); Spicmd [0] = 0x00; / / 软件复位 Write _ 7758 (0x13,1); / / measurement mode. Spidelay (10); Spicmd [0] = 0x38; / / line cycle accumulation mode. Write _ 7758 (0x17,1); Spicmd [0] = 0x00; / / interrupt mask Spicmd [1] = 0x00; Spicmd [2] = 0x00; Write _ 7758 (0x18,3); Spicmd [0] = 0x00; / / gain Write _ 7758 (0x23,1); / / SPCR = 0x22; } # pragma vector = vector usart1rx _ / USART 1 接收信息中断 _ _ interrupt void u7758 _ ISP (void) / / SPI1 发送中断服务程序 { Spidata [SPI _ a] = rxbuf1; Ifg2 & = ~ urxifg1; SPI _ a + +; } Void main (void) {int i; Wdtctl = wdtpw + wdthold; / / FLL _ ctl0 | = xcap14pf; Scfi0 = 0x20; / / FN _ 4; / / 设置系统工作频率 Scfi1 = 0x20; / / scfqctl = 64; / / (1 + 1) * * 2 = 7.99mhz 32768 FLL _ ctl0 = 0xec; FLL _ CTL1 = 0x00; P1dir = 32; P1sel = 32; _ SPI1 init (); / / init _ 7758 (); _ EINT (); For (I = 0; I < 100; I + +) read _ 7758 (I); While (1) read _ 7758 (0x46); } Msp430f449采用三线spi主模式, 采用1mhz的通讯频率与ade7758 通讯. 449采用中断方式进行接收. 通过示波器可以看到收发的时序.
本文档为【ADE7758 read and write】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_721103
暂无简介~
格式:doc
大小:22KB
软件:Word
页数:0
分类:生活休闲
上传时间:2017-10-19
浏览量:12