UM1573
User manual
ST7540 power line modem firmware stack
Introduction
This document explains how to use the firmware stack protocol designed for an
STM32F103xx microcontroller interfaced with an ST7540 FSK power line transceiver.
The firmware is organized in a layer structure and is able to drive the ST7540 transceiver,
implementing a communication protocol for the data transfer between two or more devices
connected to the same power line. The stack is also able to manage the possible conflicts,
the data acknowledgement and the repetitions in the case of data loss.
This firmware stack is developed using the STM32F103xx Standard Peripherals Library
Rel.3.5.0 and IAR Embedded Workbench IDE for STM32F103xx microcontrollers Rel. 6.3.
November 2012
Doc ID 023619 Rev 1
1/27
www.st.com
Contents
UM1573
Contents
1
2
Network model description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
ST7540 stack firmware code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.1
ST7540 driver layer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.1.1
2.1.2
2.1.3
PLM initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Receiving data from power line modem . . . . . . . . . . . . . . . . . . . . . . . . . 11
Transmitting data to power line modem . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.2
Data link and network level . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.2.1
2.2.2
2.2.3
2.2.4
Stack initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Stack data reception service (NL_NetworkIndication) . . . . . . . . . . . . . . 18
Stack data transmission service (NL_NetworkRequest) . . . . . . . . . . . . 20
Other stack interface APIs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
3
4
5
Stack firmware structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
2/27
Doc ID 023619 Rev 1
UM1573
List of figures
List of figures
Figure 1.
Figure 2.
Figure 3.
Figure 4.
Figure 5.
Figure 6.
Figure 7.
Figure 8.
CSMA/CA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Data exchange diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Firmware structure of the power line modem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Data communication flow with a case of repetition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Firmware stack block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
ST7540 driver structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Stack working mode bitmap definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Stack firmware structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Doc ID 023619 Rev 1
3/27
Network model description
UM1573
1
Network model description
The power line modem firmware stack is designed to manage a network structure
composed of several power line modems, called nodes. These modem nodes are
distributed throughout the power line. One or more modems can be used as a data
concentrator and the others as slave modems. All the nodes and the concentrator share the
same power line, which is used as a data communication channel (physical means).
The network is logically designed to be a master-slave structure, where the data
concentrator is considered a master device and each addressed node is the slave. And, in
fact, any device can initiate the communication, thereby becoming a master, while the target
node, having a unique address ID, becomes the slave device.
Each node can also act as a data repeater, without any additional programming features,
increasing both the reliability of the network and the statistical probability that the
information from the master to the slave is delivered even under difficult network conditions.
However, the coexistence of more than one master and more repeaters introduces the need
for data collision management. Since more than one device can initiate communication at
any time, this may cause a network jam, lowering overall performance. This potential
problem can be solved using one of two main techniques. One of these - carrier sense
multiple access with collision detect (CSMA/CD) - is used when a hardware device is able to
detect any collision during the data transmission. The other - carrier sense multiple access
with collision avoidance (CSMA/CA) - the one used with this transceiver, is used when the
hardware does not have this capability.
Figure 1.
CSMA/CA
AM15243v1
Node D
BACKOFF
BAND IN USE
BACKOFF
BAND FREE
TRANSMISSION
BAND IN USE
BAND IN USE
Node C
BACKOFF
BAND IN USE
BACKOFF
BACKOFF
BACKOFF
TRANSMISSION
BAND FREE
Node B
BACKOFF
BAND FREE
TRANSMISSION
BAND IN USE
BAND IN USE
BAND IN USE
BAND FREE
Node A
BACKOFF
BACKOFF
BACKOFF
BACKOFF
TRANSMISSION
t
The implemented conflict avoidance mechanism uses a backoff time and the “band in use”
(BU) hardware feature of the PLM to avoid transmission conflicts. Before initiating any
communication, each device waits until the band is free by checking its own BU flag. As
soon as the band is free, a random backoff time is calculated. Once the backoff time has
elapsed, if the band is still free, the transmission is started, otherwise the loop is started
again (waiting for the BU and new backoff calculation).
4/27
Doc ID 023619 Rev 1
UM1573
Network model description
The data exchange between all the nodes connected to the same power line also uses a
data frame acknowledgement mechanism. In this way, the master knows if its own
transmitted data packet has been correctly delivered to the target node since it receives an
acknowledgment frame for each data frame sent to a target device. This acknowledgement
excludes some data frames sent in broadcast by the master.
Figure 2.
Data exchange diagram
t0
DAT TO
TA
SLAV
E x
t2
SEND
ACK
FRAME
MASTER
Receive
User Data
t
t1
SEND
DATA
FRAME
SLAVE
x
S
x
M
DATA
ACK
Data
Pr
rocessing
bACK
t3
t
SEND bACK
FRAME
t0
t1
t2
2
t3
AM15244v1
The repetition feature improves the probability that the data frame is delivered to nodes that
are far away or under noisy network environments. As all the other nodes are connected in
the same power line, they continuously sense the network catching all data transiting on it.
Depending on the device addressing and the data frame/acknowledge flow, each node is
able to detect if the sensed frame must be repeated, discharged, or processed. A data
identification technique (frame ID) and the forward error correction redundancy (FEC) in the
data frames are implemented in order to avoid cyclic repetitions or data loss that can cause
an unnecessary increase of data traffic.
Doc ID 023619 Rev 1
5/27