MelexisIO SCPI Commands
Loading...
Searching...
No Matches
ADC SCPI Commands

This document describes the SCPI-like command interface implemented in commands_adc.c for controlling and reading the ADC (Analog-to-Digital Converter) pins on the STM32 microcontroller.

Overview

The commands_adc.c file provides a set of commands for initializing ADC pins, configuring their sample times, and reading their analog voltage values. These commands are accessible via a terminal or remote interface that supports the defined command patterns.

Supported Commands

Command Pattern Handler Tag Description
:A0:ADC:INIT CMD_AdcInit ADC_A0_PIN Initialize ADC A0 pin
:A1:ADC:INIT CMD_AdcInit ADC_A1_PIN Initialize ADC A1 pin
:A3:ADC:INIT CMD_AdcInit ADC_A3_PIN Initialize ADC A3 pin
:A0:ADC:SampleTime CMD_AdcSampTime ADC_A0_PIN Set sample time for ADC A0 pin
:A1:ADC:SampleTime CMD_AdcSampTime ADC_A1_PIN Set sample time for ADC A1 pin
:A3:ADC:SampleTime CMD_AdcSampTime ADC_A3_PIN Set sample time for ADC A3 pin
:A0:ADC:SampleTime? CMD_AdcSampTimeQ ADC_A0_PIN Query sample time for ADC A0 pin
:A1:ADC:SampleTime? CMD_AdcSampTimeQ ADC_A1_PIN Query sample time for ADC A1 pin
:A3:ADC:SampleTime? CMD_AdcSampTimeQ ADC_A3_PIN Query sample time for ADC A3 pin
:A0:ADC? CMD_AdcRead ADC_A0_PIN Read voltage from ADC A0 pin
:A1:ADC? CMD_AdcRead ADC_A1_PIN Read voltage from ADC A1 pin
:A3:ADC? CMD_AdcRead ADC_A3_PIN Read voltage from ADC A3 pin

» Note: Commands for A2 are present in the code but commented out or marked as TODO.

Command Details

Initialization

  • :A0:ADC:INIT, :A1:ADC:INIT, :A3:ADC:INIT
  • Initializes the specified ADC pin for analog input.

Set Sample Time

  • :A0:ADC:SampleTime «cycles» (cycles: 3, 15, 28, 56, 84, 112, 144, 480)
  • Sets the ADC sample time for the specified pin.

Query Sample Time

  • :A0:ADC:SampleTime?
  • Returns the current sample time setting for the specified pin.

Read ADC Value

  • :A0:ADC?
  • Reads and prints the voltage value from the specified ADC pin.

Handler Functions

  • CMD_AdcInit: Configures the GPIO and ADC hardware for the selected pin.
  • CMD_AdcSampTime: Sets the sample time for the selected ADC pin.
  • CMD_AdcSampTimeQ: Queries the current sample time for the selected ADC pin.
  • CMD_AdcRead: Reads the voltage from the selected ADC pin and prints the result.

Examples

Initialize ADC Pin

Command sent:

:A0:ADC:INIT\n

Response:

(OK)>

Set Sample Time

Command sent:

:A0:ADC:SampleTime 56\n

Response:

(OK)>

Query Sample Time

Command sent:

:A0:ADC:SampleTime?\n

Response:

SampleTime=56
(OK)>

Read ADC Value

Command sent:

:A0:ADC?\n

Response:

A0=1.234
(OK)>

Error Example (Invalid Pin)

Command sent:

:A2:ADC:INIT\n

Response:

(Some error)>

Notes

  • The command interface is extensible. To add new ADC pins or features, update the command table and implement the corresponding handler logic.
  • Some features (e.g., A2 pin support) are marked as TODO and may require hardware-specific handling.