Trying SPI basics in Arduino Mega

Dear all,

I am quite new with the Arduino and I was trying to make an SPI communication, just sending a number an watching in the osciloscope if something is sent or not. I noticed that the pin 51 of the Arduino Mega (MOSI pin) is by default HIGH. In the code below, MOSI pin is HIGH, a number is sent (a combination of HIGH and LOWs is readed in te oscilloscope) and then MOSI is HIGH again

#include <SPI.h> 

//const int SlaveSelectPin = 53;
#define SlaveSelectPin 53

void setup() {
  pinMode(SlaveSelectPin, OUTPUT);
  SPI.begin();
  SPI.setClockDivider(SPI_CLOCK_DIV16); //1 MHZ
  pinMode(MOSI, OUTPUT);
  
}

void loop() {

  digitalWrite(MOSI, HIGH);
  delay(1000);
  digitalWrite(MISO, LOW);
  delay(1000);
  SPI.transfer(45);
  
}

I wanted to know why is the MOSI pin HIGH by default, and not LOW.

Best regards

mattinm:
Dear all,

I am quite new with the Arduino and I was trying to make an SPI communication, just sending a number an watching in the osciloscope if something is sent or not. I noticed that the pin 51 of the Arduino Mega (MOSI pin) is by default HIGH. In the code below, MOSI pin is HIGH, a number is sent (a combination of HIGH and LOWs is readed in te oscilloscope) and then MOSI is HIGH again

#include <SPI.h> 

//const int SlaveSelectPin = 53;
#define SlaveSelectPin 53

void setup() {
  pinMode(SlaveSelectPin, OUTPUT);
  SPI.begin();
  SPI.setClockDivider(SPI_CLOCK_DIV16); //1 MHZ
  pinMode(MOSI, OUTPUT);
 
}

void loop() {

digitalWrite(MOSI, HIGH);
  delay(1000);
  digitalWrite(MISO, LOW);
  delay(1000);
  SPI.transfer(45);
 
}




I wanted to know why is the MOSI pin HIGH by default, and not LOW.

Best regards

Your driving MOSI and MISO direct, this is not normal.

And as far as the Arduino is concerned MISO is an input yet you seem to be using it as a output and driving it low.

SPI.transfer(45) Will cause data to be clocked out of MOSI, but dont try to control these pins direct.

Read the Atmel datsheet for the Atmega 2560 and you will get all the details of SPI. It is actually very straighforward.

...R