Author Topic: Arduino Mega2560 no signal on MOSI or MISO.  (Read 11970 times)

0 Members and 1 Guest are viewing this topic.

Offline NoradIVTopic starter

  • Contributor
  • Posts: 23
  • Country: ca
Arduino Mega2560 no signal on MOSI or MISO.
« on: March 19, 2017, 07:32:21 pm »
Hello everyone,

I am currently working on a project. I have purchased the following board to use with my Mega2560.

I am using this demo code as-is (only removed the SS pin to use the default one on the Mega).

Currently, the sd.begin() does not appear to work at all.

I have connected my old (and inadequate) LBO-310A on the MOSI and MISO pins. I get no data transmitted from the arduino at all.

I have done the following troubleshooting steps:
1. Tried to create an empty project to make sure this was not an interference from some other code I originally had.
2. Used an arduino pin layout to make sure nothing was shorting the SPI header from the digital IO header.
3. Tried two different SD cards and SD boards.
4. Disconnected the SD boards to make sure they were not shorted out.

I also tried to manually transmit using spi.initialize() and spi.transfer(), but this is my first time coding this thing, so I do not know how good my code was.

Any help would me much appreciated.

Thanks!
 

Offline ElectronicCat

  • Regular Contributor
  • *
  • Posts: 61
  • Country: gb
Re: Arduino Mega2560 no signal on MOSI or MISO.
« Reply #1 on: March 19, 2017, 09:53:30 pm »
Can you post a photo or wiring diagram that you have used? You could also try running the code through a debugger and seeing where it fails.
 

Offline Avacee

  • Supporter
  • ****
  • Posts: 299
  • Country: gb
Re: Arduino Mega2560 no signal on MOSI or MISO.
« Reply #2 on: March 19, 2017, 10:03:03 pm »
The Mega2560 SPI pins are: 50 (MISO), 51 (MOSI), 52 (SCK), 53 (SS).
Taken from this link: https://www.arduino.cc/en/Main/arduinoBoardMega2560

Are you checking pins 50-53 or pins 11,12,13 mentioned in the code and are applicable for the UNO.
I ask as the pin layout link you provided is for an UNO and not a Mega2560.

https://arduino-info.wikispaces.com/MegaQuickRef  for the Mega2560 pin layout


Taking SPI out of the equation what do you get if you execute   digitalWrite(pinNumber_To_Check,HIGH)   - do you get 5V?
If not 5V, what do you get and how are you powering your arduino?
« Last Edit: March 19, 2017, 10:18:50 pm by Avacee »
 

Offline Nusa

  • Super Contributor
  • ***
  • Posts: 2418
  • Country: us
Re: Arduino Mega2560 no signal on MOSI or MISO.
« Reply #3 on: March 19, 2017, 10:22:42 pm »
The demo source should be portable, it's only the comments about pin assignments are hardware specific. Still, you do have to know which pins they are for wiring purposes!
 

Offline NoradIVTopic starter

  • Contributor
  • Posts: 23
  • Country: ca
Re: Arduino Mega2560 no signal on MOSI or MISO.
« Reply #4 on: March 19, 2017, 10:26:31 pm »
The Mega2560 SPI pins are: 50 (MISO), 51 (MOSI), 52 (SCK), 53 (SS).
Taken from this link: https://www.arduino.cc/en/Main/arduinoBoardMega2560

Are you checking pins 50-53 or pins 11,12,13 mentioned in the code and are applicable for the UNO.
I ask as the pin layout link you provided is for an UNO and not a Mega2560.

https://arduino-info.wikispaces.com/MegaQuickRef  for the Mega2560 pin layout


Taking SPI out of the equation what do you get if you execute   digitalWrite(pinNumber_To_Check,HIGH)   - do you get 5V?
If not 5V, what do you get and how are you powering your arduino?

Sorry, I did not provide a picture because there is a lot going on on the board right now. It is wired to a breadboard.

I am using the SPI header from the mega, and I made sure 50-53 are not connected to anything else. Both of 50-53 and the SPI headers are outputting the same things.

I basically have the following wiring:
Arduino | SD Module
5V         | VCC
GND      | GND
MOSI     | MISO
MISO    | MOSI
SCK      | CLK
PIN 53  | CS

Regardless what connected or programmed, nothing is outputted from MOSI. Clocks and CS works fine thought.
« Last Edit: March 19, 2017, 10:34:14 pm by NoradIV »
 

Offline artag

  • Super Contributor
  • ***
  • Posts: 1365
  • Country: gb
