hi ,
i am working on 3-phase energy meter with this M90E32AS ic.
i make the circuit for 3p3w(3-phase 3-wire). i did the spi communication for this ic.
but in this power ic (M90E32AS) the MMODE0 register default value is 0x0087. but my circuit is 3p3w , so i want to write 0x0185 on this register.
i try to write but i get the default value only(0x0087) . can you please provide me any example to how change that register value.
my program:
#include <SPI.h>
/********************************************************************************
Macros
*******************************************************************************/
#define PM0 7 //Mode control 0
#define PM1 8 //Mode control l
#define CS 10 //ChipSelect
#define DATAOUT 11 //MOSI
#define DATAIN 12 //MISO
#define SPICLOCK 13 //Clock
byte commandByte_write = B00000000;
byte commandByte_read = B10000000;
byte mode0_register = B00110011; // address bits 33h
byte mode0_MSB_byte = B00000001; // MSB byte 01 ; (0185)
byte mode0_LSB_byte = B10000101; // LSB byte 85 ; (0185)
void setup() {
pinMode(CS, OUTPUT);
pinMode(PM1, OUTPUT);
pinMode(PM0, OUTPUT);
digitalWrite(CS, HIGH);
digitalWrite(PM1, HIGH);
digitalWrite(PM0, HIGH);
SPI.begin(); // spi protocol begin function
SPI.setClockDivider(SPI_CLOCK_DIV16); // slow the SPI bus down 16/16 = 1 Mhz
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE3); // mode3 for spi communication
Serial.begin(9600); // uart baudrate
}
void loop() {
write_33h_register(); // change the mode0 for 3p3w
read_33h_register(); // read the writed value in this address
Serial.println();
Serial.println();
delay(2000);
}
/*******************************************************************
Write the mode0 register 33H
*******************************************************************/
void write_33h_register(void)
{
digitalWrite(CS, LOW);
delayMicroseconds(100);
SPI.transfer(commandByte_write);
SPI.transfer(mode0_register);
SPI.transfer(mode0_MSB_byte);
SPI.transfer(mode0_LSB_byte);
digitalWrite(CS, HIGH);
delay(50);
}
/*******************************************************************
Read the mode0 register 33H
*******************************************************************/
void read_33h_register(void)
{
digitalWrite(CS, LOW);
delayMicroseconds(100);
receiveByte1 = SPI.transfer(commandByte_read);
receiveByte2 = SPI.transfer(commandByte8); // 33 address bits
receiveByte3 = SPI.transfer(commandByte3);
receiveByte4 = SPI.transfer(commandByte4);
delayMicroseconds(100);
delay(50);
Serial.print("33H-MSB-byte : ");
Serial.println(receiveByte3, BIN);
delay(50);
Serial.print("33H-LSB-byte : ");
Serial.println(receiveByte4, BIN);
delay(50);
digitalWrite(CS, HIGH);
delay(50);
}
i can read the default values from the register, but i can not change that default value on that 33H register. can you please tell me that what change i want to do in my code.
regards
Arun Kumar.N