Need help for reading data from ade7753 by using arduino uno
hi doing project on enery metering ic ade7753 stuck , not able data ic either 6 or 86 ot time variable please me in iam able complete .
please tell me making mistake
thanks in advance
code: [select]
// spi master
//arduino spi pin
//10 (ss), 11 (mosi), 12 (miso), 13 (sck)
#include <spi.h>
#include <avr/interrupt.h>
#include <avr/io.h>
#include "pins_arduino.h"
#include <liquidcrystal.h>
#define sdrdy 9 // slave data ready
#define mackpin pinb3
liquidcrystal lcd(7, 6, 5, 4, 3, 2);
byte t=0;
signed char ae=0;
unsigned char re=0;
unsigned char ipk=0;
long irms=0;
unsigned char vpk=0;
long vrms=0;
int tmp=0;
byte rtnval[2];
byte rtn1val[1];
byte rtn2val[2];
//byte r1=0;
//short j;
void setup() {
pinmode(sdrdy, input);
spi_masterinit();
setclockdivider(spi_clock_div16);
lcd.begin(16,2);
serial.begin(9600);
}
void loop()
{
//---------------------------------------------- vrms--------------------------------------------------------------------//
digitalwrite(ss, low);
t=spi_mastertransmit(0x17);
//block when slave data not ready (not write spdr yet)
while (digitalread(sdrdy) == low) //;
{
//vrms = spi_masterreceive();
rtn2val[0] = spi_masterreceive();
rtn2val[1] = spi_masterreceive();
rtn2val[2] = spi_masterreceive();
}
// assemble long type
vrms = vrms | rtn2val[0];
vrms = vrms >> 8;
vrms = vrms | rtn2val[1];
vrms = vrms >> 8;
vrms = vrms | rtn2val[2];
//serial.write(firstsensor);
digitalwrite(ss, high);
serial.print(" ,vrms");
// serial.print(vrms);
serial.println(vrms, dec);
delay(100);
lcd.setcursor(6,1);
lcd.print("vr=");
lcd.print(vrms);
delay(100);
//----------------------------------------------irms--------------------------------------------------------------------//
digitalwrite(ss, low);
t=spi_mastertransmit(22);
//block when slave data not ready (not write spdr yet)
while (digitalread(sdrdy) == low) ;
//vrms = spi_masterreceive();
rtnval[0] = spi_masterreceive();
rtnval[1] = spi_masterreceive();
rtnval[2] = spi_masterreceive();
// assemble long type
irms = irms | rtnval[2];
irms = irms >> 8;
irms = irms | rtnval[1];
irms = irms >> 8;
irms = irms | rtnval[0];
//serial.write(firstsensor);
digitalwrite(ss, high);
serial.print(" ,irms");
// serial.print(vrms);
serial.println(irms, dec);
delay(100);
lcd.setcursor(1,0);
lcd.print("vr=");
lcd.print(irms);
delay(100);
delay(100);
//---------------------------------------------- temp--------------------------------------------------------------------//
digitalwrite(ss, low);
t=spi_mastertransmit(61);
//block when slave data not ready (not write spdr yet)
while (digitalread(sdrdy) == low) ;
//vrms = spi_masterreceive();
rtn1val[0] = spi_masterreceive();
rtn1val[1] = spi_masterreceive();
// rtnval[2] = spi_masterreceive();
// assemble long type
// tmp = tmp | rtn1val[0];
//tmp = tmp >> 8;
//tmp = tmp | rtn1val[1];
// vrms = vrms >> 8;
// vrms = vrms | rtnval[2];
//serial.write(firstsensor);
digitalwrite(ss, high);
serial.print(" ,tmp");
// serial.print(vrms);
serial.println(tmp, dec);
delay(100);
lcd.setcursor(6,1);
lcd.print("vr=");
lcd.print(vrms);
delay(100);
}
// copy http://arduino.googlecode.com/svn
// spi.cpp, spi.h
void spi_masterinit(void)
{
pinmode(sck, output);
pinmode(mosi, output);
pinmode(ss, output);
digitalwrite(sck, low);
digitalwrite(mosi, low);
digitalwrite(ss, high);
// warning: if ss pin ever becomes low input spi
// automatically switches slave, data direction of
// ss pin must kept output.
spcr |= _bv(mstr);
spcr |= _bv(spe);
//default spi speed osc/2 (in arduino uno, 4mhz, fast)
//change osc/16
setclockdivider(spi_clock_div16);
}
byte spi_mastertransmit(byte cdata)
{
/* start transmission */
spdr = cdata;
/* wait transmission complete */
while(!(spsr & (1<<spif)))
;
return spdr;
}
byte spi_masterreceive(void)
{
spdr = 0x11;
/* wait reception complete */
while(!(spsr & (1<<spif)))
;
return spdr;
}
void setclockdivider(byte rate)
{
spcr = (spcr & ~spi_clock_mask) | (rate & spi_clock_mask);
spsr = (spsr & ~spi_2xclock_mask) | (rate & spi_2xclock_mask);
}
please tell me making mistake
thanks in advance
got link datasheet?
Arduino Forum > International > India (Moderators: Nishant_Sood, jo_v) > Need help for reading data from ade7753 by using arduino uno
arduino
Comments
Post a Comment