Hello everyone,
I am currently working on a project that is using the M90E32AS Poly-Phase Energy Metering IC and the ATMEGA328P. Currently I'm using the arduino uno as a quick development board to try and get my project started. The problem I am having is with the SPI serial communication, I just can't get a proper response from the chip. My code for reading register 78H is:
#include <SPI.h>
#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
void setup() {
pinMode(PM1, OUTPUT);
pinMode(PM0, OUTPUT);
DDRB |= (1 << PB2); // chipselect pin output
digitalWrite(PM1, HIGH);
digitalWrite(PM0, HIGH);
SPI.setClockDivider( SPI_CLOCK_DIV16); // slow the SPI bus down 16/16 = 1 Mhz
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE2);
SPI.begin();
Serial.begin(9600);
}
void loop() {
byte commandByte1 = B10000000; // start bit, 5 bit "x", and first two address bits 00
byte commandByte2 = B01111000; // address bits 78H = 0111 1000
byte commandByte3 = B00000000;
byte commandByte4 = B00000000;
byte hiByte, loByte;
PORTB &= ~(1 << PB2); // activate Chipselect
SPI.transfer(commandByte1);
SPI.transfer(commandByte2);
hiByte = SPI.transfer(commandByte3);
loByte = SPI.transfer(commandByte4);
PORTB |= (1 << PB2); //deactivate Chipselect
Serial.println(hiByte, BIN);
Serial.println(loByte, BIN);
Serial.println();
delay(2000);
}
the only response i get is all 1's and I know I have the wiring correct.
If there are any SPI experts out there that can help I would really appreciate it.
Attached is the datasheet and application notes.
Thanks,