2

i connected an Arduino Nano to an external SPI Flash using THIS tutorial (russian) and the SPIMemory library. While accessing the Flash works well, i have encountered the following issue:

The Problem: When the SPI MISO line is pulled high by the flash while the Arduino boots, it does not start, for example because it was rebooted while accessing the flash. I have to power down the Flash before it boots again. But even then, it takes unusually long to boot.

I know that the Atmega328p allows reprogramming via SPI, but to my knowledge this should not cause this behavior since the SPI lines do not change (starting the programming mode would require a command to be sent immediately after restart). Is there any way to prevent this behavior? (Except disabling SPI programming via fuse bits, this would be my last choice)

EDIT

Programming the Arduino via ISP does work, however i added some series resistors to the flash to prevent accidentally driving the SPI lines from multiple sources.

The problem seems to come from the MISO line, when it is pulled to VCC the Arduino does not start. This is not mentioned in the data sheets anywhere and i am not sure how to prevent this (sketch below to show the wiring).

enter image description here

4
  • Is it possible for you to burn the bootloader/flash a sketch via ISP? If you erase the bootloader you can find out if thats where it hangs.
    – Sim Son
    May 11 at 23:50
  • @SimSon I made a few tests, i will add the results to the post, too: writing via ISP does work, however i added some series resistors to the flash to prevent multiple drivers on the same line. Writing the firmware without bootloader greatly speeds up the startup of the arduino, but does not prevent it from freezing when the SPI lines are pulled by the flash. The MISO line seems to be the main problem, when it is pulled to VCC the Arduino does not start.
    – Sabulanis
    May 12 at 9:03
  • how do you actually know that it "freezes"? If it still happens without a bootloader, then it looks like it's caused by your sketch. you might also want to include a wiring diagram
    – Sim Son
    May 12 at 9:09
  • @SimSon i edited the program so that it enables the status led of the nano right at the beginning. The LED remains dark until i pull the MISO line from the nano, then it immediately lights up
    – Sabulanis
    May 12 at 9:16
1

I honestly can't imagine why a sketch like that would hang in this scenario. But I'm confident that my answer can solve the issue.

My guess is that the following happens: The flash is selected (CS pulled low by atmega) at the moment at which the reset happens. At this moment, the master will stop generating a clock signal and CS will be floating. Thus, the flash will not be deselected reliably due to the floating CS and MISO will remain in the state it was before the reset occured (HIGH if it was transmitting a logic 1, LOW for 0). Basically, the SPI communication of the flash will be stuck with MISO being actively pulled to logic high or low.

IDK why this causes the sketch to freeze, but if you add a pullup resistor to the flash's CS, it should be deactivated by default (and also after a reset of the atmega as pins will be inputs/floating by default). As a result, the flash can not actively pull MISO and should therefore barely affect the atmega at all.

I suggest you add the mentioned pullup and see if that makes any difference. If it doesn't I'm going to delete this answer, but it was a bit too long for a comment ;).

Edit: I also just saw that you are missing the pullup resistor on the reset pin. That could well be the actual problem.

2
  • Thank you, this actually works! I've also added a weak pull down on the MISO line to be sure, but this does not seem to be really necessary.
    – Sabulanis
    May 12 at 17:54
  • @Sabulanis I just saw that you also don't have a pullup on the reset pin. That could have been the problem behind it
    – Sim Son
    May 13 at 13:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.