Dtynin
Dtynin
DIIDevHeads IoT Integration Server
Created by Dtynin on 9/13/2024 in #middleware-and-os
Troubleshooting ADC Configuration for Sensor Data Acquisition on AVR128DA48 with Zephyr OS
hey guys on my Smart Industrial Monitoring System project, I've connected a vibration sensor (MPU6050) and temperature sensor (DS18B20) to the AVR128DA48. I'm using Zephyr OS, and I've configured the ADC for reading the sensor data. Below is the code I'm using to initialize the ADC for reading sensor data:
#include <zephyr.h>
#include <drivers/adc.h>

static const struct device *adc_dev;
static int16_t sample_buffer[1];

void adc_init() {
adc_dev = device_get_binding("ADC_0");
struct adc_channel_cfg channel_cfg = {
.gain = ADC_GAIN_1,
.reference = ADC_REF_INTERNAL,
.acquisition_time = ADC_ACQ_TIME_DEFAULT,
.channel_id = 1,
};
adc_channel_setup(adc_dev, &channel_cfg);
}

void read_adc() {
struct adc_sequence sequence = {
.channels = BIT(1),
.buffer = sample_buffer,
.buffer_size = sizeof(sample_buffer),
.resolution = 10,
};
adc_read(adc_dev, &sequence);
}
#include <zephyr.h>
#include <drivers/adc.h>

static const struct device *adc_dev;
static int16_t sample_buffer[1];

void adc_init() {
adc_dev = device_get_binding("ADC_0");
struct adc_channel_cfg channel_cfg = {
.gain = ADC_GAIN_1,
.reference = ADC_REF_INTERNAL,
.acquisition_time = ADC_ACQ_TIME_DEFAULT,
.channel_id = 1,
};
adc_channel_setup(adc_dev, &channel_cfg);
}

void read_adc() {
struct adc_sequence sequence = {
.channels = BIT(1),
.buffer = sample_buffer,
.buffer_size = sizeof(sample_buffer),
.resolution = 10,
};
adc_read(adc_dev, &sequence);
}
However, I'm getting no readings from the sensors. What could be wrong with my ADC configuration, and how can I ensure correct sensor data acquisition?
4 replies