ST AN2159 APPLICATION NOTE

AN2159
Application note
SPI protocol for STPM01/STPM10 metering devices
Introduction
The STPM01 and STPM10 devices are energy meter ASSPs (Application Specific Standard Products) designed to address a wide range of electricity metering requirements thanks to their built-in functionalities as signal conditioning, signal processing, data conversion, input/output signals and voltage reference.
STPM10 is dedicated for peripheral use only in microcontroller based applications, while STPM01 is able to work as a peripheral but also as a standalone device, since it can permanently store configuration and calibration data.
Both the devices have an SPI port to write configuration parameters and read all the information on the line energy from their internal registers.
Measured data (like active, reactive and apparent energy, V voltage and current, line frequency, device status etc.) should be read by the microcontroller at a fixed time interval to be further processed.
This application note describes the SPI protocol to read measured data from STPM01 and STPM10 in a single-phase energy meter and how these readings should be processed by the application.

Figure 1. STPMxx based application block diagram

RMS
, I
, instantaneous
RMS
July 2010 Doc ID 11400 Rev 3 1/23
www.st.com
Contents AN2159
Contents
1 Devices overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.1 STPM01 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2 STPM10 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2 SPI module description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.1 Connection to microcontroller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
3 SPI interface timings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
4 SPI operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
4.1 Remote reset request . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
4.2 Data registers writing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
4.3 Data registers permanent writing (STPM01 only) . . . . . . . . . . . . . . . . . . 10
4.4 Reading data registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
5 Data processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
5.1 Reading process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
5.1.1 Data register assembling example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
5.2 Parity check . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
5.2.1 Parity check example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
5.3 Unpacking data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
6 Converting readings into measured values . . . . . . . . . . . . . . . . . . . . . 16
6.1 Energies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
6.2 Other values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
7 Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
2/23 Doc ID 11400 Rev 3
AN2159 Devices overview

1 Devices overview

1.1 STPM01

The STPM01 is an ASSP designed for effective measurement of active, reactive and apparent energy in a power line system using Rogowski coil, current transformer and shunt sensors. This device can be implemented as a single chip in single phase energy meters or as a peripheral in microcontroller based meter.
The STPM01 consists, essentially, of two parts: the analog part and the digital part. The former, is composed by preamplifier and 1 voltage reference, low drop voltage regulator, the latter by system control, oscillator, hard wired DSP and SPI interface.
There is also an OTP block, which is controlled through the SPI by means of a dedicated command set. The configured bits are used for testing, configuration and calibration purpose.
The DSP unit computes active, reactive and apparent energy, RMS and instantaneous values of voltage and current. The results of computation are available as pulse frequency and states on the digital outputs of the device or into the internal data registers, which can be read from the device by means of SPI.
For more details on the device please refer to datasheet.

1.2 STPM10

The STPM10 is designed for effective measurement of active, reactive and apparent energy in a power line system using Current Transformer or Shunt sensors. This device is intended to be a peripheral measurement device in a microcontroller based meter.
The STPM10 consists of an analog part and a digital part. The former, is composed by preamplifier and 1 voltage regulator, the latter by system control, oscillator, hard wired DSP and SPI interface.
st
order Δ A/D converter blocks, band gap
st
order Δ A/D converter blocks, Band gap voltage reference, Low drop
Configuration and calibration bits should be set by a microcontroller.
The DSP unit computes active, reactive and apparent energy, RMS and instantaneous values of voltage and current. The results of computation are available in the internal data registers, which can be read from the device by means of SPI.
For more details on the device please refer to datasheet.
Doc ID 11400 Rev 3 3/23
SPI module description AN2159

2 SPI module description

The STPM01-10 SPI interface supports a simple serial protocol, which is implemented in order to enable a communication between a host system (microcontroller or PC) and the device.
With this interface it is possible to perform the following tasks:
remote reset of the device,
temporary programming of internal configuration/calibration data and system signals,
STPM01 only: permanent programming in OTP memory of internal
configuration/calibration data,
reading of internal data registers (shown in Figure 5).
Four pins of the device are dedicated to this purpose: SCS, SYN, SCL, and SDA.
SCS, SYN and SCL are all input pins while SDA can be input or output according if the SPI is in write or read mode.
The internal register are not directly accessible, rather a 32 bit of transmission latches are used to pre-load the data before being read or written to the internal registers.
The condition in which SCS, SYN and SCL inputs are set to high level determines the idle state of the SPI interface and no data transfer occurs. Any SPI operation should start from this idle state.
SCS: enables SPI operation when low.
SYN: when SCS is low the SYN pin status select if the SPI is in read (SYN=1) or write
mode (SYN=0). When SCS is high and SYN is also high the results of the input or output data are transferred to the transmission latches.
SCL: is the clock pin of the SPI interface. This pin function is also controlled by the SCS
status. If SCS is low, SCL is the input of serial bit synchronization clock signal. When SCS is high, SCL is also high determining the idle state of the SPI.
SDA: is the data pin. If SCS is low, the operation of SDA is dependent on the status of
SYN pin. If SYN is high SDA is the output of serial bit data (read mode) if SYN is low SDA is the input of serial bit data signal (write mode). If SCS is high SDA is idle. When SCS is active (low), signal SDA should change its state at trailing edge of signal SCL and the signal SDA should be stable at next leading edge of signal SCL. The first valid bit of SDA is always started with activation of signal SCL.
A high level signal for these pins means a voltage level higher than 0.75 x V level signal means a voltage value lower than 0.25 x V

