Hello everyone,
while coding a project (2axis remote controlled camera carrier), I ran into difficulties.
The project itself works well, however as soon as I try starting the Arduino Micro cold (i.e. bring it up from completely powerd down) it will not establish a SPI link (I guess??).
The only way I can get it to work is by pressing the reset button and waiting for the reset to finish (hot reset).
This is very strange to me, as a "hot" or "cold" reset should essentially do the same.
However it freezes (line marked in code below) at the first SPI command if it is reset cold.
I also observed, that waiting for a serial connection at boot also fixes the issue.
This is not an option for me, as the micro will be inaccessible when the project ist finished.
See this code in the main.cpp:
Button invertierung = Button();
Button stopp = Button();
SK6812 led(1);
AD770X ad7706(5);
void setup()
{
panSkalierung = (unsigned long) PANMINDESTABSTANDVOLLGESCHW * (unsigned long) 10000 / (unsigned long) (2 * MICROSTEPPING_PAN);
tiltSkalierung = (unsigned long) TILTMINDESTABSTANDVOLLGESCHW * (unsigned long) 10000 / (unsigned long) (2 * MICROSTEPPING_TILT);
pinMode(DIR_PIN_TILT, OUTPUT);
pinMode(DIR_PIN_PAN, OUTPUT);
pinMode(STEP_PIN_TILT, OUTPUT);
pinMode(STEP_PIN_PAN, OUTPUT);
pinMode(EN_PIN, OUTPUT);
led.set_output(LED_PIN);
ad7706.reset(); <- Arduino freezes here during cold reset
ad7706.init(AD770X::CHN_AIN1);
ad7706.init(AD770X::CHN_AIN2);
ad7706 is a A/D converter, which is connected via SPI
ad7706.reset():
void AD770X::reset() {
digitalWrite(pinCS, LOW); //pinCS = 13
for (int i = 0; i < 100; i++)
spiTransfer(0xff);
digitalWrite(pinCS, HIGH);
}
spiTransfer:
byte spiTransfer(volatile byte data) {
_SFR_IO8(0x2E)= data;
while (!(_SFR_IO8(0x2D) & _BV(7)));
return _SFR_IO8(0x2E);
};
The code I use for connecting to the ADC works well if the SPI link can be completed.
It belongs to this library: AD7705/AD7706 Library – Kerry D. Wong
Hase anyone ever observed something similar?
Thank you for reading through this, any input is appreciated!