This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

2 SPI Configurations sharing MOSI & MISO

Hello There, I want to connect two slaves to my nRF51422 PCA10028. I came up with the idea of using two master communications which share MOSI AND MISO but have different clocks and chip selects. I want to make sure that I can share the MISO and MOSI. Meanwhile, Is it another hard ware configuration for RX and TX buffers on different pins or that the only ones are 28 and 25?

Thank You

switch (spi_master_instance)
    {
        
        case SPI_MASTER_0:
        {
            spi_config.SPI_Pin_SCK  = 29;
            spi_config.SPI_Pin_MISO = 28;
            spi_config.SPI_Pin_MOSI = 25;
            spi_config.SPI_Pin_SS   = 24;
        }
        break;
				
			  case SPI_MASTER_1:
        {
            spi_config.SPI_Pin_SCK  = 27;
            spi_config.SPI_Pin_MISO = 28;
            spi_config.SPI_Pin_MOSI = 25;
            spi_config.SPI_Pin_SS   = 23;
        }
        break;
        

        default:
            break;
    }
Parents Reply Children
  • I once used the bellow code and got some weird output for my SPI1 clock so I decided to allocate different clocks for each master. Meanwhile, Shouldn't I still define to instance of SPI like SPI0 & SPI1 for making a chip select or what is the other way to do it?

        case SPI_MASTER_0:
     { spi_config.SPI_Pin_SCK = 29;
     spi_config.SPI_Pin_MISO = 28; 
    spi_config.SPI_Pin_MOSI = 25;
     spi_config.SPI_Pin_SS = 24; }
     break;
        
              case SPI_MASTER_1:
        {
            spi_config.SPI_Pin_SCK  = 29; // (I used the same clock)
            spi_config.SPI_Pin_MISO = 28;
            spi_config.SPI_Pin_MOSI = 25;
            spi_config.SPI_Pin_SS   = 23;
        }
        break;
        
        
        default:
            break;
        }
    

    Thank You

  • @Milad: Still I don't understand why you need 2 SPI master instance ?

    You only need 2 SPI master when you need to have 2 slave working at the same time.

    If they can take turn you can use just one master and use the SS pin to control them.

    If you need to use 2 masters instance, and they work at the same time, you can't share any pin between them.

  • I know within the spi_master_send_receive() the select pin get pulled down, I also know its better not to configure the master.c file as well. This brings me to this question should I have the following for every time I wanna switvh between master devices? If not then how could I use the spi_master_send_receive() function while sending spi_master_0 as the argument and puling down the second select pin?

    case SPI_MASTER_0:
    
           { spi_config.SPI_Pin_SCK = 29;
             spi_config.SPI_Pin_MISO = 28; 
             spi_config.SPI_Pin_MOSI = 25;
             spi_config.SPI_Pin_SS = 24; 
    }
    
     break;
    
              case SPI_MASTER_1:
        {
           { spi_config.SPI_Pin_SCK = 29;
             spi_config.SPI_Pin_MISO = 28; 
             spi_config.SPI_Pin_MOSI = 25;
             spi_config.SPI_Pin_SS = 23; 
    }
    
        }
        break;
    
    
        default:
            break;
        }
    
  • @Milad: Please answer my question:

    Do you need to communicate with 2 SPI slaves at the same time ?

    Or you can talk them by turn ? Read/write SPI slave 1 and when you finish you can start to read/write SPI slave 2 ?

    If you need to communicate with 2 SPI slaves at the same time, then you need to have 2 SPI master instance and you only need to define the hardware once. BUT you can't use the same SCK, and MISO for both of them as shown in your code.

    If you don't need to talk to 2 slaves at the same time, and they can take turn then you only configure ONE SPI master. And then you use the SS pins to control each of them. You change the SS pin everytime you want to switch between each slaves.

Related