Arduino nano freezes when calling SPI.begin()

Hi there,

I am using an Arduino Nano, ATmega328P with the old bootloader. When I call SPI.begin() anywhere in the program (either in a seperate callable function, the setup or inside main) the program freezes and the Arduino doesn't seem to budge. Any chance I am doing anything wrong?

It does not matter if I have periphery hooked up or if I don't.

Other libraries which use SPI like the nRFLite library work just fine. I know this because I can successfully communicate with the nRF chip through the library and the example sketches work.

Seems likely.

Code is this.

#include <SPI.h>

int CEpin = 9;
int CSNpin = 10;

//the blinky function is used for debugging and just flashes the on-board LED
void blinky(int repeats, int pauseLength){
  for(int i = 1; i <= repeats; i++){
    digitalWrite(LED_BUILTIN, HIGH);
    digitalWrite(LED_BUILTIN, LOW);

void setup() {

  pinMode(CEpin, OUTPUT);
  pinMode(CSNpin, OUTPUT);

  blinky(5, 100);
  //de-select slave and set chip-enable of slave to 0
  digitalWrite(CEpin, LOW);
  digitalWrite(CSNpin, HIGH);
  //begin SPI with normal settings

  blinky(25, 50);


void loop(){

Is there anything I am not seeing?

EDIT: Wanted to apologize for not posting the code in the first place.

D13, used for LED_BUILTIN, is also used by SPI, so you cannot use both.

1 Like

This is a really great hint already, thank you. I'll try disabling it and report back.


Now, look into the following diagram (Fig-1) to understand that in SPI Mode, DPin-13 carries SCK signal.


1 Like

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