Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
hx711.c File Reference

Interface for the HX711 sensor. More...

#include "hx711.h"
#include "mcu_periph/gpio.h"
#include "mcu_periph/sys_time.h"
#include "modules/core/abi.h"
#include "modules/datalink/downlink.h"
#include "modules/datalink/telemetry.h"
#include <BOARD_CONFIG>
Include dependency graph for hx711.c:

Go to the source code of this file.

Data Structures

struct  hx711_dev_t
struct  hx711_t

Macros

#define HX711_DEVICES_NB   4
#define HX711_GAIN   1
#define HX711_PWM_FREQUENCY   6000000
#define HX711_DEVICES   {}
#define HX711_FORCE_SENSOR_ID   ABI_BROADCAST
#define HX711_DEBUG   false
#define HX711_PERIOD   (HX711_PWM_FREQUENCY / 50000)

Functions

static void pwmpcb (PWMDriver *pwmp)
 Callback on the falling edge of the clock signal.
void hx711_init (void)
void hx711_event (void)
 Start a measurement and publish the results when possible.

Variables

float hx711_meas_time = 0
static volatile struct hx711_t hx711
static PWMConfig pwmcfg

Detailed Description

Interface for the HX711 sensor.

Definition in file hx711.c.


Data Structure Documentation

◆ hx711_dev_t

struct hx711_dev_t

Definition at line 68 of file hx711.c.

Data Fields
uint16_t data_pin
ioportid_t data_port
int32_t measurement

◆ hx711_t

struct hx711_t

Definition at line 74 of file hx711.c.

Collaboration diagram for hx711_t:
Data Fields
volatile bool busy
struct hx711_dev_t devices[HX711_DEVICES_NB]
volatile bool measurement_ready
volatile uint8_t read_bit_idx

Macro Definition Documentation

◆ HX711_DEBUG

#define HX711_DEBUG   false

Definition at line 57 of file hx711.c.

◆ HX711_DEVICES

#define HX711_DEVICES   {}

Definition at line 49 of file hx711.c.

◆ HX711_DEVICES_NB

#define HX711_DEVICES_NB   4

Definition at line 37 of file hx711.c.

Referenced by hx711_event(), hx711_init(), and pwmpcb().

◆ HX711_FORCE_SENSOR_ID

#define HX711_FORCE_SENSOR_ID   ABI_BROADCAST

Definition at line 53 of file hx711.c.

Referenced by hx711_event().

◆ HX711_GAIN

#define HX711_GAIN   1

Definition at line 41 of file hx711.c.

Referenced by pwmpcb().

◆ HX711_PERIOD

#define HX711_PERIOD   (HX711_PWM_FREQUENCY / 50000)

Definition at line 65 of file hx711.c.

Referenced by hx711_event().

◆ HX711_PWM_FREQUENCY

#define HX711_PWM_FREQUENCY   6000000

Definition at line 45 of file hx711.c.

Function Documentation

◆ hx711_event()

void hx711_event ( void )

Start a measurement and publish the results when possible.

Definition at line 135 of file hx711.c.

References DefaultChannel, DefaultDevice, get_sys_time_float(), get_sys_time_usec(), gpio_get(), hx711, HX711_DEVICES_NB, HX711_FORCE_SENSOR_ID, hx711_meas_time, HX711_PERIOD, and pprzlog_tp.

Here is the call graph for this function:

◆ hx711_init()

void hx711_init ( void )

Definition at line 110 of file hx711.c.

References gpio_setup_input(), gpio_setup_pin_af(), hx711, HX711_DEVICES_NB, pwmcfg, and pwmpcb().

Here is the call graph for this function:

◆ pwmpcb()

void pwmpcb ( PWMDriver * pwmp)
static

Callback on the falling edge of the clock signal.

Definition at line 197 of file hx711.c.

References dev, gpio_get(), hx711, HX711_DEVICES_NB, and HX711_GAIN.

Here is the call graph for this function:

Variable Documentation

◆ hx711

volatile struct hx711_t hx711
static
Initial value:
= {
.busy = false,
.measurement_ready = false,
.devices = {
},
.read_bit_idx = 0
}
#define HX711_DEVICES
Definition hx711.c:49

Definition at line 85 of file hx711.c.

Referenced by hx711_event(), hx711_init(), and pwmpcb().

◆ hx711_meas_time

float hx711_meas_time = 0

Definition at line 67 of file hx711.c.

Referenced by hx711_event().

◆ pwmcfg

PWMConfig pwmcfg
static
Initial value:
= {
.frequency = HX711_PWM_FREQUENCY,
.period = HX711_PERIOD,
.callback = NULL,
.channels = {
{ PWM_OUTPUT_DISABLED, NULL },
{ PWM_OUTPUT_DISABLED, NULL },
{ PWM_OUTPUT_DISABLED, NULL },
{ PWM_OUTPUT_DISABLED, NULL },
},
.cr2 = 0,
.bdtr = 0,
.dier = 0
}
#define HX711_PERIOD
Definition hx711.c:65
#define HX711_PWM_FREQUENCY
Definition hx711.c:45

Definition at line 94 of file hx711.c.

Referenced by hx711_init().