Skip to content

A0 and A1 not working in M4? #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mrubioroy opened this issue Apr 24, 2024 · 10 comments
Closed

A0 and A1 not working in M4? #72

mrubioroy opened this issue Apr 24, 2024 · 10 comments
Assignees
Labels
conclusion: resolved Issue was resolved type: imperfection Perceived defect in any part of project

Comments

@mrubioroy
Copy link

When I run Arduino_AdvancedAnalog/examples/Advanced/ADC_Multi_Channel/ADC_Multi_Channel.ino in the M4 co-processor of my Portenta H7, it only works for channels A4 to A7. According to the documentation ADC1 should also work with A0 and A1. Why are A0 and A1 not working? They do work in the main M7 core.

I have used these codes:
M7:

void setup() {
  bootM4();
  Serial.begin(9600);
}
void loop() {
  Serial.println("M7");
  digitalWrite(LEDG, LOW);
  delay(100);
  digitalWrite(LEDG, HIGH);
  delay(2000);
}

M4:

#include <Arduino_AdvancedAnalog.h>

AdvancedADC adc(A0); // not working with A0 or A1. It does work with A4 to A7
uint64_t last_millis = 0;

void setup() {
  Serial1.begin(9600);

  // Resolution, sample rate, number of samples per channel, queue depth.
  if (!adc.begin(AN_RESOLUTION_16, 16000, 32, 128)) {
      Serial1.println("Failed to start analog acquisition!");
      while (1);
  }
}

void loop() {
  if (adc.available()) {
      SampleBuffer buf = adc.read();
      // Process the buffer.
      if ((millis() - last_millis) > 20) {
        Serial1.println(buf[0]);   // Sample from first channel
        Serial1.println(buf[1]);   // Sample from second channel
        last_millis = millis();
      }
      // Release the buffer to return it to the pool.
      buf.release();
  }
}
@iabdalkader
Copy link
Collaborator

iabdalkader commented Apr 24, 2024

This might be related to this issue: arduino/ArduinoCore-mbed#867

But how do you know if it works or not ? The M4 can't use serial to print message. The difference between A0..A3 and A4-A7, is that A0-A3 are dual-pad pins. The M4 may have an issue configuring or accessing them.

@per1234 per1234 added type: imperfection Perceived defect in any part of project status: waiting for information More information must be provided before work can proceed labels Apr 24, 2024
@mrubioroy mrubioroy changed the title A0 and A11 not working in M4? A0 and A1 not working in M4? Apr 25, 2024
@mrubioroy
Copy link
Author

Please note I use Serial1 for M4, which does work with output on UART1 pins.

When I use A0 or A1, I get the message “Failed to start analog acquisition!” on UART1. For A4 to A7, it prints the read values as expected. A2 and A3 don't work either, but that's the expected behavior for ADC1 according to the documentation.

@iabdalkader
Copy link
Collaborator

Ah I see. Well, as I've mentioned those pins happen to be dual-pads pins. That's the only difference, and I'm guessing but there might be an issue we've missed with using them from the M4. I'll give this a try next week.

@leonardocavagnis leonardocavagnis added status: in progress Work is in progress on this and removed status: waiting for information More information must be provided before work can proceed labels Apr 29, 2024
@iabdalkader
Copy link
Collaborator

I tested this issue and I just can't reproduce it. I tried A0->A4, all seem to work fine, see the screenshot. Note the serial monitor is connect to a USB to serial port.

image

Sketch:

#include "RPC.h"
#ifdef CORE_CM7
void setup() {
  bootM4();
  Serial.begin(9600);
}
void loop() {
}
#else
#include <Arduino_AdvancedAnalog.h>

AdvancedADC adc(A0); // not working with A0 or A1. It does work with A4 to A7
uint64_t last_millis = 0;

void setup() {
  Serial1.begin(9600);

  // Resolution, sample rate, number of samples per channel, queue depth.
  if (!adc.begin(AN_RESOLUTION_16, 16000, 32, 128)) {
      Serial1.println("Failed to start analog acquisition!");
      while (1);
  }
}

void loop() {
  if (adc.available()) {
      SampleBuffer buf = adc.read();
      // Process the buffer.
      if ((millis() - last_millis) > 20) {
        Serial1.println(buf[0]);   // Sample from first channel
        Serial1.println(buf[1]);   // Sample from second channel
        last_millis = millis();
      }
      // Release the buffer to return it to the pool.
      buf.release();
  }
}
#endif

@iabdalkader
Copy link
Collaborator

Were you using the latest library or an older release ? You should be using 1.4.0.

@mrubioroy
Copy link
Author

I'm using Advanced Analog 1.4.0 and board 4.1.1

I've uploaded your sketch to both cores and I still get the "Failed to start analog acquisition!" message on pin 14. I've even tried changing the #define DUAL_PIN according to commit 992ed2c but I still get the error message.

I'm using a Portenta H7 with no peripherals. Just USB-C for programming and Serial to USB on pin 14 (picture attached).

@facchinm
Copy link
Collaborator

facchinm commented May 3, 2024

@mrubioroy changing only the source files has no effect since the same setting should be applied to the precompiled library. Can you give a spin to core 4.1.3 (just released) that contains the full patch? Thx

@iabdalkader
Copy link
Collaborator

iabdalkader commented May 3, 2024

I tested this the first time with a Giga, which had a newer core. I tested it again with a Portenta, and the Portenta does fail with an older core (4.0.8) but works with the latest (4.1.3).

@mrubioroy
Copy link
Author

Works now, thank you

If I may, what is a "dual pad" pin?

@iabdalkader
Copy link
Collaborator

iabdalkader commented May 6, 2024

If I may, what is a "dual pad" pin?

Special pins that connect to two pads, or used separately as a GPIO pad and an ADC input.

@per1234 per1234 added conclusion: resolved Issue was resolved and removed status: in progress Work is in progress on this labels May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
conclusion: resolved Issue was resolved type: imperfection Perceived defect in any part of project
Projects
None yet
Development

No branches or pull requests

5 participants