Problems with Arduino DUE

So, I have made one project using a MAX 7219 (the led display 8x32) on my Arduino UNO, but it stopped working and I wanted to continue on a Arduino Due that I found. The problem is, the code utilizes the pins SCK, MOSI and SS ( CLOCK, DATA PIN and CHIP SELECT), that were the pins 13, 11 and 10 on the Arduino UNO.

Checking the pinouts of the Arduino DUE in some other posts, I have found that the SCK and MOSI are some pins in the middle of the board, where I need to use female jumpers to get them. The problem is, those pins doesn't have a "number" for then, they are just the SCK and MOSI itself. On the previous code I defined they by "#define CLK_PIN 13", how can I adjust the code so I can get that pinout?

I'm new to the forum and Arduino itself, so if I am saying things wrongs sorry for my misinformation... and for my bad english as well

The central ISP\SPI connector is where the DUE SPI pins are.

Its also the location of the SPI pins on the UNO and Mega.

You want to do this to figure out if the Uno failed or the max7219 failed? If the max7219 works with the Due you will know that the Uno has failed?

Can you test the Uno another way? Can you upload the blink sketch to it and have the on-board led flashing, for example?

What you need to find out is whether the code uses the hardware SPI of the Uno or is using software SPI ("bit-banging") but by coincidence is using the same pins as are normally used for hardware SPI.

If it is software SPI, then you can use any ordinary digital pins on the Due.

This makes me suspect that your code is using software SPI. It would not be necessary to define that pin if hardware SPI was used.

The UNO is a 5V Logic device and the DUE is a 3.3V logic device.

Can the MAX7219 be used on the 3.3V DUE ?

In theory no. The supply voltage is 4.0-5.5V and a logic high signal must be above 3.5V according to the datasheet.

In practice, I have had max7219 working fine with esp8266 which are also 3.3V. But it is not guaranteed to work.

A logic level shifter such as 74hct125 might be needed.

I actually wanted to continue the project on the DUE, because the capacity of the UNO was basically at its limit... But after the last upload on the code the UNO began to never upload anything at all and I am pretty worried about it. But the UNO was working perfectly fine with the code before.

On the Due while I was trying to make the code work on it, the max7219 is sometimes with all the led's off, sometimes all on, or just some 8x8 at a time. I don't know actually if the problem is on the code (and saying the right things abot the 3 pins - SCK, MOSI and SS) or the max7219, but before trying it on Due it was perfectly fine.

Ohhh understood, I did not know there was a difference there, the parts of using those pins of the display specifically I got from another code, so I assumed it was necessary to be those pins (the original code is actually written as "#define CS_PIN 10 // or SS", so I assumed it was the SS of the board that you are using. Is there a way for me to know if I am using a software SPI or the hardware SPI? I am just know learning about those and it's quite interesting.

Okay, I am gonna try using on 3 "random" pins on the DUE and see if it is gonna work.

Thankss a lot for the response

Ohh I did not think of that, maybe that could be the problem cause the matrix even with everything on it sometimes experienced some instability.

Maybe that would fix the problem but I am still gonna try some other stuff and see if I can maybe make the code "kinda work" on it first
Thanks so much for the help

It would be clear to us all if you posted the code.

The only part of the code that actually uses these defined PINs is the mx and P below, so I don't know if they have a bigger influence on the rest of it just by being defined (I believe they don't have right??).

This define thing I got from another code so I don't know if it could be done other way or if it must be this way

Plus, I am not sure if the voltage thing is a problem because on the Arduino Due there is a pin (the 5V pin) that has a 4.5/4.8 DC on it (I used a multimeter) , so it has a voltage pretty similar right?

#include <MD_MAX72xx.h>
#include <MD_Parola.h>

#define HARDWARE_TYPE MD_MAX72XX::ICSTATION_HW
#define MAX_DEVICES   4
#define CLK_PIN   13  // or SCK
#define DATA_PIN  11 // or MOSI
#define CS_PIN    10  // or SS

MD_MAX72XX mx = MD_MAX72XX(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);

These definitions are not used anywhere in your code. Try searching for them and you will see. You can delete those lines, they have no effect on the code.

This must mean that the library is using hardware SPI. So you should use hardware SPI pins on the Due also. You don't need to update the code because they are different pins on the Due.

If you want to use the SPI pins on the ISP connector, and you want new names for them, you can do:

#define CLK_PIN SCK
#define SPIOUT_PIN MOSI  // or whatecer...
#define SPIIN_PIN MISO

(the standard names SCK/MOSI/MISO are defined in the appropriate "variant.h" file.)

There is an error in variant.h for Due:

#define PIN_SPI_SS0          (77u)
#define PIN_SPI_SS1          (87u)
#define PIN_SPI_SS2          (86u)
#define PIN_SPI_SS3          (78u)
...
#define BOARD_SPI_SS0        (10u)
#define BOARD_SPI_SS1        (4u)
#define BOARD_SPI_SS2        (52u)
#define BOARD_SPI_SS3        PIN_SPI_SS3
#define BOARD_SPI_DEFAULT_SS BOARD_SPI_SS3

On the Due board there is no pin 78, nor 77, 86, 87!
If you use function calls from the SPI library you have to choose those calls with chip select pin as first parameter, e.g.

int cs_pin   = 4;  // or 
...
SPI.begin(cs_pin);
SPI.transfer(cs_pin, 0xFF);

never use:

SPI.begin();
SPI.transfer(0xFF);

because without cs_pin as parameter BOARD_SPI_DEFAULT_SS will be used as chip select.

Are you sure? On some boards, pins will have multiple "Arduino Pin Numbers", depending on what function is being demanded of them. Since the g_aPinDescription type only lets a pin have a single function, usually.

For instance, looking at variant.cpp, there is an entry for "pin 86":

  // 86 - SPI CS2
  { PIOB, PIO_PB21B_SPI0_NPCS2, ID_PIOB, PIO_PERIPH_B, PIO_DEFAULT, PIN_ATTR_DIGITAL,                  NO_ADC, NO_ADC, NOT_ON_PWM,  NOT_ON_TI

which is an alias of pin 52 (also on PB21):

  { PIOB, PIO_PB21,          ID_PIOB, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL,                  NO_ADC, NO_ADC, NOT_ON_PWM,  NOT_ON_TIMER }, // PIN 52