sensor_pzem.c File Reference

library to query measurements from peacefair PZEM-004 and PZEM-004T electricity meter (code) More...

Go to the source code of this file.

## Macros

#define | SENSOR_PZEM_USART 2
| USART peripheral.
#define | SENSOR_PZEM_TIMER 2
| timer peripheral

## Functions

void | sensor_pzem_setup (void)
| setup peripherals to communicate with electricity meter
void | sensor_pzem_measurement_request (uint32_t address, enum sensor_pzem_measurement_type_t type)
| request measurement from electricity meter More...
struct sensor_pzem_measurement_t | sensor_pzem_measurement_decode (void)
| decode received measurement More...
void USART_ISR() | SENSOR_PZEM_USART (void)
| USART interrupt service routine called when data has been transmitted or received.
void TIM_ISR() | SENSOR_PZEM_TIMER (void)
| interrupt service routine called on timeout

## Variables

static uint8_t | rx_buffer [7] = {0}
| buffer for received response
static volatile uint8_t | rx_i = 0
| current position of read received data
static uint8_t | tx_buffer [7] = {0}
| buffer for request to transmit
static volatile uint8_t | tx_i = 0
| current position of transmitted data
volatile bool | sensor_pzem_measurement_received = false
| a measurement response has been received

## Detailed Description

library to query measurements from peacefair PZEM-004 and PZEM-004T electricity meter (code)

Author
  King Kévin kingk.nosp@m.evin.nosp@m.@cuvo.nosp@m.odoo.nosp@m..info

Date
  2016

Note
  peripherals used: USART USART peripheral used for communication with electricity meter, timer timer peripheral used for waiting before sending the next request

Definition in file sensor_pzem.c.

## Function Documentation

## sensor_pzem_measurement_decode()

struct sensor_pzem_measurement_t sensor_pzem_measurement_decode | ( | void |  | ) |

decode received measurement

Returns
  decoded measurement (invalid if no new measurement has been received)

Definition at line 128 of file sensor_pzem.c.

## sensor_pzem_measurement_request()

void sensor_pzem_measurement_request | ( | uint32_t | address,
|  | enum sensor_pzem_measurement_type_t | type
| ) |  |

request measurement from electricity meter

Parameters

  [in] | address | electricity meter device address
  [in] | type | measurement type to request

Definition at line 97 of file sensor_pzem.c.