2.1 Connection to microcontroller

The SPI master should be implemented by a host system, a PC or a microcontroller.
Microcontrollers SPI bus is usually a four wire bus with full duplex functionality, which signals are usually named as:
SCLK: Serial Clock (output from master)
MOSI: Master Output, Slave Input (output from master)
MISO: Master Input, Slave Output (output from slave)
SS: Slave Select (active low; output from master)
4/23 Doc ID 11400 Rev 3
CC
, while a low
CC
.
AN2159 SPI module description
The best way to connect this standard SPI port to the STPMxx SPI is to have SCS and SYN driven from some general purpose i/o port and SCL and SDA driven from SPI pins.
The suggested connection between microcontroller and STPMxx is the following:
MISO connected to SDA;
MOSI not connected;
SCLK connected to SCL;
SS connected to SCS;
a general purpose I/O pin connected to SYN.
In this way the SPI peripheral unit of microprocessor should operate as 2-wire (simplex synchronous transfers) SPI.
The micro SPI peripheral can be used during STPMxx device reading, while during the writing process it is possible to implement the SPI protocol via firmware.
In fact, in real applications with STPM01 the meter is calibrated and configured during meter production, so the main microcontroller task is to read from the device and, more rarely, to reset the device.
In STPM10 based meters the metering device has to be configured at startup from the microcontroller, but also in this case the writing process is done once a while, while reading is a continuous process during meter lifetime.
In both cases, since the reading time is crucial for a correct evaluation of the device data, it is advisable to emulate writing procedure by firmware and to read using SPI peripheral functionality, thus exploiting all the port performances to reach very fast reading.
Doc ID 11400 Rev 3 5/23
SPI interface timings AN2159

3 SPI interface timings

Table 1. SPI interface timings

Symbol Parameter Min. Typ. Max. Unit
F
SCLKr
F
SCLKw
t
t
t
t
OFF
t
SYN
DS
DH
ON
In Table above f
Data read speed 32 MHz
Data write speed 100 kHz
Data setup time 20 ns
Data hold time 0 ns
Data driver on time 20 ns
Data driver off time 20 ns
SYN active width 2/f
is the oscillator clock frequency (see device datasheet for details).
CLK
CLK
s
6/23 Doc ID 11400 Rev 3
AN2159 SPI operations

4 SPI operations

4.1 Remote reset request

STPM01 and STPM10 have no reset pin. They are automatically reset by the power on reset (POR) circuit when the V the SPI interface giving a dedicated command, which timing diagram is shown in Figure 2.
The reset through SPI (remote reset request - RRR) is sent from the on-board microprocessor when some malfunction of metering device has been detected.
Unlike the POR, the RRR signal does not cause the 30 ms retarded restart of analog module and the 120 ms retarded restart of digital module. This reset doesn't clear the mode signals.

Figure 2. Remote reset request timing

SCS
crosses the 2.5 V value but they can be reset also through
CC
SYN
SCL
SDA
t2t
1
t4t
3
t6t
5
Note: All the time intervals must be longer than 30 ns. t
be longer than 30 ns as well.

4.2 Data registers writing

Each writable bit (configuration and mode signals bits) of STPM01 and STPM10 has its own 6-bit absolute address (see related datasheets for configuration bits map).
t
7
t8 is the reset time, this interval must
7
t
t
t
10
8
9
In order to change the state of some pin one must send to STPM01 a byte of data via SPI. This byte consists of 1-bit data to be written (MSB), followed by 6-bit address of destination bit, followed by 1-bit don't care data (LSB), which makes a command byte.
For example, to set the STPM01 configuration bit 47 (part of the secondary current channel calibrator) to 0, the decimal 47 should be first converted to its 6-bit binary value: 101111.
Doc ID 11400 Rev 3 7/23
Loading...
+ 16 hidden pages