The average residence or business likely has a number of devices that piggyback on mains line for communication. Recently, Haris Andrianakis decided to design his very own power line communication system for a thesis project at the Technological Education Institute of Piraeus in Greece.
As HackADay’s Eric Evenchick explains, the basic principle of the system is to inject a signal onto the power lines at a significantly higher frequency than the 50 or 60 Hz of the AC power itself.
“Using both active and passive filters, the signal can be separated from the AC power and decoded. This system uses frequency-shift keying to encode data,” he says. ”This part is done by a ST7540 modem that’s designed for power line applications. The modem is controlled over SPI by an ATmega168 microcontroller.”
Comms between the ST7540 modem could have also been established using UART (asynchronous), although as we noted above, Andrianakis chose SPI to establish a synchronous connection.
“After a lot of hours of SPI debugging using logic analyzer and testing different combinations I found an unusual but working method. In order to enable the Slave’s (ATmega168) SS pin to indicate SPI’s start/stop I used another pin of the same MCU and not one of the ST7540 (while it wasn’t included),” Andrianakis wrote on the project’s official page.
“So by checking the CD_PD line (carrier frequency detect line) of the ST7540 the MCU knows when there are available data for reception in ST7540. If the MCU detect available data enables the SS pin and the SPI communication starts by receiving the available data. When the data reception ends thus the CD_PD pin has changed state to indicate that there are no more available data the MCU restores the SS pin to its initial state disabling the SPI and clearing the SPI bit counter used to synchronize the communication.”
Essentially, says Andrianakis, this method is like deceiving the SPI while the same (Slave) device enables its SS pin.