Software/Arduino Core/Basics

Digital and Analog Pins

The Neuro N6 header pins, their capabilities, and the 1.8 V analog reference.

beginner4 min read

The Neuro N6 header uses Arduino Nano style D and A pin names. The standard functions pinMode, digitalWrite, digitalRead, digitalToggle, analogRead, analogWrite, tone, pulseIn, shiftIn and shiftOut are implemented. Two properties differ from 5 V Arduino boards:

  1. Digital logic is 3.3 V. No header pin tolerates 5 V.
  2. Analog full scale is 1.8 V. Inputs above approximately 1.79 V read 4095, and the datasheet requires analog inputs to remain below the analog supply.

Pin table

NameMCU pinAnalogPWMNotes
D0PD0Header RX. UART4 when the LTE library is linked
D1PD1Header TX
D5PE9yes
D6PF5
D9PD12Shares an interrupt line with A2
D10PF10SS by convention
D11PF15
D12PA3
D13PG14
A0PF13yes
A1PF11yes
A2PF12yesShares an interrupt line with D9
A3PF3yes
A4PF14yesyes
A5PG15yesConventional SD card chip select
SDAPD15Header I2C, 3.3 V, 4.7k pull-ups
SCLPD14Header I2C
MOSIPD7SPI2
MISOPD11SPI2
SCKPF2SPI2
LEDRPE11yesRGB LED red, active low
LEDGPD6yesRGB LED green, active low. Aliased as LED_BUILTIN
LEDBPC1yesRGB LED blue, active low
BTN_USERPG8External 10k pull-down. Reads HIGH while pressed

All pins in the table are digital capable. D2, D3, D4, D7 and D8 are not routed; their table entries are placeholders so that pin numbers match their names. Pins used by the camera, display, USB and external flash are not exposed.

Analog input

cpp
void setup() {
  Serial.begin(115200);
  analogReadResolution(12);       // 0 to 4095
}

void loop() {
  int raw = analogRead(A0);
  int mv  = (raw * 1800) / 4095;  // 1.8 V full scale
  Serial.print(raw); Serial.print("  "); Serial.print(mv); Serial.println(" mV");
  delay(200);
}

The reference is the VDDA_1V8 rail, measured at approximately 1.79 V from the factory calibration word. The STM32N6 datasheet specifies the ADC input range as VSSA to VREF+, and on this board VREF+ is the 1.8 V analogue supply, which is the origin of the limit. The converters are two 12-bit successive approximation ADCs rated at up to 5 Msps with a hardware oversampler; the default resolution is 10 bits for Arduino compatibility, and analogReadResolution(12) selects the native range.

Voltage division. Signals above 1.8 V must be divided. For a single cell lithium polymer battery, a 100k over 51k divider with 100 nF from the tap to ground gives a 1:3 ratio and keeps 4.3 V within range. For a 3.3 V signal, 100k over 100k gives 1.65 V at full scale.

Digital output

pinMode(pin, OUTPUT) followed by digitalWrite. digitalToggle(pin) inverts a pin in one call. The board datasheet specifies a GPIO voltage range of -0.3 to 3.6 V and a current limit of 4 mA per pin. The STM32N6 I/Os are capable of up to 20 mA depending on the speed setting; the board rating is the design limit.

OUTPUT_OPENDRAIN configures a pin that only pulls low. When released the pin is high impedance and an external pull-up sets the level. This is the correct mode for the power key of a cellular modem.

Digital input

INPUT, INPUT_PULLUP and INPUT_PULLDOWN are supported. The USER button has an external pull-down and is read with plain INPUT: HIGH while pressed, LOW when released.

PWM

analogWrite produces hardware PWM on D5, A4 and the three LED channels at 1 kHz by default. The board datasheet lists D5, D10, D12 and D13 as PWM capable pins; the core implements analogWrite on D5, A4 and the LED channels. analogWriteFrequency(hz) sets the frequency and analogWriteResolution(bits) the range. digitalPinHasPWM(pin) reports capability at run time. Because the LEDs are active low, a larger value dims them.

tone() and noTone() work on any digital pin and do not require a PWM capable pin. PWM is generated by the STM32N6's general purpose timers, which are clocked at up to 240 MHz.

Interrupts

cpp
attachInterrupt(digitalPinToInterrupt(BTN_USER), onPress, RISING);

RISING, FALLING and CHANGE are supported. digitalPinToInterrupt(pin) returns the pin number unchanged.

Each pin is connected to one of sixteen external interrupt lines, selected by its pin number within its port. Two pins with the same number in different ports cannot both have interrupts attached. On this header, A2 (PF12) and D9 (PD12) share line 12; the second attachInterrupt prints a warning and has no effect. No other header pins collide.

Handlers run in interrupt context. Shared variables are declared volatile.

Pulse and shift functions

pulseIn(pin, level, timeout) measures a pulse in microseconds. shiftIn and shiftOut clock bytes on any two pins. Both are the reference Arduino implementations.

Pin constants

LED_BUILTIN is a macro, so that #ifdef LED_BUILTIN works in existing sketches. The remaining pin names are typed constants rather than macros, because a macro named A0 collides with a structure member in the CMSIS DSP headers. Typed constants cannot be used in preprocessor #if tests; a sketch that needs a pin number in one uses the raw value, for example 18 for A4.