Arduino Mega2560 no signal on MOSI or MISO. - Page 1
Forum section: electronics / general

author: NoradIV
author_rank: Contributor
timestamp: March 19, 2017, 07:32:21 pm
content: Hello everyone,I am currently working on a project. I have purchased thefollowing boardto use with my Mega2560.I am using thisdemo codeas-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 arduinopin layoutto 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!

author: ElectronicCat
author_rank: Regular Contributor
timestamp: March 19, 2017, 09:53:30 pm
content: 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.

author: Avacee
author_rank: Unknown
timestamp: March 19, 2017, 10:03:03 pm
content: The Mega2560 SPI pins are: 50 (MISO), 51 (MOSI), 52 (SCK), 53 (SS).Taken from this link:https://www.arduino.cc/en/Main/arduinoBoardMega2560Are 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/MegaQuickReffor the Mega2560 pin layoutTaking 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?

author: Nusa
author_rank: Super Contributor
timestamp: March 19, 2017, 10:22:42 pm
content: 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!

author: NoradIV
author_rank: Contributor
timestamp: March 19, 2017, 10:26:31 pm
content: Quote from: Avacee on March 19, 2017, 10:03:03 pmSorry, 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 Module5V | VCCGND | GNDMOSI | MISOMISO | MOSISCK | CLKPIN 53 | CSRegardless what connected or programmed, nothing is outputted from MOSI. Clocks and CS works fine thought.

author: artag
author_rank: Super Contributor
timestamp: March 19, 2017, 10:33:54 pm
content: 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)

author: Avacee
author_rank: Unknown
timestamp: March 19, 2017, 10:37:45 pm
content: Regarding your wiring table: MOSI <--> MOSI and MISO <--> MISOIt's not like serial where RX <-> TX.Did you try a digitalWrite?

author: Nusa
author_rank: Super Contributor
timestamp: March 19, 2017, 10:44:58 pm
content: It can be helpful to remember what the abbreviations stand for:SCLK = Serial ClockMOSI = Master Out Slave InMISO = Master In Slave OutSS = Slave Select (usually active low)The arduino is the Master in this situation.

author: NoradIV
author_rank: Contributor
timestamp: March 20, 2017, 12:31:50 am
content: Quote from: artag on March 19, 2017, 10:33:54 pmI am using that header.Quote from: Avacee on March 19, 2017, 10:37:45 pmOh, 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.

author: rrinker
author_rank: Super Contributor
timestamp: March 20, 2017, 12:39:56 am
content: 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.

author: NoradIV
author_rank: Contributor
timestamp: March 20, 2017, 02:12:58 am
content: Quote from: rrinker on March 20, 2017, 12:39:56 amNot 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.

author: rrinker
author_rank: Super Contributor
timestamp: March 20, 2017, 07:44:12 pm
content: 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.

author: NoradIV
author_rank: Contributor
timestamp: March 20, 2017, 08:23:27 pm
content: Quote from: rrinker on March 20, 2017, 07:44:12 pmOh, sorry, my bad. I didn't understand what you meant.I will test it and come back with the results tonight.

author: NoradIV
author_rank: Contributor
timestamp: March 22, 2017, 08:15:37 pm
content: 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).

author: rrinker
author_rank: Super Contributor
timestamp: March 23, 2017, 02:55:42 pm
content: 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.

author: NoradIV
author_rank: Contributor
timestamp: March 23, 2017, 10:29:32 pm
content: Quote from: rrinker on March 23, 2017, 02:55:42 pmI am using the demo code from arduino:https://www.arduino.cc/en/Tutorial/ReadWriteI have connected my scope to both mosi and miso, nothing gets transmitted to either pins. The clock and enable works fine thought.

author: NoradIV
author_rank: Contributor
timestamp: March 26, 2017, 10:13:04 pm
content: Bump for help.Please?

author: Avacee
author_rank: Unknown
timestamp: March 26, 2017, 10:21:34 pm
content: 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.

author: NoradIV
author_rank: Contributor
timestamp: March 27, 2017, 08:46:51 pm
content: Here is the exact code:Code:#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)

author: Avacee
author_rank: Unknown
timestamp: March 27, 2017, 10:34:03 pm
content: 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 photosThe Logic Analyzer shows the start of the SPI communication from SD.begin().50 - MISO - Green - Channel 051 - MOSI - White - Channel 152 - CLOCK - Yellow - Channel 253 - ENABLE - Blue - Channel 3ICSP1 - Pin1 - MISO1 - Green - Channel 4ICSP1 - Pin5 - MOSI1 - White - Channel 5I 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: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);}

author: NoradIV
author_rank: Contributor
timestamp: March 28, 2017, 10:50:06 pm
content: Quote from: Avacee on March 27, 2017, 10:34:03 pmI 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!

author: Avacee
author_rank: Unknown
timestamp: March 29, 2017, 09:00:50 am
content: Quote from: NoradIV on March 28, 2017, 10:50:06 pmHa haLessons learnt the hard way are rarely repeated ... or maybe they are :phttps://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/ArduinoPinCurrentLimitationsIt 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.Quote from: NoradIV on March 28, 2017, 10:50:06 pmNo problem

author: NoradIV
author_rank: Contributor
timestamp: March 29, 2017, 09:08:48 pm
content: 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.