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).
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.
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.
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.
DrDiettrich:
SCK never maps to the on-board LED, you are doing something very wrong
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...