DAC_MCP49xx blocks digitalpin out (Arduino Uno)

Hello,

I find that the DAC_MCP49xx from electronics/Arduino/Libraries/DAC_MCP49xx at master · exscape/electronics · GitHub makes stop all I/O on a Arduino Uno:

My test code is a simple combination of the "blink"-example with the DAC-definition:

#include <SPI.h>            
#include <DAC_MCP49xx.h>   
#define CS 10
#define LDAC 7

/* commenting the following line makes the blink routine work */
DAC_MCP49xx dac(DAC_MCP49xx::MCP4922, CS, LDAC);

void setup() {
 pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
 digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
 delay(1000);                       // wait for a second
 digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
 delay(1000);                       // wait for a second
}

The LED does not blink. If I comment or remove the setup line for the DAC the LED starts blinking. It does not matter, whether the DAC is connected to the Arduino Uno or not.

The astonishing thing:
I try to adopt an old Arduino based hardware project from some one else ( GitHub - cs80/CS15_SSK: Replacement SSK board for Yamaha CS15 synthesizer ) for a new software. The project reads a keyboard matrix of a piano keyboard and creates voltages corresponding to the played keys. In this code the library is used completely in the same way and works fine (there is some trouble with the MIDI-function, but that is another story).

So: what is wrong with my code?

Regards
Florian

Which controller was used in the old (working) project and which one do you use now?

Hi,
Have you tried one of the IDE library examples for this library?
To prove your hardware connections FIRST.

Then added your extra code lines?

What model Arduino are you using?

Thanks.. Tom.. :slight_smile:

DrDiettrich:
Which controller was used in the old (working) project and which one do you use now?

What do you mean with "controller"? The Arduino board?
The old project was developed on an Arduino Uno (see CS15_SSK/YamahaSSK_MIDI_legato/YamahaSSK_MIDI_legato.ino at master · cs80/CS15_SSK · GitHub ), but the final Hardware ran on a plain ATMega328P. ( Old Crow's Synth Shop: The Yamaha CS15 Key Assigner )
I am using an Arduino Uno which I bought two months ago.

TomGeorge:
Have you tried one of the IDE library examples for this library?
To prove your hardware connections FIRST.

Then added your extra code lines?

The DAC itself works. I tested and proved with the testroutines from the example and a scope. Then I added the code

What model Arduino are you using?

As the subject says: Arduino Uno.

Thanks for helping!

Ahh, btw: I found that writing to the serial console works:

#include <SPI.h>            
#include <DAC_MCP49xx.h>   
#define CS 10
#define LDAC 7
DAC_MCP49xx dac(DAC_MCP49xx::MCP4922, CS, LDAC);

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
  Serial.println("test ");
}

I get the "test " in the console window, but the LED does not blink.

Hi,
As you are using a UNO, you do not need;

while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}

See what happens if you remove that bit of code, I think it is only used on controllers that have more than one UART port.

Tom... :slight_smile:

See what happens if you remove that bit of code, I think it is only used
on controllers that have more than one UART port.
My problem is not the serial (the serial works!)

The problem is, that the digitalOut does not work. See the blink-example in my thread opening post
(I changed the thread subject, so hopefully this is more clear now).

Digital pins can map to different physical pins for each board, that's why I ask for the exact controller and board. But if the code without the ADC blinks the LED then the mapping should be okay. Nonetheless trying a different pin may reveal unexpected usage of the built-in LED by the library.

Jepp, you guessed it right. I wrote Thomas Backman (the author of the library) and he replied quite immediately, that SPI uses the pin 13 (LEDpin on the UNO) for the SCK-signal. I will test the other ports.

Hi,
Does the 49XX use pin 13 in your circuit?

Tom... :slight_smile:

TomGeorge:
Does the 49XX use pin 13 in your circuit?

Hello Tom,
as written, the original circuit uses a plain ATMega328P, not an Arduino Uno. So pin 13 of the Arduino corresponds to pin 19 (=SCK) of the ATMega - and of course the MCP4922 in the original circuit uses the SCK signal.

If I had translated the pin assignements Arduino<->ATMega from the beginning, then my problem would not have appeared.

Thanks anyway for everybodies help!

Florian

Sorry, I was wrong:
SCK never maps to the on-board LED~~, you are doing something very wrong~~ :frowning:

DrDiettrich:
SCK never maps to the on-board LED, you are doing something very wrong :frowning:

Hello DrDittrich,

I can't prove you wrong. I only can forward, what the author of the DAC_MCP49xx-Library wrote me:
-------- Weitergeleitete Nachricht --------
Betreff: Re: DAC_MCP49xx blocks digitalouts on arduino ?
Datum: Mon, 18 Jan 2021 14:44:13 +0100
Von: Thomas Backman XXXX@XXXXXXXX.org
An: Florian Anwander fanwander@mnet-online.de

Hey! […]

I think your issue is that the SPI SCK pin (13) is the same as LED_BUILTIN, so you can't use that LED while using SPI, as the library does to communicate with the DAC!

From the Uno specs:

  • SPI: 10 (SS), 11 (MOSI), 12 (MISO), 13 (SCK). These pins support SPI communication using the SPI library.
  • LED: 13. There is a built-in LED driven by digital pin 13. When the pin is HIGH value, the LED is on, when the pin is LOW, it's off.

Have you tested writes on other digital pins? They should work!
[…]

So what should I say? I considered what he wrote, tested the pins 2 to 9 and they work nicely...

Regards
Florian

Sorry, my bad, I was so sure that the LED can not be tied to SCK :frowning:

This means that the LED is quite useless as soon as SPI is used in code. Remains the hint to use another LED on another pin for visual feedback.

DrDiettrich:
Sorry, my bad, I was so sure that the LED can not be tied to SCK :frowning:

No problem at all.

This means that the LED is quite useless as soon as SPI is used in code.

I could imagine, that it makes sense if you want to monitor action while you are using the Arduino as ISP

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.