Re: Arduino Mega2560 no signal on MOSI or MISO.
« Reply #5 on: March 19, 2017, 10:33:54 pm »
Are you using the ICSP header near the reset button (AVR SPI) or the one near the USB connector (USB interface SPI) ?
(actually, the presence of SCLK probably proves you're using the correct header)
 
« Last Edit: March 19, 2017, 10:37:41 pm by artag »
 

Offline Avacee

  • Supporter
  • ****
  • Posts: 299
  • Country: gb
Re: Arduino Mega2560 no signal on MOSI or MISO.
« Reply #6 on: March 19, 2017, 10:37:45 pm »
Regarding your wiring table:  MOSI  <--> MOSI and MISO <-->  MISO
It's not like serial where RX <-> TX.

Did you try a digitalWrite?
« Last Edit: March 19, 2017, 10:39:21 pm by Avacee »
 

Offline Nusa

  • Super Contributor
  • ***
  • Posts: 2418
  • Country: us
Re: Arduino Mega2560 no signal on MOSI or MISO.
« Reply #7 on: March 19, 2017, 10:44:58 pm »
It can be helpful to remember what the abbreviations stand for:

SCLK = Serial Clock
MOSI = Master Out Slave In
MISO = Master In Slave Out
SS = Slave Select (usually active low)

The arduino is the Master in this situation.
 

Offline NoradIVTopic starter

  • Contributor
  • Posts: 23
  • Country: ca
Re: Arduino Mega2560 no signal on MOSI or MISO.
« Reply #8 on: March 20, 2017, 12:31:50 am »
Are you using the ICSP header near the reset button (AVR SPI) or the one near the USB connector (USB interface SPI) ?
(actually, the presence of SCLK probably proves you're using the correct header)
 

I am using that header.

Regarding your wiring table:  MOSI  <--> MOSI and MISO <-->  MISO
It's not like serial where RX <-> TX.

Did you try a digitalWrite?

Oh, well, that would certainly not help. Thanks for that clarification.

I tried digitalWrite, but my coding "skills" are almost inexistant in C++; I am not sure I wrote the test code properly with this function as I am unsure what initialization and prerequesites are needed for that function.
 

Offline rrinker

  • Super Contributor
  • ***
  • Posts: 2046
  • Country: us
Re: Arduino Mega2560 no signal on MOSI or MISO.
« Reply #9 on: March 20, 2017, 12:39:56 am »
 Use the initial Blink example sketch but change the pin number to the pin you are trying to use, and hook the LED and resistor to it. If the hardware is good, the LED will blink.

 

Offline NoradIVTopic starter

  • Contributor
  • Posts: 23
  • Country: ca
Re: Arduino Mega2560 no signal on MOSI or MISO.
« Reply #10 on: March 20, 2017, 02:12:58 am »
Use the initial Blink example sketch but change the pin number to the pin you are trying to use, and hook the LED and resistor to it. If the hardware is good, the LED will blink.



Not sure what you mean. I have a LCD display on it as well as a couple leds and stuff. Everything works fine aside of the SPI data transmission.
 

Offline rrinker

  • Super Contributor
  • ***
  • Posts: 2046
  • Country: us
Re: Arduino Mega2560 no signal on MOSI or MISO.
« Reply #11 on: March 20, 2017, 07:44:12 pm »
 Since we were trying to see if the MISO and MOSI pins are functional or else hardware damaged, the idea was to just turn one on (set it to output, set output to high, measure voltage - should be 5V) and you indicated you weren't sure how to do that. So the easy alternative, load the blink sketch but change the pin number to whatever pin number is being used for MISO or MOSI. Hook an LED and resistor to that pin, see if it blinks. If it does for both, the hardware is OK and the problem is with your main sketch in that it is not correctly addressing the MISO and MOSI pins.

 

Offline NoradIVTopic starter

  • Contributor
  • Posts: 23
  • Country: ca
Re: Arduino Mega2560 no signal on MOSI or MISO.
« Reply #12 on: March 20, 2017, 08:23:27 pm »
Since we were trying to see if the MISO and MOSI pins are functional or else hardware damaged, the idea was to just turn one on (set it to output, set output to high, measure voltage - should be 5V) and you indicated you weren't sure how to do that. So the easy alternative, load the blink sketch but change the pin number to whatever pin number is being used for MISO or MOSI. Hook an LED and resistor to that pin, see if it blinks. If it does for both, the hardware is OK and the problem is with your main sketch in that it is not correctly addressing the MISO and MOSI pins.



Oh, sorry, my bad. I didn't understand what you meant.

I will test it and come back with the results tonight.
 

Offline NoradIVTopic starter

  • Contributor
  • Posts: 23
  • Country: ca
Re: Arduino Mega2560 no signal on MOSI or MISO.
« Reply #13 on: March 22, 2017, 08:15:37 pm »
Ok, I have basically made the following code:



void loop() {
  digitalWrite(52, HIGH);
  digitalWrite(51, HIGH);
  digitalWrite(50, HIGH);
  delay(1);
  digitalWrite(52, LOW);
  digitalWrite(51, LOW);
  digitalWrite(50, LOW);
  delay(1);
}


This outputs a relatively clean square wave (it is quite possible that the problem is my LBO-310A with alligator clips showing a slightly disorted wave).
 

Offline rrinker

  • Super Contributor
  • ***
  • Posts: 2046
  • Country: us
Re: Arduino Mega2560 no signal on MOSI or MISO.
« Reply #14 on: March 23, 2017, 02:55:42 pm »
 OK, so the hardware is fine. How are you trying to implement SPI? With the standard Arduino libray? If so, it should work, those are the correct pins on the Mega and we know that all 3 are working. It would seem to be a software problem at this point, unless the slave device is not connected or operating properly.
 

Offline NoradIVTopic starter

  • Contributor
  • Posts: 23
  • Country: ca
Re: Arduino Mega2560 no signal on MOSI or MISO.
« Reply #15 on: March 23, 2017, 10:29:32 pm »
OK, so the hardware is fine. How are you trying to implement SPI? With the standard Arduino libray? If so, it should work, those are the correct pins on the Mega and we know that all 3 are working. It would seem to be a software problem at this point, unless the slave device is not connected or operating properly.


I am using the demo code from arduino: https://www.arduino.cc/en/Tutorial/ReadWrite

I have connected my scope to both mosi and miso, nothing gets transmitted to either pins. The clock and enable works fine thought.
 

Offline NoradIVTopic starter

  • Contributor
  • Posts: 23
  • Country: ca
Re: Arduino Mega2560 no signal on MOSI or MISO.
« Reply #16 on: March 26, 2017, 10:13:04 pm »
Bump for help.

Please?
 

Offline Avacee

  • Supporter
  • ****
  • Posts: 299
  • Country: gb
Re: Arduino Mega2560 no signal on MOSI or MISO.
« Reply #17 on: March 26, 2017, 10:21:34 pm »
Can you post a schematic and/or a decent quality photo that lets people see your wiring?

Also the actual code you are using if it's different (even by one line) from the link you posted.
 

Offline NoradIVTopic starter

  • Contributor
  • Posts: 23
  • Country: ca
Re: Arduino Mega2560 no signal on MOSI or MISO.
« Reply #18 on: March 27, 2017, 08:46:51 pm »
Here is the exact code:

Code: [Select]
#include <Arduino.h>
#include <SPI.h>
#include <SD.h>

File myFile;

void setup() {
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }


  Serial.print("Initializing SD card...");

  if (!SD.begin()) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");
}
void loop() {
}

As far as wiring goes, I mean, its an oscilloscope connected to the MOSI pin on the ICSP header. Not that I want to argue, but I do not have a software for making schematics. Do you need one for that? (I have disconnected everything else from the board)
« Last Edit: March 27, 2017, 09:43:05 pm by NoradIV »
 

Offline Avacee

  • Supporter
  • ****
  • Posts: 299
  • Country: gb
Re: Arduino Mega2560 no signal on MOSI or MISO.
« Reply #19 on: March 27, 2017, 10:34:03 pm »
And you are definitely using the ICSP1 header in the middle of the board between the chip and reset button?

I have the same micro-SD Card Reader so knocked it up on the breadboard with the Logic Analyzer - See photos
The Logic Analyzer shows the start of the SPI communication from SD.begin().
50 - MISO - Green - Channel 0
51 - MOSI - White - Channel 1
52 - CLOCK - Yellow - Channel 2
53 - ENABLE - Blue - Channel 3

ICSP1 - Pin1 - MISO1 - Green - Channel 4
ICSP1 - Pin5 - MOSI1 - White - Channel 5

I appreciate this is a "It works on my machine" but the Logic Analyzer shows the same data when connected to MOSI1 and MISO1 pins (middle of the board)
It shows nothing when I connect to the MOSI2 and MISO2 pins which are on the second ICSP2 header by the Digital 13 pin.

Detach your SD reader and try the following code that will just toggle pins 50-53 HIGH and LOW every 100ms.
Do these HIGH/LOWs show on your oscilloscope - both on the pin and on the ICSP header?
Code: [Select]
void setup()
{
for (int i = 50; i < 54; i++)
pinMode(i, OUTPUT);

}
void loop()
{
for (int i = 50; i < 54; i++)
{
digitalWrite(i, HIGH);
}
delay(100);
for (int i = 50; i < 54; i++)
{
digitalWrite(i, LOW);
}
delay(100);
}
« Last Edit: March 27, 2017, 11:13:33 pm by Avacee »
 

Offline NoradIVTopic starter

  • Contributor
  • Posts: 23
  • Country: ca
Re: Arduino Mega2560 no signal on MOSI or MISO.
« Reply #20 on: March 28, 2017, 10:50:06 pm »
And you are definitely using the ICSP1 header in the middle of the board between the chip and reset button?

I have the same micro-SD Card Reader so knocked it up on the breadboard with the Logic Analyzer - See photos
The Logic Analyzer shows the start of the SPI communication from SD.begin().
50 - MISO - Green - Channel 0
51 - MOSI - White - Channel 1
52 - CLOCK - Yellow - Channel 2
53 - ENABLE - Blue - Channel 3

ICSP1 - Pin1 - MISO1 - Green - Channel 4
ICSP1 - Pin5 - MOSI1 - White - Channel 5

I appreciate this is a "It works on my machine" but the Logic Analyzer shows the same data when connected to MOSI1 and MISO1 pins (middle of the board)
It shows nothing when I connect to the MOSI2 and MISO2 pins which are on the second ICSP2 header by the Digital 13 pin.

Detach your SD reader and try the following code that will just toggle pins 50-53 HIGH and LOW every 100ms.
Do these HIGH/LOWs show on your oscilloscope - both on the pin and on the ICSP header?
Code: [Select]
void setup()
{
for (int i = 50; i < 54; i++)
pinMode(i, OUTPUT);

}
void loop()
{
for (int i = 50; i < 54; i++)
{
digitalWrite(i, HIGH);
}
delay(100);
for (int i = 50; i < 54; i++)
{
digitalWrite(i, LOW);
}
delay(100);
}


I finally figured it out.

I tried what you told me, and tweaked my oscilloscope to get better results for the picture, and while doing boosting the intensity of my faded out CRT, I saw a bunch of noise on the CS, MOSI and MISO pins on the board that I couldn't see before due to the faint image.

When I saw that, I went ahead and started to measure voltages (I have just watched a couple of Dave's video recently, and he says 'thou shall check voltages'). In doing so, I realized that my MOSI was wired to the ground of the module and the ground to the MOSI pin.

No wonder it didn't work!

A little context here; I have not done electronics since I have left college, 5 years ago. And while doping this project, I am teaching electronics to a mate. We split tasks; I give him more "manual" stuff, and I work on the code and design.

I gave him the task of making the connector and identify the wire with tape, but I didn't doublecheck it.

Well, my fault, sorry!

I want to apologize for wasting y'all time, and I really appreciate your help!
 

Offline Avacee

  • Supporter
  • ****
  • Posts: 299
  • Country: gb
Re: Arduino Mega2560 no signal on MOSI or MISO.
« Reply #21 on: March 29, 2017, 09:00:50 am »
<snip>
I realized that my MOSI was wired to the ground of the module and the ground to the MOSI pin..
<snip>
I gave him the task of making the connector and identify the wire with tape, but I didn't doublecheck it.
Well, my fault, sorry!

Ha ha   :palm:
Lessons learnt the hard way are rarely repeated ... or maybe they are :p  https://www.eevblog.com/forum/chat/things-i-learn-over-and-over/

You need to check the mega hasn't blown any of its pins.
The absolute max current per Arduino pin is 40ma with a recommended max of 20ma.  http://playground.arduino.cc/Main/ArduinoPinCurrentLimitations
It sounds as if the pins have been directly shorted to ground which can exceed the current limit and cause pin damage.

If your SPI communications have glitches this is something to consider or given the cost of a mega just start over with a new one.


I want to apologize for wasting y'all time, and I really appreciate your help!
No problem  :-+
« Last Edit: March 29, 2017, 09:26:59 am by Avacee »
 

Offline NoradIVTopic starter

  • Contributor
  • Posts: 23
  • Country: ca
Re: Arduino Mega2560 no signal on MOSI or MISO.
« Reply #22 on: March 29, 2017, 09:08:48 pm »
I will take that into account, but I cannot affoard a decent oscilloscope at the moment, so I have no way of checking.

I am building this project for someone else, so I have ordered another arduino already in order to have a replica of the thing at home (he lives kinda far). I can use both of the units at the same time if needed.

Seeing the chips in there, I doubt the power usage of it exceed the 40ma, but I will not disregard this information anyway.

Although, I tried the code you gave me (around 100Hz) and the board looks fine.

« Last Edit: March 29, 2017, 11:30:20 pm by NoradIV »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf