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?
Solution:
Do you have the correct ADC device name, we make mistakes like this attimes . In the Zephyr OS, the ADC device names may vary depending on the hardware you're using. Instead of "ADC_0", check your board’s device tree for the correct device name. Print out the available devices with: ``` const struct device *adc_dev = device_get_binding(DT_LABEL(DT_NODELABEL(adc0))); if (!adc_dev) { printk("Failed to bind to ADC_0 device\n");...
Jump to solution
2 Replies
Solution
Marvee Amasi
Marvee Amasi4mo ago
Do you have the correct ADC device name, we make mistakes like this attimes . In the Zephyr OS, the ADC device names may vary depending on the hardware you're using. Instead of "ADC_0", check your board’s device tree for the correct device name. Print out the available devices with:
const struct device *adc_dev = device_get_binding(DT_LABEL(DT_NODELABEL(adc0)));
if (!adc_dev) {
printk("Failed to bind to ADC_0 device\n");
}
const struct device *adc_dev = device_get_binding(DT_LABEL(DT_NODELABEL(adc0)));
if (!adc_dev) {
printk("Failed to bind to ADC_0 device\n");
}
Just make sure you reference the correct node label for your device
Dtynin
Dtynin4mo ago
oh yeah, thanks manh @Marvee Amasi I ensured the ADC device name was correct and I had to adjust the resolution also for it.
Want results from more Discord servers?
Add your server