Arduino Forum

Products => Arduino Yún => Topic started by: Blizzart on Sep 16, 2015, 03:16 pm

Title: Arduino Yun / SPI Problem / Power Measuring CS5463
Post by: Blizzart on Sep 16, 2015, 03:16 pm
Hey Guys,
I'm pretty new to the arduino world and I'm currently facing a communication Problem between the Arduino Yun and the CS5463 Measuring IC (Datasheet (http://www.cirrus.com/cn/pubs/proDatasheet/CS5463_F3.pdf))

For testing and debugging purposes I am NOT connecting anything to line Voltage and only working with "save low voltage"!
The Arduino Power Outputs (5V VCC and GND) are powering the CS5463 and I connected the pins of the ICSP header to the corresponding SPI pins on the CS5463. (--> schematic below)

Right now I have nothing connected to the VIN and IIN pins, but I am planning on using a 50Hz sinus wave signal with Vrms=700mV coming from a function generator after reducing the the Voltage with two simple resistors. (the CS5463 can measure up to 250mV peak which should be about 170mV RMS).

I do have an Oscilloscope, stable power supply, function generator but I don't have a logic analyzer (but I want to buying on).

I was planning on using the signal provided by the function generator for both Voltage and Current Measuring for the first testing. Later I will carry on to a shunt Resistor for the Current.

I'm having trouble to read and write the registers in order to get the Voltage and Current measurements, that's why i went back to simply write some configurations in the config register and trying to read the data to verify the operation.
I would really appreciate your help and am very grateful for any advice.
If I missed any crucial information about my test setup just let my know and I will try to provide them as quickly as possible.

Thanks a lot!
Felix

Here is my shematic:
(http://i.imgur.com/Ss2dtuT.jpg)

Here is my Code:
Code: [Select]

 /*
 CS5463 Single Phase Power Measuring IC

 Circuit:
 CS5463 attached to pins 8, 9, 12, 13:

 
 /*
// CS5463 Register Addresses
// B7 B6 B5 B4 B3 B2 B1 B0
// 0 W/R RA4 RA3 RA2 RA1 RA0 0
// W=1 R=0
Read Write Address
 Config  = 0x0     0x40 0b00000  ; // Configuration
 IDCoff  = 0x2     0x42 0b00001  ; // Current DC Offset
 Ign         = 0x4     0x44 0b00010  ; // Current Gain
 VDCoff      = 0x6     0x46 0b00011  ; // Voltage DC Offset
 Vgn         = 0x8     0x48 0b00100  ; // Voltage Gain
 CycleCount  = 0xA     0x4A 0b00101  ; // Number of A/D conversions used in one computation cycle (N)).
 PulseRateE  = 0xC     0x4C 0b00110  ; // Sets the E1, E2 and E3 energy-to-frequency output pulse rate.
 I           = 0xE     0x4E 0b00111  ; // Instantaneous Current
 V           = 0x10   0x50 0b01000  ; // Instantaneous Voltage
 P           = 0x12   0x52 0b01001  ; // Instantaneous Power
 PActive     = 0x14   0x54 0b01010  ; // Active (Real) Power
 IRMS        = 0x16   0x56 0b01011  ; // RMS Current
 VRMS        = 0x18   0x58 0b01100  ; // RMS Voltage
 Epsilon     = 0x1A   0x5A 0b01101  ; // Ratio of line frequency to output word rate (OWR)
 Poff        = 0x1C   0x5C 0b01110  ; // Power Offset
 Status      = 0x1E   0x5E 0b01111  ; // Status
 IACoff      = 0x20   0x60 0b10000  ; // Current AC (RMS) Offset
 VACoff      = 0x22   0x62 0b10001  ; // Voltage AC (RMS) Offset
 Mode        = 0x24   0x64 0b10010  ; // Operation Mode
 T           = 0x26   0x66 0b10011  ; // Temperature
 QAVG        = 0x28   0x68 0b10100  ; // Average Reactive Power
 Q           = 0x2A   0x6A 0b10101  ; // Instantaneous Reactive Power
 IPeak       = 0x2C   0x6C 0b10110  ; // Peak Current
 VPeak       = 0x2E   0x6E 0b10111  ; // Peak Voltage
 QTrig       = 0x30   0x70 0b11000  ; // Reactive Power calculated from Power Triangle
 PF          = 0x32   0x72 0b11001  ; // Power Factor
 Mask        = 0x34   0x74 0b11010  ; // Interrupt Mask
 S           = 0x36   0x76 0b11011  ; // Apparent Power
 Ctrl        = 0x38   0x78 0b11100  ; // Control
 PH          = 0x3A   0x7A 0b11101  ; // Harmonic Active Power
 PFA         = 0x3C   0x7C 0b11110  ; // Fundamental Active Power
 QF          = 0x3E   0x7E 0b11111  ; // Fundamental Reactive Power / Page


 created 15. September 2015
 
 
 */

// the CS5463 communicates using SPI, so include the library:
#include <SPI.h>



const int CS = 8; // Assign the Chip Select signal to pin 8
const int RESET = 13; // Assign Reset to pin 13

byte H_ByteC;          //High Byte
byte M_ByteC;          //Middle Byte
byte L_ByteC;          //Low Byte

byte Read  = 0B0000000;
byte Write = 0B0100000;
int junk;

void setup() {  

  pinMode(CS, OUTPUT); //initalize the chip select pin;
  pinMode(RESET, OUTPUT); //initalize the RESET pin;

  digitalWrite(CS, HIGH);
  digitalWrite(RESET, HIGH);
  
  delay (100);
  
  
 //Create a serial connection to display the data on the terminal.  
  Serial.begin(9600);
  
  //start the SPI library;
  SPI.begin();
  
    SPI.setBitOrder(MSBFIRST);
SPI.setClockDivider(8);

digitalWrite(RESET, LOW);
 delay (100);
 digitalWrite(RESET, HIGH);
delay (100);


digitalWrite(CS, LOW); //Chip select to low to initialise comms with CS5463

//Set Config register
 
SPI.transfer(0x40);
SPI.transfer(0x34);  //3 bytes of data to set 24bits of config register        
   SPI.transfer(0xC);    
   SPI.transfer(0x34);
    
digitalWrite(CS, HIGH);  //Chip select to low to disable comms with CS5463  
}


void loop()
{
digitalWrite(CS, LOW);
SPI.transfer(Read);
SPI.transfer(0x0);             //Read the Instantaneous Power Register                                
H_ByteC = SPI.transfer(0xFF);   //Reads high byte and writes sync1                                      
M_ByteC = SPI.transfer(0xFF);   //Reads middle byte and writes sync1                                    
L_ByteC = SPI.transfer(0xFF);   //Reads low byte and writes sync1                                  
digitalWrite(CS, HIGH);

delay (100);
  

Serial.print("Config: ");
Serial.println(H_ByteC,BIN);
Serial.println(M_ByteC,BIN);
Serial.println(L_ByteC),BIN ;
delay (100);

}


Title: Re: Arduino Yun / SPI Problem / Power Measuring CS5463
Post by: sonnyyu on Sep 16, 2015, 07:18 pm
The URL of Code?

Correct diagram:

(http://i.imgur.com/BCoDmWT.png)

...
The Arduino Power Outputs (5V VCC and GND) are powering the CS5463.
...
Deadly wrong!

Missing SPI isolation!

If I were you, cease the project immediately!





Title: Re: Arduino Yun / SPI Problem / Power Measuring CS5463
Post by: -dev on Sep 16, 2015, 09:38 pm
Could you list *all* the connections.  There are separate analog and digital power/ground pins on this device.

Do you have a schematic?

What crystal are you using?

Are you using a SSOP-24 breakout board, or are you using the Eval board?

Do you have an oscilloscope?

Do you have a logic analyzer?

Have you connected anything to VIN or IIN?  This is the safety concern, as there is no electrical isolation in the chip.

You can develop your software with "safe" inputs to VIN and IIN (i.e., true isolated low-voltage/current inputs instead of mains), and then switch to conditioned mains inputs for the final system.  You'd still have to use isolation from the Arduino to something else, like a PC, unless you're using wireless ethernet.  However, you'd always have to disconnect the device from mains to reprogram the Arduino.

Most projects will isolate the CS5463 SPI pins from the Arduino pins: ADuM1200 and Si8441 come to mind.  That would allow you to reprogram the Arduino without disconnecting from the CS5463 from mains, and safely connect the Arduino Serial to your PC for debugging.

You could also use a voltage and current transformer to isolate VIN and IIN from mains, with some distortion in the readings.

There are many safety concerns here, with deadly results.  We don't know your background or who may be guiding your work, hence our questions.

Cheers,
/dev
Title: Re: Arduino Yun / SPI Problem / Power Measuring CS5463
Post by: sonnyyu on Sep 16, 2015, 10:02 pm
...
There are many safety concerns here, with deadly results.  We don't know your background or who may be guiding your work, hence our questions.
...
very nice!



Title: Re: Arduino Yun / SPI Problem / Power Measuring CS5463
Post by: sonnyyu on Sep 16, 2015, 10:04 pm
Plan B:

Get Single Phase Din Rail Energy Meter with RS485 Modbus RTU

(http://i.imgur.com/mMtPuyZ.jpg)

US $18.00  / Piece (http://www.alibaba.com/product-detail/Single-Phase-Din-Rail-Energy-Meter_60067388395.html?spm=a2700.7782932.1998701000.26.VgVMr6)

A lot of them uses CS5463  inside.

Yun/Yun shield  + USB-RS485  adaptor connect with Energy Meter.

You made IOT ( Internet of Things)  Energy Meter.



Title: Re: Arduino Yun / SPI Problem / Power Measuring CS5463
Post by: Blizzart on Sep 17, 2015, 12:07 am
Thanks a lot for your replies so far!



I soldered the CS5463 to a breakout board and connected everything on a breadboard.
I do know that line voltage is dangerous, that is exactly why I was planning on testing the whole setup with "save low voltage", sorry for not mentioning that.

Here is my shematic:
(http://i.imgur.com/Ss2dtuT.jpg)


I do have an Oscilloscope, but I don't have a logic analyzer, I am happy to buy one if you could give me a recommendation.
Right now I have nothing connected to the VIN and IIN pins, but I am planning on using a 50Hz sinus wave signal with Vrms=700mV coming from a function generator after reducing the the Voltage with two simple resistors. (the CS5463 can measure up to 250mV peak which should be about 170mV RMS). EDIT: found a typo in my shematic, its a 4.096MHz oscillator

I was planning on using the signal for both Voltage and Current Measuring for the first testing. Later I will carry on to a shunt Resistor for the Current.

I do know about the requirement for galvanic isolation when i go one step further and do actual Line Voltage and Power measurements but for now I need to verify that the CS5463 with its SPI connection is working and I can receive the correct Values .


Right now I am trying to understand how the register read functions are working and how i can write to the Config register.
Hopefully this will help my to correct my mistakes in the read routine for the calculated measuring values.

Thanks again for your help!
Felix

Title: Re: Arduino Yun / SPI Problem / Power Measuring CS5463
Post by: -dev on Sep 17, 2015, 01:14 am
Quote
I was planning on testing the whole setup with "safe low voltage"
We're all relieved to hear that!

Is the MODE pin connected?

Regarding the software, I don't think you're reading the "Instantaneous Power" register with this code:

Code: [Select]
SPI.transfer(Read);
SPI.transfer(0x0);            //Read the Instantaneous Power Register
H_ByteC = SPI.transfer(0xFF);  //Reads high byte and writes sync1
M_ByteC = SPI.transfer(0xFF);  //Reads middle byte and writes sync1
L_ByteC = SPI.transfer(0xFF);   //Reads low byte and writes sync1

The problem is that you are sending two bytes (Read, then 0x00) instead of one (00010010 = 0x12).  You have the correct description at the top.

The "P" register is at address 9.  To read register 9, you have to send

Code: [Select]
        SPI.transfer( Read | (9 << 1) ); // LSB "B0" is always zero
H_ByteC = SPI.transfer(0xFF);  //Reads high byte and writes sync1
M_ByteC = SPI.transfer(0xFF);  //Reads middle byte and writes sync1
L_ByteC = SPI.transfer(0xFF);   //Reads low byte and writes sync1

Note how the "9" is shifted left by one bit, and the same byte has B6 clear for Read, and set for Write.  See 5.16.5 (register picture) and Figure 1 (read sequence).    However, you should probably read the Status register first (15).

As far as Logic Analyzers,

Anybody else have suggestions?

Cheers,
/dev
Title: Re: Arduino Yun / SPI Problem / Power Measuring CS5463
Post by: Blizzart on Sep 17, 2015, 10:25 am
Is the MODE pin connected?

Regarding the software, I don't think you're reading the "Instantaneous Power" register with this code:

The problem is that you are sending two bytes (Read, then 0x00) instead of one (00010010 = 0x12).  You have the correct description at the top.
Sorry for the misleading information, there was a copy paste mistake from my main sketch, it should have said: "Read the Config Register" that is why I am sending the 0x00 bit to initialize the read operation and "collect" the bytes with synch1.
I fixed the mistake of sending two read bytes (Read and 0x00).
Right now I am just reading zeros on the high middle and low bit of the config register, though I am expecting (0x34); (0xC); (0x34) because I just set the register to those values.
I will try to check what information the status register will provide me.
I connected the mode pin to pin 9 on my Arduino and pulled it high to initialize auto boot.
Thanks for the advice with the logic analyzers, can you provide more information about that 3,3V to 5V mod? Soldering should not be an issue (I have a fair amount of SMD soldering experience). Considering the price I could still buy a better unit later on if I need the analog inputs or more features.

Here is my updated code:
Code: [Select]

/*
 CS5463 Single Phase Power Measuring IC

 Circuit:
 CS5463 attached to pins 8, 9, 12, 13:

 
 /*
// CS5463 Register Addresses
// B7 B6 B5 B4 B3 B2 B1 B0
// 0 W/R RA4 RA3 RA2 RA1 RA0 0
// W=1 R=0
        Read Write           Address
1 Config    = 0x0     0x40 0b00000  ; // Configuration
2 IDCoff    = 0x2     0x42 0b00001  ; // Current DC Offset
3 Ign         = 0x4     0x44 0b00010  ; // Current Gain
4 VDCoff      = 0x6     0x46 0b00011  ; // Voltage DC Offset
5 Vgn         = 0x8     0x48 0b00100  ; // Voltage Gain
6 CycleCount  = 0xA     0x4A 0b00101  ; // Number of A/D conversions used in one computation cycle (N)).
7 PulseRateE  = 0xC     0x4C 0b00110  ; // Sets the E1, E2 and E3 energy-to-frequency output pulse rate.
8 I           = 0xE     0x4E 0b00111  ; // Instantaneous Current
9 V           = 0x10   0x50 0b01000  ; // Instantaneous Voltage
10 P           = 0x12   0x52 0b01001  ; // Instantaneous Power
11 PActive     = 0x14   0x54 0b01010  ; // Active (Real) Power
12 IRMS        = 0x16   0x56 0b01011  ; // RMS Current
13 VRMS        = 0x18   0x58 0b01100  ; // RMS Voltage
14 Epsilon     = 0x1A   0x5A 0b01101  ; // Ratio of line frequency to output word rate (OWR)
15 Poff        = 0x1C   0x5C 0b01110  ; // Power Offset
16 Status      = 0x1E   0x5E 0b01111  ; // Status
17 IACoff      = 0x20   0x60 0b10000  ; // Current AC (RMS) Offset
18 VACoff      = 0x22   0x62 0b10001  ; // Voltage AC (RMS) Offset
19 Mode        = 0x24   0x64 0b10010  ; // Operation Mode
20 T           = 0x26   0x66 0b10011  ; // Temperature
21 QAVG        = 0x28   0x68 0b10100  ; // Average Reactive Power
22 Q           = 0x2A   0x6A 0b10101  ; // Instantaneous Reactive Power
23 IPeak       = 0x2C   0x6C 0b10110  ; // Peak Current
24 VPeak       = 0x2E   0x6E 0b10111  ; // Peak Voltage
25 QTrig       = 0x30   0x70 0b11000  ; // Reactive Power calculated from Power Triangle
26 PF          = 0x32   0x72 0b11001  ; // Power Factor
27 Mask        = 0x34   0x74 0b11010  ; // Interrupt Mask
28 S           = 0x36   0x76 0b11011  ; // Apparent Power
29 Ctrl        = 0x38   0x78 0b11100  ; // Control
30 PH          = 0x3A   0x7A 0b11101  ; // Harmonic Active Power
31 PFA         = 0x3C   0x7C 0b11110  ; // Fundamental Active Power
32 QF          = 0x3E   0x7E 0b11111  ; // Fundamental Reactive Power / Page


 created 17. September 2015
 
 
 */

// the CS5463 communicates using SPI, so include the library:
#include <SPI.h>



const int CS = 8; // Assign the Chip Select signal to pin 8
const int RESET = 13; // Assign Reset to pin 13
const int MODE = 9; // Assign Mode to pin 9

byte H_ByteC;          //High Byte
byte M_ByteC;          //Middle Byte
byte L_ByteC;          //Low Byte

byte H_ByteV;          //High Byte
byte M_ByteV;          //Middle Byte
byte L_ByteV;          //Low Byte

byte Read  = 0B0000000;
byte Write = 0B0100000;
int junk;

void setup() {   

  pinMode(CS, OUTPUT); //initalize the chip select pin;
  pinMode(RESET, OUTPUT); //initalize the RESET pin;
  pinMode(MODE, OUTPUT); //initialize the MODE pin;

  digitalWrite(CS, HIGH);
  digitalWrite(RESET, HIGH);
  digitalWrite(MODE, HIGH);
 
  delay (100);
 
 
 //Create a serial connection to display the data on the terminal.   
  Serial.begin(9600);
 
  //start the SPI library;
  SPI.begin();
 
    SPI.setBitOrder(MSBFIRST);
 SPI.setClockDivider(8);
 
 digitalWrite(RESET, LOW);
  delay (100);
  digitalWrite(RESET, HIGH);
 delay (100);
 
 
 digitalWrite(CS, LOW); //Chip select to low to initialise comms with CS5463
 
 //Set Config register
 
 SPI.transfer(0x40);
 SPI.transfer(0x34);  //3 bytes of data to set 24bits of config register       
   SPI.transfer(0xC);     
   SPI.transfer(0x34);
   
 digitalWrite(CS, HIGH);  //Chip select to HIGH to disable comms with CS5463 
}


void loop()
{
 digitalWrite(CS, LOW);
 SPI.transfer(0x00);             //Read the Config Register                                 
 H_ByteC = SPI.transfer(0xFF);   //Reads high byte and writes sync1                                     
 M_ByteC = SPI.transfer(0xFF);   //Reads middle byte and writes sync1                                   
 L_ByteC = SPI.transfer(0xFF);   //Reads low byte and writes sync1                                   
 digitalWrite(CS, HIGH);
 
 delay (100);

 digitalWrite(CS, LOW);
 SPI.transfer( Read | (9 << 1 )); //Instantaneous Voltage // LSB "B0" is always zero
 H_ByteV = SPI.transfer(0xFF);   //Reads high byte and writes sync1                                     
 M_ByteV = SPI.transfer(0xFF);   //Reads middle byte and writes sync1                                   
 L_ByteV = SPI.transfer(0xFF);   //Reads low byte and writes sync1
digitalWrite(CS, HIGH);
 
   delay (100);

Serial.print("Config: ");
Serial.println(H_ByteC,BIN);
Serial.println(M_ByteC,BIN);
Serial.println(L_ByteC,BIN) ;
delay (100);

Serial.print("Instantaneous Voltage: ");
Serial.println(H_ByteV,BIN);
Serial.println(M_ByteV,BIN);
Serial.println(L_ByteV,BIN) ;
delay (100);
}


Title: Re: Arduino Yun / SPI Problem / Power Measuring CS5463
Post by: Blizzart on Sep 17, 2015, 10:27 am
Here my main code if that's for any help, though I would like to figure out how to read and write the config file properly and read the status register before I put it all together and start measuring and reading the calculated values.
Title: Re: Arduino Yun / SPI Problem / Power Measuring CS5463
Post by: sonnyyu on Sep 17, 2015, 11:10 am
...
3. Eliminate interference from power supply:

Use isolated DC/DC Converter for Arduino Yun only. motor shield use its own DC/DC converter

(http://i.imgur.com/hZBtQjf.gif)

(http://i.imgur.com/ULWALMs.png)
...
Use isolated (few KV isolated)  DC/DC Converter to separate power supply.


ADUM3151 (ADUM315X)  3.75 kV, Dedicated Isolators for SPI Interfaces

(http://i.imgur.com/WWtYvw2.png)





Title: Re: Arduino Yun / SPI Problem / Power Measuring CS5463
Post by: Blizzart on Sep 17, 2015, 11:15 am
Use isolated (few KV isolated)  DC/DC Converter to separate power supply.


Is that really necessary for my test setup?
I am powering the CS5463 through the Arduino Yun and have no other external source coming in.
Even in my second step I believe that the 0,7V sinus signal should do no harm to the CS5463 or the Arduino Yun.
I do know that I need the isolation as soon as I start doing real measurements and when I am connecting an external power source to my bread board, but for now the Arduino is doing it all.

Cheers
Title: Re: Arduino Yun / SPI Problem / Power Measuring CS5463
Post by: sonnyyu on Sep 17, 2015, 11:32 am
for  0,7V sinus signal , No
for  line voltage 110/220/240 V AC, Yes

...
I soldered the CS5463 to a breakout board and connected everything on a breadboard.
...
I'm sure you understand breadboard the does not meet safety requirements once at line voltage.



Title: Re: Arduino Yun / SPI Problem / Power Measuring CS5463
Post by: Blizzart on Sep 17, 2015, 11:38 am
for  0,7V sinus signal , No
for  line voltage 110/220/240 V AC, Yes

I'm sure you understand breadboard the does not meet safety requirements once at line voltage.


Perfect so I can focus on the code for now.
The first test with line Voltage will be on a soldered stripboard, as soon as that works I'll carry on to an actual PCB layout.
Title: Re: Arduino Yun / SPI Problem / Power Measuring CS5463
Post by: -dev on Sep 17, 2015, 05:48 pm
Quote
I connected the mode pin to pin 9 on my Arduino and pulled it high to initialize auto boot.
According to the spec,

Quote
MODE - High, enables the "auto-boot" mode. The mode pin has an internal pull-down resistor.

Section 8. AUTO-BOOT MODE USING E2PROM

In auto-boot mode, the CS5463 downloads the required commands and register data from an external serial E2PROM, allowing the CS5463 to begin performing energy measurements.
So... I don't think you want auto-boot mode.  Your schematic does not show an EEPROM.  This is really for letting the CS5463 configure itself, without any SPI commands from a host.  It will pull the configuration from the EEPROM and start running by itself.  You should have the MODE pin floating or tied to ground.

Quote
can you provide more information about that 3,3V to 5V mod?
There are a few ways to do it... You can replace the internal 5V-intolerant buffers with a 5V-tolerant part (some SMD soldering), or you can make an external voltage divider array.  I chose the latter.  That's the HW side.

For the SW, you also have to download some Cypress tools to modify a few bytes inside the cheapie LA.  That lets it be recognized by the Windows USB drivers for the LA software.  Of course, you have to modify some Windows INF files first before the Cypress tools will recognize the cheapie. :P

If you want to try it, go ahead and place your order, 'cuz it'll take a week to get to you.  I'll write up the step-by-step process in the meantime.  The reviews for the cheapie on DX.com point to all the information, but I'll gather it up into one place.

You can do some debugging with the oscilloscope.  Hook it to the MISO line to see what the CS5463 is sending, or to the MOSI line to see what your arduino is sending.  If you have two channels, do both.

Cheers,
/dev
Title: Re: Arduino Yun / SPI Problem / Power Measuring CS5463
Post by: Blizzart on Sep 18, 2015, 01:29 pm
According to the spec,
So... I don't think you want auto-boot mode.  Your schematic does not show an EEPROM.  This is really for letting the CS5463 configure itself, without any SPI commands from a host.  It will pull the configuration from the EEPROM and start running by itself.  You should have the MODE pin floating or tied to ground.

I did as you said and tied the mode pin to ground.
Now I am getting results from the CS5463 back but its still not the expected config values:
Code: [Select]

Config: 11111111
11111111
11111100
Config: 11111111
11111111
0
Config: 11111111
11111111
11110000
Config: 11111111
11111111
0
Config: 11111111
11111111
11111100
Config: 11111111
11111111
11110000
Config: 11111111
11111111
11000000
Config: 11111111
11111111
11000000
Config: 11111111
11111111
0
Config: 11111111
11111110
0
Config: 11111111
11111111
11110000
Config: 11111111
11111111
11111100
Config: 11111111
11111111
11111100
Config: 11111111
11111111
11111111
Config: 11111111
11111111
11111111
Config: 11111111
11111111
11110000
Config: 11111111
11111111
0



I am expecting :
Code: [Select]

Config:110100
1100
110100
Config:110100
1100
110100

and so on

Could that be a timing issue of the SPI Bus or is there still something wrong with me read and write routine?

Cheers
Title: Re: Arduino Yun / SPI Problem / Power Measuring CS5463
Post by: -dev on Sep 18, 2015, 04:23 pm
Neither your actual nor the expected Config register values match the last code that you posted.  You have to keep us up-to-date with your code.

Did you try just reading the status register?

BTW, You should consider defining some constants or types to make your code more readable.  For example:

Code: [Select]
// page 0 registers
static const uint8_t CONFIG         = 0;
static const uint8_t POWER          = 9; // instantaneous
static const uint8_t POWER_ACTIVE   = 10;
static const uint8_t STATUS         = 15;
static const uint8_t POWER_REACTIVE = 20;
   ...
// page 1 registers
static const uint8_t LOAD_MIN = 1;
   ...

// Write this first to select the "current" register page for successive Read/Write operations
static const uint8_t SELECT_PAGE = 0x1F;


...or with an enum:

Code: [Select]
enum CS5463_register_t {
  CONFIG         = 0,  // page 0 registers
  POWER          = 9,
  POWER_ACTIVE   = 10,
  STATUS         = 15,
  POWER_REACTIVE = 20,
     ...
  LOAD_MIN = 1, // page 1 registers
     ...
  SELECT_PAGE = 0x1F
};

You can define a few, as above, or all the registers.  Then accessing a register becomes:

Code: [Select]
SPI.transfer( Write | (CONFIG<<1) );
   or
SPI.transfer( Read | (CONFIG<<1) );

This will be much easier for you (and us) to understand what you meant to do.

Regarding the CONFIG register, I think you need to review the K value.  It's a divider to produce MCLK from crystal frequency.  While the crystal can be 2.5MHz to 20MHz, the MCLK must be between 2.5MHz and 5MHz (see section 5.12 and 6.1.1).  The config values in CS5463_SPI_V3.0.INO (0x000C00) and your first post (0x340C34) are not valid.

This is a fairly complicated chip, so I also encourage you to re-read the spec from top to bottom, making a note of any configurable item that affects its operation.  By the time you get to the bottom, you will know what the CONFIG register should contain.

Spec reading is something of an art... just accept that you may have to read all of it, every time you have a new question.  You may have ignored a sentence during a previous reading as being "irrelevant", and now you need the information it contains.  Unless you're lucky enough to have a photographic memory, you'll have to read it multiple times.

Cheers,
/dev
Title: Re: Arduino Yun / SPI Problem / Power Measuring CS5463
Post by: ShapeShifter on Sep 18, 2015, 05:12 pm
This is a fairly complicated chip, so I also encourage you to re-read the spec from top to bottom, making a note of any configurable item that affects its operation.  By the time you get to the bottom, you will know what the CONFIG register should contain.
Many times, the documentation will include a one or two page summary chart of all of the registers: no descriptions, just each register on its own line, with the individual fields shown and blocked out. If they have this, I will print out this page, and have it handy while reading the rest of the spec and the details of the registers. As details and settings become apparent, I write in the required field values on this printout. If the document doesn't have such a summary, like the one for this chip, I will make one.

If you fill in the fields as you are reading the document, by the time you get to the end, you probably have the full register contents figured out.


Quote
Spec reading is something of an art... just accept that you may have to read all of it, every time you have a new question.  You may have ignored a sentence during a previous reading as being "irrelevant", and now you need the information it contains.  Unless you're lucky enough to have a photographic memory, you'll have to read it multiple times.
VERY TRUE! 

You haven't lived until you've wasted days trying to get a programming pod to talk to a new processor chip, only to find that on page 240 of a 2259 page manual is the one and only sentence that indicates a particular pin MUST be pulled high on power up or else it comes up in a bootloader mode that ignores the JTAG port.  :smiley-mad:

And of course, this mostly happens when the customer is looking over your shoulder, wondering why the new board you built for them isn't doing anything...
Title: Re: Arduino Yun / SPI Problem / Power Measuring CS5463
Post by: Blizzart on Sep 23, 2015, 04:25 pm
I have been working on the code today and collected all the register addresses in an enum.
I did not understand fully why you split them into a page 0 and a page 1 register, could you please provide an explanation.

I did only write those values to the config register for testing so I could read out those same values to verify a working write and read process.
The default setting for the config register should be (0x000001). I am still not reading those values though.


And here the values the status register provides:
Code: [Select]

Status: 0
0
0
Status: 10000000
0
0
Status: 0
0
0
Status: 10000000
0
0
Status: 0
0
0
Status: 10000000
0
0
Status: 10000000
0
0
Status: 0
0
1
Status: 0
0
0
Status: 0
0
0
Status: 0
0
1
Status: 0
0
0
Status: 0
0
1


  

I did order a small logic analyzer and received it today, this one should work with the Saleae software. Logic Analyzer (http://www.amazon.de/Generic-Saleae-Analyzer-8Channel-support/dp/B00EXJ34DE/ref=sr_1_1?ie=UTF8&qid=1443018274&sr=8-1&keywords=logic+analyzer)
Title: Re: Arduino Yun / SPI Problem / Power Measuring CS5463
Post by: -dev on Sep 23, 2015, 05:38 pm
Quote
I did not understand fully why you split [the registers] into a page 0 and a page 1...
See Section 6.  It is divided into three subsections, one for each page.  Why?

In a Read/Write command byte, there are only 5 bits to select a register.  That means you can address 0..31.  Because there are more than 32 registers in this complicated chip, Cirrus had to implement multiple "pages" (see Section 5.15).  The way you select a page is by Writing the Page Register, at address 31.  Having selected the page (0, 1 or 3), all successive Read/Write commands are with respect to that page's list of registers.  Page 0 has 31 registers, Page 1 has 4 registers, and Page 3 has 4 registers, for a total of 40 registers.  The Page Register is a special case, as it "appears" on every page... that's how you switch pages.

Notice how the "No Load Threshold" register is at address 1, just like "Current DC Offset".  They're actually on different pages: Page 1 vs. Page 0.

You start out on Page 0, so unless you need access to one of the 8 other registers, you don't have to mess with doing a Page Register Write before every Page 0 Read/Write.

Quote
And here the values the status register provides:
Code please.  Oops, I see it's attached... I'll take a look

Quote
I did order a small logic analyzer and received it today
The model you purchased (http://sigrok.org/wiki/MCU123_Saleae_Logic_clone) has the same input buffer as the cheapie (http://sigrok.org/wiki/MCU123_USBee_AX_Pro_clone).  It will draw extra current when 5V logic signals are applied to the inputs.  This is definitely a problem on lines that are supposed to float (e.g., OneWire bus), and it may be a problem for the SPI lines.

IIRC, the input buffer, a NXP 74HC245 (http://www.nxp.com/documents/data_sheet/74HC_HCT245.pdf), can end up sinking 5mA on a 5V logic high (~4.7V).  I think that's the max that the CS5463 can drive on a digital output, like the MISO line.  Actually, 5mA is about the total current of the CS5463.  I still suggest replacing the 74HC245 with 74LCX245 (https://www.fairchildsemi.com/datasheets/74/74LCX245.pdf) (SMD desoldering/soldering), or using a voltage divider on the inputs (much easier).

Here's a plug-in voltage divider I soldered up, using 33K and 56K resistors I had on hand:

(http://forum.arduino.cc/index.php?action=dlattach;topic=347910.0;attach=138707)

(http://forum.arduino.cc/index.php?action=dlattach;topic=347910.0;attach=138705)

The black pin at the bottom is GND.  Tain't pretty, but it does the job.  :P  There is no issue if you use this LA with a 3.3V system.

Cheers,
/dev
Title: Re: Arduino Yun / SPI Problem / Power Measuring CS5463
Post by: -dev on Sep 23, 2015, 06:24 pm
Quote
And here the values the status register provides:

  Status: 0
  0
  0
  Status: 10000000
  0
  0
Actually, those look ok.  See Section 6.1.11.  That high bit is toggling between DRDY and !DRDY as the chip performs conversions.

You commented out the CONFIG read/write, so I have no idea what happened.  You must think I'm Santa Claus, who knows when you are sleeping, and knows when you're awake...  ;)

Cheers,
/dev
Title: Re: Arduino Yun / SPI Problem / Power Measuring CS5463
Post by: Blizzart on Sep 23, 2015, 06:35 pm
Actually, those look ok.  See Section 6.1.11.  That high bit is toggling between DRDY and !DRDY as the chip performs conversions.

You commented out the CONFIG read/write, so I have no idea what happened.  You must think I'm Santa Claus, who knows when you are sleeping, and knows when you're awake...  ;)

Cheers,
/dev
Sounds great that the status register makes sense, I only commented the Config read out in order to see the status values by itself, when i was testing the config register the values where changing after every reading cycle which did not make sense to me, shouldn't they be persistent over time?

Cheers
Title: Re: Arduino Yun / SPI Problem / Power Measuring CS5463
Post by: -dev on Sep 23, 2015, 07:28 pm
Quote
shouldn't [the CONFIG register] be persistent over time?
Yes, it should not change.  However...

To be blunt, we can't trust your interpretation of what you saw.  You must show us the code and the output it produces... together.

After that, you'll need to hook up your LA to confirm that the sketch really sends and receives what it prints.  You may need to attach screen prints of the LA software for us to interpret.

It's all about verification, at many levels.
Title: Re: Arduino Yun / SPI Problem / Power Measuring CS5463
Post by: Blizzart on Sep 28, 2015, 02:19 pm
I have done some testing and checked the values that I am sending over SPI.
I observed that the Arduino is sending the correct values to the CS5463, although the CS5463 responds to it with two phrases alternately.
In some cases it responds ([0][0][0][1]) which would be correct for the Config register. The first byte is the response to the register selection and byte 2-4 are my high middle and low byte. This results in a low byte value of 1 on my serial monitor.
The second case however delivers a ([0][128][0][1]) which means that the MSB of the high byte is a logic one instead of the expected logic 0.
I confirmed this behavior with the serial monitor and both the logic analyzer and my oscilloscope. After rebooting the Arduino the CS5463 behaved in the same way.
I lowered the SPI CLK to 1MHz (arduino clock divider=16) but it did not change the behavior.
EDIT: After checking more of the brodcasted bytes I also found the value ([0][128][0][5]) in the config register. There must be something wrong that makes it change over time. Could it be a wrong initialization of the SPI BUS and the CS5463 chip itself?


I attached the code I am using and the pictures of the LA and oscilloscope.
Right now I am rereading the spec sheet to get the correct configuration for measuring a 50Hz sinus wave.


Cheers!
Blizzart

 
Title: Re: Arduino Yun / SPI Problem / Power Measuring CS5463
Post by: -dev on Sep 28, 2015, 06:36 pm
(http://forum.arduino.cc/index.php?action=dlattach;topic=347910.0;attach=139130)

That clock signal looks nasty, but it could be aliasing.  You should zoom in (sample faster) to see how they look.  I'm a little suspicious because there's similar noise on the other lines.  How long are these wires? 

Do you have decoupling bypass caps?  See Figure 18, which shows three.  I don't see any on the schematic.

For now, I think I'd let the MODE pin just float LOW, instead of driving it from the Arduino.

Cheers,
/dev
Title: Re: Arduino Yun / SPI Problem / Power Measuring CS5463
Post by: ShapeShifter on Sep 28, 2015, 10:46 pm
Yes, there looks like a lot of nasty ringing on that clock pulse. It is very much worth it zooming in on them to get a better view. It looks like there are only four clocks per group, where the logic analyzer shows four? It seems like the scope has enough resolution to not be aliasing those pulses, but zooming in would prove that one way or another.

I agree, the noise on the other signals, which are coincident with the clock, makes me suspect long leads and insufficient bulk and/or bypass capacitance at the chip.
Title: Re: Arduino Yun / SPI Problem / Power Measuring CS5463
Post by: Blizzart on Sep 29, 2015, 11:01 am
I checked the leads on my oscilloscope and shortened them as much as possible, and made sure that the ground connection is decent.
Then I zoomed in on the clock line and and snapped a couple of pictures for you.

(http://forum.arduino.cc/index.php?action=dlattach;topic=347910.0;attach=139189)
(http://forum.arduino.cc/index.php?action=dlattach;topic=347910.0;attach=139193)

I also measured the SPI pins straight on the arduino with no connection to the CS5463 to provide a reference of the signal.

(http://forum.arduino.cc/index.php?action=dlattach;topic=347910.0;attach=139183)
(http://forum.arduino.cc/index.php?action=dlattach;topic=347910.0;attach=139187)

I added some decoupling caps to the VA+ and VD+ inputs with a capacity of 1uF each. (C1 and C2 in the schematic)

(http://forum.arduino.cc/index.php?action=dlattach;topic=347910.0;attach=139195)

EDIT:
I found a mistake in my code, the WRITE byte in my enum should be 64 instead of 32.
After commenting out the reading of the status register the config register behaves completely normal and I can write values to it and verify them through the read process.
However, when I leave the status read in the code, my config values are still changing.
Title: Re: Arduino Yun / SPI Problem / Power Measuring CS5463
Post by: ShapeShifter on Sep 29, 2015, 02:32 pm
That clock signal looks reasonable. Adding some larger bulk capacitance is usually good, but for bypass caps, larger is not better: smaller caps can better smooth high frequency current changes. Usually 0.1uF or 0.01uF caps are used for bypass caps. The reference schematic uses 0.1uF. I would add some in addition to the caps you have. The larger caps smooth out the slower high current variations, the smaller ones take care of the higher frequency switching variations.
Title: Re: Arduino Yun / SPI Problem / Power Measuring CS5463
Post by: Blizzart on Sep 29, 2015, 02:49 pm
That clock signal looks reasonable. Adding some larger bulk capacitance is usually good, but for bypass caps, larger is not better: smaller caps can better smooth high frequency current changes. Usually 0.1uF or 0.01uF caps are used for bypass caps. The reference schematic uses 0.1uF. I would add some in addition to the caps you have. The larger caps smooth out the slower high current variations, the smaller ones take care of the higher frequency switching variations.
Thanks, for the explanation. I do understand the characteristics and behavior of a capacitor and high frequency signals or spikes on a power line, I added another 0.01uF capacitor for the power inputs.
Title: Re: Arduino Yun / SPI Problem / Power Measuring CS5463
Post by: Blizzart on Sep 29, 2015, 03:22 pm
I changed to a new version of code with more register writes.
The writing process seems totally fine in the LA.

(http://forum.arduino.cc/index.php?action=dlattach;topic=347910.0;attach=139212)

I can read out the same register values as long as I only read one register and comment out everything else, as soon as I read the config and status in one sketch or any combinations of two registers the values are changing over time.
Code is attached.
Title: Re: Arduino Yun / SPI Problem / Power Measuring CS5463
Post by: -dev on Sep 29, 2015, 04:36 pm
I agree, those signals look much better!  There should also be a bypass cap on Vref.  That may affect the readings, but doubt it would affect the register contents.

Could I suggest something like this at the end of loop, to pace the output and keep serial interrupts from delaying the SPI transfers?  It keeps the LA traces together a little nicer:

Code: [Select]
  Serial.flush(); // let all the serial TX interrupts finish...

  static uint32_t lastTime = 0; // I would usually put this at file scope and
                                // initialize it to millis() at the end of setup
  while (millis() - lastTime < 1000) // or 2000ms?
    ;
  lastTime = millis();
}

This will make it a little easier to capture, too.

What output do you get when you read any two registers?

There is an IC bit in the status register that indicates an "invalid command" (if IC == 0).  Be sure to check that.

And you're reading too many bytes for VOLTAGE_RMS, CURRENT_RMS, POWER and TEMPERATURE.  Those are 1-byte registers.  Although the spec says

Quote from: Section 5.14
Register writes must be followed by three bytes of data.
Register reads can return up to four bytes of data.
...I can only find one-byte or three-byte registers.  ???

Cheers,
/dev
Title: Re: Arduino Yun / SPI Problem / Power Measuring CS5463
Post by: dennislwy on Dec 30, 2015, 09:21 am
I changed to a new version of code with more register writes.
The writing process seems totally fine in the LA.

(http://forum.arduino.cc/index.php?action=dlattach;topic=347910.0;attach=139212)

I can read out the same register values as long as I only read one register and comment out everything else, as soon as I read the config and status in one sketch or any combinations of two registers the values are changing over time.
Code is attached.
Hi Blizzart, I also facing the same issue, reading CONFIG or STATUS only is ok (comment out everything else)
I am using Arduino Nano 5V. I unable to get a correct TEMPERATURE register reading as well, my room temperature expected around 24-26'C. But readings i get are

Code: [Select]
TEMPERATURE:
10000
11110110
0
-2560


TEMPERATURE:
10000
11110110
0
-2560


TEMPERATURE:
10001
100100
0
9216


Below is the SPI setting i tried
Code: [Select]

  //start the SPI library;
  SPI.begin();
  SPI.setBitOrder(MSBFIRST);
  SPI.setClockDivider(64);
  SPI.setDataMode(SPI_MODE0);

  digitalWrite(CS, LOW);

  digitalWrite(RESET_PIN, LOW);
  delay (100);
  digitalWrite(RESET_PIN, HIGH);
  delay (100);

  //Sync commands
  SPI.transfer(SYNC1);   
  SPI.transfer(SYNC1);     
  SPI.transfer(SYNC1);   
  SPI.transfer(SYNC0);
   
  digitalWrite(CS, HIGH);


Do you have a working solution? can share?
Title: Re: Arduino Yun / SPI Problem / Power Measuring CS5463
Post by: Blizzart on Jan 10, 2016, 12:35 pm
Hey dennislwy,

I'm sorry for the delayed reply.
The problem you are facing is that you're trying to read out the CS5463 with 16MHz over SPI, but it only supports speeds up to 4MHz.
You are using the wrong code for setting up the SPI frequency (they changed it at some point), now you're not setting a divider any more, but the frequency itself.
This code should work:

Code: [Select]

 //start the SPI library;
  SPI.begin();
  SPI.beginTransaction(SPISettings(1000000,MSBFIRST,SPI_MODE0)); //Set SPI to 1MHz, MSBFIRST and SPI_MODE0
 
 
//Run a Hardware Reset of the CS5463
digitalWrite(CS, LOW);

digitalWrite(RESET_PIN, LOW);
delay (100);
digitalWrite(RESET_PIN, HIGH);
delay (100);

//Run a Soft Reset of the CS5463
//Sync commands
   SPI.transfer(SYNC1);   
   SPI.transfer(SYNC1);     
   SPI.transfer(SYNC1);   
   SPI.transfer(SYNC0);
   
   digitalWrite(CS, HIGH);

delay (100);
Title: Re: Arduino Yun / SPI Problem / Power Measuring CS5463
Post by: alan_lima on Jul 14, 2016, 12:14 am
Good evening,
I'm trying to create a meter using this IC and am basing myself on dennislwy friend code, but I'm also having the same problem, even without any signal in voltage and current inputs are my readings:

Code: [Select]
5
250
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
255
255
255
255
255
255
255
255
255
255
255
255
0
63
0
0
0
0
255
255
255
255
255
255
255
255
255
0
255
0
0
0
0
255
255
255
255
255
255
255
255
255
255
255
255
96
0
0
0
0
0
255
255
255
255
255
255
255
255
255
0
15
0
0
0
0
255
255
255
255
255
255
192
255
0
0
0
0
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
63
224
0
0
0
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
0
124
0
0
0
0
255
255
255
255
255
255
255
255
255
128
7
0
0
0
0
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
0
0
0
3
0
96
255
255
255
255
255
255
112
0
0
0
0
0
255
255
255
255
255
255
255
255
255
255
255
255
240
7
0
0
0
0
255
255
255
255
255
255
255
255
255
255
255
255
248
0
128
0
0
0
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
128
255
0
0
0
0
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
240
255
128
255
255
255
0
0
0
0
0
7
255
255
255
0
255
0
0
0
0
255
255
255
255
255
255
255
255
255
255
127
248
255
0


I'm using a simple code just to start doing the readings.

Code: [Select]
#include<SPI.h> //declaração da biblioteca de comunicação SPI

enum Registradores_CS5463{ //criando variáreis para os registradores do CS5463 e atribuindo valores fixos para elas

  // Registradores da Página 0
  CONFIGURACAO = 0,
  CORRENTE_DC_OFFSET = 1,
  GANHO_CORRENTE = 2,
  TENSAO_DC_OFFSET = 3,
  GANHO_TENSAO = 4,
  CONTADOR_CICLOS = 5, //número de conversões usado no conversor A/D
  TAXA_PULSOS_E = 6, //define a taxa de pulsos das saídas de energia E1, E2 e E3
  CORRENTE = 7,
  TENSAO = 8,
  POTENCIA_INSTANTANEA = 9,
  POTENCIA_REAL = 10,
  CORRENTE_RMS = 11,
  TENSAO_RMS = 12,
  EPSILON = 13,
  POTENCIA_OFFSET = 14,
  ESTATUS = 15,
  CORRENTE_AC_OFFSET = 16,//RMS
  TENSAO_AC_OFFSET = 17, //RMS
  MODO = 18,
  TEMPERATURA = 19,
  POTENCIA_REATIVA_MEDIA = 20,
  POTENCIA_REATIVA_INSTANTANEA = 21,
  PICO_CORRENTE = 22,
  PICO_TENSAO = 23,
  POTENCIA_REATIVA_TRIANGULO = 24,
  FATOR_POTENCIA = 25,
  MASCARA_INTERRUPCAO = 26,
  POTENCIA_APARENTE = 27,
  CONTROLE = 28,
  POTENCIA_ATIVA_HARMONICA = 29,
  POTENCIA_ATIVA_FUNDAMENTAL = 30,
  POTENCIA_REATIVA_FUNDAMENTAL = 31,


  // Registradores da Página 1
  LARG_PULSO_ENERGIA = 0,
  LIMITE_SEM_CARGA = 1,
  GANHO_TEMPERATURA = 2,
  TEMPERATURA_OFFSET = 3,


  // Registradores da Página 3
  INTERVALO_TENSAO_SAG = 6, //tempo em que a tensão deve se manter baixa para ativar a detecção de falha de tensão
  NIVEL_TENSAO_SAG = 7, //valor mínimo de tensão para ativar a detecção de falha de tensão
  INTERVALO_CORRENTE_SAG = 10, //tempo de falta de corrente para ativar a detecção de falha de corrente
  NIVEL_CORRENTE_SAG = 11, //valor mínimo de corrente para ativar a detecção de falha de corrente


  //COMANDOS
  LEITURA = 0,
  ESCRITA = 64,
  SYNC0 = 254,
  SYNC1 = 255,
};

const int PINO_CS = 10; //pino de controle do slave

byte H_VALOR_TENSAO_RMS;
byte M_VALOR_TENSAO_RMS;
byte L_VALOR_TENSAO_RMS;

byte H_VALOR_CORRENTE_RMS;
byte M_VALOR_CORRENTE_RMS;
byte L_VALOR_CORRENTE_RMS;

byte H_VALOR_POTENCIA_REAL;
byte M_VALOR_POTENCIA_REAL;
byte L_VALOR_POTENCIA_REAL;

byte H_VALOR_POTENCIA_APARENTE;
byte M_VALOR_POTENCIA_APARENTE;
byte L_VALOR_POTENCIA_APARENTE;

byte H_VALOR_POTENCIA_REATIVA;
byte M_VALOR_POTENCIA_REATIVA;
byte L_VALOR_POTENCIA_REATIVA;

void setup (){

pinMode(PINO_CS, OUTPUT); //define pino slave como saída
digitalWrite(PINO_CS, HIGH);

Serial.begin(9600);

SPI.begin();

SPI.setBitOrder(MSBFIRST);
SPI.setClockDivider(16);
SPI.setDataMode(SPI_MODE0);

delay(100);

//Configura o registrador CONFIGURACAO
digitalWrite(PINO_CS, LOW); //Seleciona o slave CS5463
SPI.transfer(0x40); //1º byte (comando de escrita e endereço do registrador CONFIGURACAO) 0100 0000
SPI.transfer(0x00); //2º byte (configuração) 0000 0000 - ultimo bit define PGA (ganho do amplificador de corrente) como 10x
SPI.transfer(0x00); //3º byte (configuração) 0000 0000
SPI.transfer(0x01); //4º byte (configuração) 0000 0001 - ultimo bit define o divisor de clock como 1
digitalWrite(PINO_CS, HIGH); //Desativa o slave CS5463

//Configura o registrador MODO
digitalWrite(PINO_CS, LOW); //Seleciona o slave CS5463
SPI.transfer(0x64); //1º byte (comando de escrita e endereço do registrador MODO) 0110 0100
SPI.transfer(0x00); //2º byte (configuração) 0000 0000
SPI.transfer(0x00); //3º byte (configuração) 0000 0000
SPI.transfer(0x01); //4º byte (configuração) 0000 0001 - ultimo bit ativa AFC
digitalWrite(PINO_CS, HIGH); //Desativa o slave CS5463

//Configura o registrador CONTROLE
digitalWrite(PINO_CS, LOW); //Seleciona o slave CS5463
SPI.transfer(0x78); //1º byte (comando de escrita e endereço do registrador CONTROLE) 0111 1000
SPI.transfer(0x00); //2º byte (configuração) 0000 0000
SPI.transfer(0x00); //3º byte (configuração) 0000 0000
SPI.transfer(0x04); //4º byte (configuração) 0000 0100 - bit 1 desativa o pino CPUCLK para economizar energia
digitalWrite(PINO_CS, HIGH); //Desativa o slave CS5463
}

void loop()
{
  digitalWrite(PINO_CS, LOW);
  SPI.transfer(0x18);
  H_VALOR_TENSAO_RMS = SPI.transfer(SYNC1);
  M_VALOR_TENSAO_RMS = SPI.transfer(SYNC1);
  L_VALOR_TENSAO_RMS = SPI.transfer(SYNC1);
  digitalWrite(PINO_CS, HIGH);

Serial.println(H_VALOR_TENSAO_RMS);
Serial.println(M_VALOR_TENSAO_RMS);
Serial.println(L_VALOR_TENSAO_RMS);

}


If you can give help I would greatly appreciate it.
Title: Re: Arduino Yun / SPI Problem / Power Measuring CS5463
Post by: Blizzart on Jul 14, 2016, 12:25 am
Hey alan_lima

I didn't read your whole code, but I can tell you that you are using the wrong SPI settings.
Try exchanging the following part:

SPI.begin();

SPI.setBitOrder(MSBFIRST);
SPI.setClockDivider(16);
SPI.setDataMode(SPI_MODE0);

delay(100);


with that:
Code: [Select]


//start the SPI library;
  SPI.begin();
  SPI.beginTransaction(SPISettings(1000000,MSBFIRST,SPI_MODE0)); //Set SPI to 1MHz, MSBFIRST and SPI_MODE0
  



Title: Re: Arduino Yun / SPI Problem / Power Measuring CS5463
Post by: alan_lima on Jul 14, 2016, 02:26 am
Thank Blizzart,
I tried it with the changes you suggested but not changed.

I understand that SPI.setClockDivider line of code (16); is dividing the clock by 16 like the Arduino clock is 16Mhz, is 1 MHz which is within the acceptable CS5463 value. The other parameters are the same.
If you can give any other tips would greatly appreciate it, I need to be able to make this project work as soon as possible.
Title: Re: Arduino Yun / SPI Problem / Power Measuring CS5463
Post by: Blizzart on Jul 14, 2016, 03:00 am
Can you please post the full code you used  after you did the changes?
Blizzart
Title: Re: Arduino Yun / SPI Problem / Power Measuring CS5463
Post by: alan_lima on Jul 14, 2016, 03:50 pm
Blizzard, I had read the whole topic, but I will re-read (my English is poor and I have missed something) and try again and put the result.
Title: Re: Arduino Yun / SPI Problem / Power Measuring CS5463
Post by: alan_lima on Jul 14, 2016, 10:01 pm
I tried using your code with as little change as possible. Just let the CS5463 the mode pin on the direct GND and direct reset pin VCC and used the pin 10 as CS (I'm using Arduino UNO). But readings still wrong. I'm using a protobord'll make a plate with welded components to reduce the possibility of poor contact. You could build your project with this IC and the Arduino? If you have any tip or idea to give me thank you very much, I need to be able to make this work as soon as possible is for a final project of my graduation from college.

Title: Re: Arduino Yun / SPI Problem / Power Measuring CS5463
Post by: Blizzart on Jul 14, 2016, 10:06 pm
Can you please provide the latest version of your code?
Blizzart
Title: Re: Arduino Yun / SPI Problem / Power Measuring CS5463
Post by: alan_lima on Jul 14, 2016, 10:09 pm
This is the code I used:

Code: [Select]
enum CS5463_register_t {
  
 //Register Page 0
 CONFIG = 0,   CURRENT_DC_OFFSET = 1,   CURRENT_GAIN = 2,   VOLTRAGE_DC_OFFSET = 3,   VOLTAGE_GAIN = 4,   CYCLE_COUNT = 5,   PULSE_RATE_E = 6,   CURRENT = 7,   VOLTAGE = 8,   POWER = 9,   POWER_ACTIVE = 10, CURRENT_RMS = 11,
 VOLTAGE_RMS = 12, EPSILON = 13, POWER_OFFSET = 14,
 STATUS = 15,
 CURRENT_AC_OFFSET = 16, VOLTAGE_AC_OFFSET = 17,
 MODE = 18, TEMPERATURE = 19,
 POWER_REACTIVE_AVERAGE = 20, POWER_REACTIVE = 21, CURRENT_PEAK = 22,
 VOLTAGE_PEAK = 23,
 POWER_REACTIVE_TRIANGLE = 24,
 POWERFACTOR = 25, MASK_INTERUPT = 26, POWER_APPARENT = 27, CONTROL = 28, POWER_ACTIVE_HARMONIC = 29, POWER_ACTIVE_FUNDAMENTAL = 30, POWER_REACTIVE_FUNDAMENTAL = 31,
    
 //Register Page 1
 PULSE_WIDTH = 0,
 LOAD_MIN = 1,
 TEMPERATURE_GAIN = 2,
 TEMPERATURE_OFFSET = 3,
 
 //Register Page 3
 VOLTAGE_SAG_DURATION = 6,
 VOLTAGE_SAG_LEVEL = 7,
 CURRENT_SAG_DURATION = 10,
 CURRENT_SAG_LEVEL = 11,

 // COMMANDS
 Read = 0,
 Write = 64,
 SYNC0 = 254, //SYNC 0 Command: Last byte of a serial port re-initialization sequence
 SYNC1 = 255, //SYNC 1 Command: Used during reads and serial port initialization.
 SELECT_PAGE = 0x1F,
 START_CONTINOUS = 0xE8,
 
}
;
const int CS = 10; // Assign the Chip Select signal to pin 8
//const int RESET_PIN = 13; // Assign Reset to pin 13
//const int MODE_PIN = 9; // Assign Mode to pin 9


//Bytes after register read
byte H_Byte_CONFIG;          //High Byte
byte M_Byte_CONFIG;          //Middle Byte
byte L_Byte_CONFIG;          //Low Byte

byte H_Byte_STATUS;          
byte M_Byte_STATUS;          
byte L_Byte_STATUS;          

byte H_Byte_VOLTAGE_RMS;
byte M_Byte_VOLTAGE_RMS;
byte L_Byte_VOLTAGE_RMS;

byte H_Byte_CURRENT_RMS;
byte M_Byte_CURRENT_RMS;
byte L_Byte_CURRENT_RMS;

byte H_Byte_POWER;
byte M_Byte_POWER;
byte L_Byte_POWER;

byte H_Byte_TEMPERATURE;
byte M_Byte_TEMPERATURE;
byte L_Byte_TEMPERATURE;

void setup() {  

  pinMode(CS, OUTPUT); //initalize the chip select pin;
//  pinMode(RESET_PIN, OUTPUT); //initalize the RESET pin;
//  pinMode(MODE_PIN, OUTPUT); //initialize the MODE pin;

  digitalWrite(CS, HIGH);
//  digitalWrite(RESET_PIN, HIGH);
//  digitalWrite(MODE_PIN, LOW);
  
  delay (100);
  
  
 //Create a serial connection to display the data on the terminal.  
  Serial.begin(9600);
  
//start the SPI library;
  SPI.begin();
  SPI.beginTransaction(SPISettings(1000000,MSBFIRST,SPI_MODE0)); //Set SPI to 1MHz, MSBFIRST and SPI_MODE0
  

 
 
 digitalWrite(CS, LOW);
 
// digitalWrite(RESET_PIN, LOW);
// delay (100);
// digitalWrite(RESET_PIN, HIGH);
// delay (100);
 
 //Sync commands
   SPI.transfer(SYNC1);    
   SPI.transfer(SYNC1);    
   SPI.transfer(SYNC1);    
   SPI.transfer(SYNC0);
  
   digitalWrite(CS, HIGH);
 
 delay (100);
 
 //Set Config register
 digitalWrite(CS, LOW); //Chip select to low to initialise comms with CS5463
 SPI.transfer( Write | (CONFIG<<1) );
 SPI.transfer(0x00);   //3 bytes of data to set 24bits of config register        
   SPI.transfer(0x00);    
   SPI.transfer(0x01);
    digitalWrite(CS, HIGH);   //Chip select to HIGH to disable comms with CS5463  

 //Set Mask register
 digitalWrite(CS, LOW);
 SPI.transfer( Write | (MASK_INTERUPT<<1) );
 SPI.transfer(0x00);   //3 bytes of data to set 24bits of mask register (Set for no interrupts)
 SPI.transfer(0x00);    
 SPI.transfer(0x00);
 digitalWrite(CS, HIGH);  
 
 //Set Mode register
 digitalWrite(CS, LOW);
 SPI.transfer( Write | (MODE<<1) );
 SPI.transfer(0x00);   //Sets High pass filters on Voltage and Current lines, sets automatic line frequency measurements
 SPI.transfer(0x00);    
 SPI.transfer(0x01);
 digitalWrite(CS, HIGH);
 
 //Set Control register
 digitalWrite(CS, LOW);
 SPI.transfer( Write | (CONTROL<<1) );
 SPI.transfer(0x00);   //Disables CPUCLK
 SPI.transfer(0x00);    
 SPI.transfer(0x4);
 digitalWrite(CS, HIGH);

 digitalWrite(CS, LOW);
 SPI.transfer(START_CONTINOUS);
 digitalWrite(CS, HIGH);
 
 
 }


void loop()
{
 digitalWrite(CS, LOW);
 SPI.transfer( Read | (CONFIG << 1 ));     //Read the Config Register                                
 H_Byte_CONFIG = SPI.transfer(SYNC1);   //Reads high byte and writes sync1                                      
 M_Byte_CONFIG = SPI.transfer(SYNC1);   //Reads middle byte and writes sync1                                    
 L_Byte_CONFIG = SPI.transfer(SYNC1);   //Reads low byte and writes sync1                                  
 //delay (10);
 digitalWrite(CS, HIGH);
 
 //delay (10);
 
 digitalWrite(CS, LOW);
 SPI.transfer( Read | (STATUS << 1 )); //Status //LSB "B0" is always zero
 H_Byte_STATUS = SPI.transfer(SYNC1);   //Reads high byte and writes sync1                                      
 M_Byte_STATUS = SPI.transfer(SYNC1);   //Reads middle byte and writes sync1                                    
 L_Byte_STATUS = SPI.transfer(SYNC1);   //Reads low byte and writes sync1
 //delay (10);
 digitalWrite(CS, HIGH);
 
 
 digitalWrite(CS, LOW);
 SPI.transfer( Read | (VOLTAGE_RMS << 1 ));
 H_Byte_VOLTAGE_RMS = SPI.transfer(SYNC1);   //Reads high byte and writes sync1                                      
 M_Byte_VOLTAGE_RMS = SPI.transfer(SYNC1);   //Reads middle byte and writes sync1                                    
 L_Byte_VOLTAGE_RMS = SPI.transfer(SYNC1);   //Reads low byte and writes sync1
 digitalWrite(CS, HIGH);
 
 digitalWrite(CS, LOW);
 SPI.transfer( Read | (CURRENT_RMS << 1 ));
 H_Byte_CURRENT_RMS = SPI.transfer(SYNC1);   //Reads high byte and writes sync1                                      
 M_Byte_CURRENT_RMS = SPI.transfer(SYNC1);   //Reads middle byte and writes sync1                                    
 L_Byte_CURRENT_RMS = SPI.transfer(SYNC1);   //Reads low byte and writes sync1
 digitalWrite(CS, HIGH);
 
 digitalWrite(CS, LOW);
 SPI.transfer( Read | (POWER << 1 ));
 H_Byte_POWER = SPI.transfer(SYNC1);   //Reads high byte and writes sync1                                      
 M_Byte_POWER = SPI.transfer(SYNC1);   //Reads middle byte and writes sync1                                    
 L_Byte_POWER = SPI.transfer(SYNC1);   //Reads low byte and writes sync1
 digitalWrite(CS, HIGH);
 
 digitalWrite(CS, LOW);
 SPI.transfer( Read | (TEMPERATURE << 1 ));
 H_Byte_TEMPERATURE = SPI.transfer(SYNC1);   //Reads high byte and writes sync1                                      
 M_Byte_TEMPERATURE = SPI.transfer(SYNC1);   //Reads middle byte and writes sync1                                    
 L_Byte_TEMPERATURE = SPI.transfer(SYNC1);   //Reads low byte and writes sync1
 digitalWrite(CS, HIGH);
 
 
 int value_VOLTAGE_RMS = (H_Byte_VOLTAGE_RMS << 16) |(M_Byte_VOLTAGE_RMS << 8) | L_Byte_VOLTAGE_RMS ;
 int value_CURRENT_RMS = (H_Byte_CURRENT_RMS << 16) |(M_Byte_CURRENT_RMS << 8) | L_Byte_CURRENT_RMS ;
 int value_POWER = (H_Byte_POWER << 16) |(M_Byte_POWER << 8) | L_Byte_POWER ;
 int value_TEMPERATURE = (H_Byte_TEMPERATURE << 16) |(M_Byte_TEMPERATURE << 8) | L_Byte_TEMPERATURE ;
 
 
 
 delay (10);

 Serial.print("Config: ");
 Serial.println(H_Byte_CONFIG,BIN);
 Serial.println(M_Byte_CONFIG,BIN);
 Serial.println(L_Byte_CONFIG,BIN);
 delay (10);
 Serial.print("Status: ");
 Serial.println(H_Byte_STATUS,BIN);
 Serial.println(M_Byte_STATUS,BIN);
 Serial.println(L_Byte_STATUS,BIN);
 delay (10);

 Serial.print("VOLTAGE_RMS: ");
 Serial.println(H_Byte_VOLTAGE_RMS,BIN);
 Serial.println(M_Byte_VOLTAGE_RMS,BIN);
 Serial.println(L_Byte_VOLTAGE_RMS,BIN);
 Serial.println(value_VOLTAGE_RMS);
 delay (10);
 
 Serial.print("CURRENT_RMS: ");
 Serial.println(H_Byte_CURRENT_RMS,BIN);
 Serial.println(M_Byte_CURRENT_RMS,BIN);
 Serial.println(L_Byte_CURRENT_RMS,BIN);
 Serial.println(value_CURRENT_RMS);
 delay (10);
 
 Serial.print("POWER: ");
 Serial.println(H_Byte_POWER,BIN);
 Serial.println(M_Byte_POWER,BIN);
 Serial.println(L_Byte_POWER,BIN);
 Serial.println(value_POWER);
 delay (10);
 
 Serial.print("TEMPERATURE: ");
 Serial.println(H_Byte_TEMPERATURE,BIN);
 Serial.println(M_Byte_TEMPERATURE,BIN);
 Serial.println(L_Byte_TEMPERATURE,BIN);
 Serial.println(value_TEMPERATURE);
 delay (10);
 
}


Title: Re: Arduino Yun / SPI Problem / Power Measuring CS5463
Post by: Blizzart on Jul 14, 2016, 10:20 pm
Hey alan_lima

I can't make out any mistakes at the moment.
I'm not working on that project anymore and don't have the hardware to do any testing at the moment, furthermore I'm in my exam period myself right now, that's why I don't have time to look further into it.
But here is my Version that I believe was stable and was working correct.
I hope that's any help for you.

Best wishes and good luck!
Blizzart
Title: Re: Arduino Yun / SPI Problem / Power Measuring CS5463
Post by: alan_lima on Jul 14, 2016, 10:20 pm
This is the result shown:

Code: [Select]
Config: 0
0
0
Status: 0
0
0
VOLTAGE_RMS: 0
0
0
0
CURRENT_RMS: 0
0
0
0
POWER: 0
0
0
0
TEMPERATURE: 0
0
0
0


Title: Re: Arduino Yun / SPI Problem / Power Measuring CS5463
Post by: alan_lima on Jul 14, 2016, 10:38 pm
Okay, thank you Blizzard, I will test again after put the result here in any way thank you for your help.
Title: Re: Arduino Yun / SPI Problem / Power Measuring CS5463
Post by: capblack on Feb 26, 2017, 11:15 pm
Please check this code work ok for me
Title: Re: Arduino Yun / SPI Problem / Power Measuring CS5463
Post by: sonnyyu on Mar 11, 2017, 02:21 am
The method of sensor AC:

Voltage Sensing Unit:

  • Resistor divider
  • AC Voltage stepdown transformer


Current Sensing Unit:

  • Current transformer
  • Hall effect-based current sensor
  • Rogowski coil sensor
  • Shunt resistor


Energy Processor 78M6610+PSU/C48 use "Shunt resistor" + "Resistor divider". That is reason we need isolator.

The CS5463 board use:



and by pass arduino directly connect with AR9331 SPI interfaces.

(http://i.imgur.com/Y6EFfdn.jpg)


(http://i.imgur.com/0LFlyze.jpg)

Title: Re: Arduino Yun / SPI Problem / Power Measuring CS5463
Post by: ShapeShifter on Mar 11, 2017, 02:14 pm
Looks like an interesting board, but what a silly arrangement! I think that current transformer should be rotated 90 degrees. The way its oriented, and being so close to the transformer, how are you supposed to pass one of the AC lines through it? It looks like it would only handle a small flexible wire, and even that would be difficult to thread.
Title: Re: Arduino Yun / SPI Problem / Power Measuring CS5463
Post by: sonnyyu on Mar 30, 2017, 08:15 pm
Looks like an interesting board, but what a silly arrangement! I think that current transformer should be rotated 90 degrees. The way its oriented, and being so close to the transformer, how are you supposed to pass one of the AC lines through it? It looks like it would only handle a small flexible wire, and even that would be difficult to thread.
I spoken with the board designer and he confirmed the problem, The work around is rotate 45 degree of current transformer.