Arduino Micro Reset

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!

The Arduino Micro has many advantages over the Arduino Uno, but also a few disadvantages. You have run into those disadvantages.

As a result of the design, there is a hot reset and a cold reset. That's how it is.

Waiting for the Serial port should only be done for testing !
To be able to do both, it is possible to wait for a few seconds, and test during that time if the Serial port becomes active. If it did not become active, then continue without Serial port.

Can you try a delay(5000) at the beginning of setup() ?

Please always show a full sketch. There is a website for that: https://snippets-r-us.com/.

Do you make the ChipSelect a OUTPUT.
When setting a pin as OUTPUT, the default output state is LOW. If you do that with the ChipSelect, then it is active. That might confuse the AD770X.

Which module do you have and how did you connect it to the Arduino ?
Do you use a breadboard ? (they have often bad contacts).

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