M90e32AS spi 3p3w communication

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

You will have a much better chance of getting a sensible reply if you post code that both compiles and has been tested.

hi ,

after write in that 33h register, i try to read that same register. but i get output is

33H-MSB-byte : 11111111 (FF)
33H-LSB-byte : 11111111 (FF)

but i need the output is like

33H-MSB-byte : 00000001 (01)
33H-LSB-byte : 10000101 (85).

if any one have any tested code for write operation means can you please share that one.

regards
Arun Kumar.N

hi,

i just copied my compiled code. this is what i am trying.

i am able to read any register but i cant write.

in this code i am read and write in 33H register. read i happen properly but write is not done.

can any one please tell me any suggestion or give a code for how to write the value in the particular register.

program:

/********************************************************************************
Include files
*******************************************************************************/
#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

#define register_address_array_size 50

/********************************************************************************
Global variables
*******************************************************************************/

byte commandByte_read = B10000000; // start bit, 5 bit "x" (dont care bits), and first two address bits 00 for read
byte commandByte_write = B00000000; // start bit, 5 bit "x" (dont care bits), and first two address bits 00 for write

byte register_addresses[register_address_array_size] = {0}; // store address values of the register in this array

byte commandByte3 = B00000000; // zero value for read the data from the slave
byte commandByte4 = B00000000; // zero value for read the data from the slave

/* ********************** Receiver byte value *************************/

byte receiveByte1 = B00000000;
byte receiveByte2 = B00000000;
byte receiveByte3 = B00000000; // receive the data MSB bits
byte receiveByte4 = B00000000; // receive the data LSB bits

/* *************************************************************************/

/* ************************ address values ******************************/

byte commandByte2 = B01111000; // address bits 78H ; 0111 1000

byte commandByte8 = B00110011; // address bits 33h

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)

/* *************************************************************************/

/* ***************************************************************************************************** */

/********************************************************************************
Main Setup
*******************************************************************************/
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

}

/********************************************************************************
while(1) loop setup
*******************************************************************************/

void loop()
{
write_33h_register(); // change the mode0 for 3p3w
Serial.println("write in the reg ");
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);

SPI.transfer(B00000000);
SPI.transfer(commandByte8);
SPI.transfer(B00000001);
SPI.transfer(B10000101);

digitalWrite(CS, HIGH);

}
/*******************************************************************
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);

}

thanks
Arun Kumar.N