42#define CHIP_NAME "AtomBit BA234"
43#define MANUFACTURER_NAME "AtomBit"
44#define SUPPLY_VOLTAGE_MIN 3.0f
45#define SUPPLY_VOLTAGE_MAX 3.6f
46#define MAX_CURRENT 1.0f
47#define TEMPERATURE_MIN -40.0f
48#define TEMPERATURE_MAX 85.0f
49#define DRIVER_VERSION 1000
54#define BA234_COMMAND_READ 0xA0
55#define BA234_COMMAND_BASELINE 0xA1
56#define BA234_COMMAND_CALIBRATION 0xA7
68static uint8_t a_ba234_make_frame(uint8_t command, uint32_t data, uint8_t output[6])
74 output[1] = (data >> 24) & 0xFF;
75 output[2] = (data >> 16) & 0xFF;
76 output[3] = (data >> 8) & 0xFF;
77 output[4] = (data >> 0) & 0xFF;
80 for (i = 0; i < 5; i++)
84 output[5] = sum & 0xFF;
99static uint8_t a_ba234_parse_frame(
ba234_handle_t *handle, uint8_t input[6], uint32_t *data)
105 for (i = 0; i < 5; i++)
109 if ((sum & 0xFF) != input[5])
115 if (input[0] != 0xAC)
117 handle->
debug_print(
"ba234: frame header invalid.\n");
121 *data = ((uint32_t)input[1] << 24) | ((uint32_t)input[2] << 16) |
122 ((uint32_t)input[3] << 8) | ((uint32_t)input[4] << 0);
143 for (i = 0; i < 15; i++)
147 if ((sum & 0xFF) != input[15])
153 if (input[0] != 0xAA)
155 handle->
debug_print(
"ba234: frame header invalid.\n");
159 data->
tds_raw = (((uint16_t)(input[1])) << 8) | (uint16_t)(input[2]);
161 (((uint32_t)(input[4])) << 16) |
162 (((uint32_t)(input[5])) << 8) |
163 (((uint32_t)(input[6])) << 0);
164 data->
salinity_raw = (((uint16_t)(input[7])) << 8) | (uint16_t)(input[8]);
166 data->
temperature_raw = (((uint16_t)(input[11])) << 8) | (uint16_t)(input[12]);
200 handle->
debug_print(
"ba234: uart_init is null.\n");
206 handle->
debug_print(
"ba234: uart_deinit is null.\n");
212 handle->
debug_print(
"ba234: uart_read is null.\n");
218 handle->
debug_print(
"ba234: uart_flush is null.\n");
224 handle->
debug_print(
"ba234: uart_write is null.\n");
270 handle->
debug_print(
"ba234: uart deinit failed.\n");
311 handle->
debug_print(
"ba234: uart flush failed.\n");
318 handle->
debug_print(
"ba234: uart write failed.\n");
330 res = a_ba234_parse_data(handle, input, data);
374 handle->
debug_print(
"ba234: uart flush failed.\n");
381 handle->
debug_print(
"ba234: uart write failed.\n");
393 res = a_ba234_parse_frame(handle, input, &data);
442 (uint32_t)(value) << 16, output);
446 handle->
debug_print(
"ba234: uart flush failed.\n");
453 handle->
debug_print(
"ba234: uart write failed.\n");
465 res = a_ba234_parse_frame(handle, input, &data);
530 *reg = (uint16_t)(percentage * 100.0f);
557 *percentage = (float)(reg) / 100.0f;
590 handle->
debug_print(
"ba234: uart flush failed.\n");
597 handle->
debug_print(
"ba234: uart write failed.\n");
630 l = handle->
uart_read((uint8_t *)buf, len);
#define BA234_COMMAND_BASELINE
#define SUPPLY_VOLTAGE_MAX
#define BA234_COMMAND_READ
chip command definition
#define BA234_COMMAND_CALIBRATION
#define MANUFACTURER_NAME
#define SUPPLY_VOLTAGE_MIN
#define CHIP_NAME
chip information definition
struct ba234_info_s ba234_info_t
ba234 information structure definition
uint8_t ba234_info(ba234_info_t *info)
get chip's information
uint8_t ba234_get_last_status(ba234_handle_t *handle, ba234_status_t *status)
get last status
#define BA234_READ_TIMEOUT
ba234 read timeout definition
uint8_t ba234_init(ba234_handle_t *handle)
initialize the chip
uint8_t ba234_deinit(ba234_handle_t *handle)
close the chip
struct ba234_handle_s ba234_handle_t
ba234 handle structure definition
uint8_t ba234_salinity_calibration(ba234_handle_t *handle, uint16_t value)
salinity calibration
uint8_t ba234_baseline_calibration(ba234_handle_t *handle)
baseline calibration
uint8_t ba234_read(ba234_handle_t *handle, ba234_data_t *data)
read the data
struct ba234_data_s ba234_data_t
ba234 data structure definition
uint8_t ba234_salinity_convert_to_data(ba234_handle_t *handle, uint16_t reg, float *percentage)
convert the register raw data to the salinity
uint8_t ba234_salinity_convert_to_register(ba234_handle_t *handle, float percentage, uint16_t *reg)
convert the salinity to the register raw data
ba234_status_t
ba234 status enumeration definition
uint8_t ba234_get_buffer(ba234_handle_t *handle, uint8_t *buf, uint16_t len)
get buffer
uint8_t ba234_set_buffer(ba234_handle_t *handle, uint8_t *buf, uint16_t len)
set buffer
float temperature_degrees_celsius
float electrical_conductivity_us_cm
float salinity_percentage
uint16_t specific_gravity_raw
uint16_t water_hardness_raw
uint32_t electrical_conductivity_raw
uint8_t(* uart_flush)(void)
uint8_t(* uart_write)(uint8_t *buf, uint16_t len)
void(* delay_ms)(uint32_t ms)
uint8_t(* uart_deinit)(void)
void(* debug_print)(const char *const fmt,...)
uint16_t(* uart_read)(uint8_t *buf, uint16_t len)
uint8_t(* uart_init)(void)
float supply_voltage_max_v
char manufacturer_name[32]
float supply_voltage_min_v