Set the right SS pin when using several SPI devices

My question is:

in order to share the SPI bus I have to have different SS pins. One for each device that share the bus. When Arduino wants to speak with one, it has to set LOW the SS related.
So, I tried to put LOW a digital PIN different from the native one (53) and I connect the digital pint to the SS pin of my shield but this does not work.

So, are you sure that simply set LOW a digital pin the communication works properly? In my case does not work

You cannot set the SS pin low yourself. You have to tell the code which pin is the SS pin and let the SPI library control it.

I tried both: by library and putting the pin to the ground.

Both cases failed!

You haven't posted your code so I don't know how we are supposed to answer your question.

the code is very simple like:

main loop {

set LOW pin X

read from SPI

set HIGH pin X }

This type of code does not work

I don't care how simple it is. If you want an answer to your question post all the code for all the shields or don't ask the question.

This is the code:

#include <mcp_can.h>
#include <SPI.h>

unsigned char len = 0;
unsigned char buf[8];

unsigned int ID;
int LED13 = 13;


void setup()
{
    pinMode(LED13, OUTPUT);
    pinMode(24, OUTPUT); 
    Serial.begin(115200);
  
START_INIT:
     
    if(CAN_OK == CAN.begin(CAN_500KBPS))                   // init can bus : baudrate = 500k
    {
        Serial.println("CAN BUS Shield init ok!");
    }
    else
    {
        Serial.println("CAN BUS Shield init fail");
        Serial.println("Init CAN BUS Shield again");
        delay(100);
        goto START_INIT;
    }
}

void loop()
{
  
  digitalWrite(24, LOW);
  
    // check if data are coming
    if(CAN_MSGAVAIL == CAN.checkReceive()) 
    {
        //*******************Begin RX****************
        //read data,  len: data length, buf: data buf
        CAN.readMsgBuf(&len, buf); 
        // read ID - max ID_HEX value is 7FF (standard CAN 11 bit)
        ID=CAN.getCanId(); 
    
        //this led is HIGH for TX
        digitalWrite(LED13, LOW);
        
        //ID printing
        Serial.print(ID,HEX);
        Serial.print("\t");
        
        //Data messages printing
        for(int i = 0; i<len; i++)    // print the data
        {
            Serial.print(buf[i],HEX);
            Serial.print("\t");
            
        }
        Serial.println();
    }
    //*******************End TX****************
    
    //delay between RX and TX
    delay(1000);
    
    //*******************Begin TX****************
    //the leds shows the TX
    digitalWrite(LED13, HIGH);
    
    //ID TX - max ID_HEX value is 7FF (standard CAN 11 bit)
    unsigned int ID_tx=0x123;
    //Data TX
    unsigned char stmp[8] = {255, 1, 2, 3, 4, 5, 6, 7};
    //send ID+DATA
    CAN.sendMsgBuf(ID_tx, 0, 8, stmp);   // send data:  id = 0x00, standrad flame, data len = 8, stmp: data buf
    
    //*******************End TX****************
    
    //delay between TX and RX
    delay(1000);
    
    digitalWrite(24, HIGH);
    
}//end void loop

