Add my_adc/
This commit is contained in:
1 parent
1deb818d3e
commit
a6c62e56d8
1 file changed
+12
-13
+12
-13
@@ -6,9 +6,8 @@
|
|||||||
#include <zephyr/drivers/adc.h>
|
#include <zephyr/drivers/adc.h>
|
||||||
#include <zephyr/sys/printk.h>
|
#include <zephyr/sys/printk.h>
|
||||||
|
|
||||||
#define MY_ADC_NODE DT_ALIAS(myadc)
|
#define MY_ADC_NODE DT_ALIAS(myadc)
|
||||||
#define MY_ADC_CH_NODE DT_CHILD(MY_ADC_NODE, channel_3)
|
#define MY_ADC_CH_NODE DT_CHILD(MY_ADC_NODE, channel_3)
|
||||||
#define MY_ADC_CHANNEL_ID DT_REG_ADDR(MY_ADC_CH_NODE)
|
|
||||||
|
|
||||||
static const struct device *const adc_dev =
|
static const struct device *const adc_dev =
|
||||||
DEVICE_DT_GET(MY_ADC_NODE);
|
DEVICE_DT_GET(MY_ADC_NODE);
|
||||||
@@ -16,18 +15,18 @@ static const struct device *const adc_dev =
|
|||||||
static const struct adc_channel_cfg ch_cfg =
|
static const struct adc_channel_cfg ch_cfg =
|
||||||
ADC_CHANNEL_CFG_DT(MY_ADC_CH_NODE);
|
ADC_CHANNEL_CFG_DT(MY_ADC_CH_NODE);
|
||||||
|
|
||||||
static uint16_t sample;
|
|
||||||
|
|
||||||
static struct adc_sequence seq = {
|
|
||||||
.channels = BIT(MY_ADC_CHANNEL_ID),
|
|
||||||
.buffer = &sample,
|
|
||||||
.buffer_size = sizeof(sample),
|
|
||||||
.resolution = DT_PROP_OR(MY_ADC_CH_NODE, zephyr_resolution, 12),
|
|
||||||
};
|
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
|
|
||||||
int err;
|
int err;
|
||||||
|
uint16_t sample;
|
||||||
|
|
||||||
|
struct adc_sequence seq = {
|
||||||
|
.channels = BIT(ch_cfg.channel_id),
|
||||||
|
.buffer = &sample,
|
||||||
|
.buffer_size = sizeof(sample),
|
||||||
|
// .resolution = DT_PROP(MY_ADC_CH_NODE, zephyr_resolution),
|
||||||
|
.resolution = DT_PROP_OR(MY_ADC_CH_NODE, zephyr_resolution, 12),
|
||||||
|
};
|
||||||
|
|
||||||
if (!device_is_ready(adc_dev)) {
|
if (!device_is_ready(adc_dev)) {
|
||||||
printk("ADC device not ready\n");
|
printk("ADC device not ready\n");
|
||||||
@@ -40,7 +39,7 @@ int main(void) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
printk("Reading ADC1 channel 3 on PA3 (Arduino A0)\n");
|
printk("Reading ADC1 channel 3 on PA3\n");
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
int32_t val_mv;
|
int32_t val_mv;
|
||||||
|
|||||||
Reference in new issue
Block a user