/*********************************************************************************************************
  END FILE
   #include <mcp_can.h>
#include <SPI.h>

unsigned char len = 0;
unsigned char buf[8];

unsigned int ID;
int LED13 = 13;


void setup()
{
    pinMode(LED13, OUTPUT);
    pinMode(24, OUTPUT); 
    Serial.begin(115200);
  
START_INIT:
     
    if(CAN_OK == CAN.begin(CAN_500KBPS))                   // init can bus : baudrate = 500k
    {
        Serial.println("CAN BUS Shield init ok!");
    }
    else
    {
        Serial.println("CAN BUS Shield init fail");
        Serial.println("Init CAN BUS Shield again");
        delay(100);
        goto START_INIT;
    }
}

void loop()
{
  
  digitalWrite(24, LOW);
  
    // check if data are coming
    if(CAN_MSGAVAIL == CAN.checkReceive()) 
    {
        //*******************Begin RX****************
        //read data,  len: data length, buf: data buf
        CAN.readMsgBuf(&len, buf); 
        // read ID - max ID_HEX value is 7FF (standard CAN 11 bit)
        ID=CAN.getCanId(); 
    
        //this led is HIGH for TX
        digitalWrite(LED13, LOW);
        
        //ID printing
        Serial.print(ID,HEX);
        Serial.print("\t");
        
        //Data messages printing
        for(int i = 0; i<len; i++)    // print the data
        {
            Serial.print(buf,HEX);
            Serial.print("\t");
            
        }
        Serial.println();
    }
    //*******************End TX****************
    
    //delay between RX and TX
    delay(1000);
    
    //*******************Begin TX****************
    //the leds shows the TX
    digitalWrite(LED13, HIGH);
    
    //ID TX - max ID_HEX value is 7FF (standard CAN 11 bit)
    unsigned int ID_tx=0x123;
    //Data TX
    unsigned char stmp[8] = {255, 1, 2, 3, 4, 5, 6, 7};
    //send ID+DATA
    CAN.sendMsgBuf(ID_tx, 0, 8, stmp);   // send data:  id = 0x00, standrad flame, data len = 8, stmp: data buf
    
    //*******************End TX****************
    
    //delay between TX and RX
    delay(1000);
    
    digitalWrite(24, HIGH);
    
}//end void loop

/****************************************************

click the MODIFY button in the upper right of the post window.
Highlight all you code.
click the “#” CODE TAGS button on the toolbar above just to the left of the QUOTE button.
click SAVE (at the bottom).
When you post code on the forum, please make a habit of using the code tags “#” button.

Arduino Uno + Arduino Motorshield + Arduino Wifi Shield is this possible?

THIS IS YOUR POST TITLE

I'm trying to figure out if I could stack these three boards together, but I've been reading there is conflicts on pins 11-13. Is this true?

THIS IS YOUR QUESTION

CAN BUS Shield

DOES YOUR POST TITLE SAY ANYTHING ABOUT CAN BUS SHIELD ?

THE CODE YOU JUST POSTED IS NOT ANY OF THE CODE FOR THE HARDWARE LISTED IN YOUR POST TITLE NO , YOU CANNOT RUN THIS "CAN BUS SHIELD " CODE BECAUSE IT IS USING PIN 13 FOR A LED

  int LED13 = 13;

WHERE IS ALL THE OTHER CODE FOR THE SHIELDS ?

When you post all the code for the hardware in your post title we can check to see if any of THAT code is using pin-13 for a LED. There is no reason why the led in this code needs to be pin 13. If that is the only use of that pin you can reassign the led to any other pin.

HI, probably you did not understand the code.

The PIN13 is used to transmit to me the idea that the TX and the RX are working properly. The PIN24 is instead used to simulate the SS!

this is the code the I use now to TX and RX data from the shield

raschemmel,

This fellow celica is NOT the original poster. He hijacked this old post (necropost) and started discussing his own problems, not entirely related to the original post or its title. I hate to shut people up but this is when I have to say “shut up and start your own post”.

Anyone reading this thread will be confused by this fellow and his new questions and even if he gets his answers, it’s buried with this non-related post and nobody will find it.

celica,

Stop posting on this thread and start your own post!!!

@celica, Start your own post. This is someone else's thread. If you don't stop posting on this thread the Global Moderator will ask you to start your own post. It is rude to hijack someone else's thread. Start your own post.

Also starting your own post with a proper title gets you more help. It also helps others with your question find answer in your new post.

I splitted the new question from celica into a new thread. If you, celica, thinks that the title isn't appropriate, plase edit the first post and this new thread and feel free to change it

@everybody: please have more patience :sweat_smile: :sweat_smile: