How to call multiple slaves for Spi data transmission?

933 views Asked by At

I have a general approach where the Data in SDRAM is Transferred SPIC.DATA. I have added delay function in order to adjust my digital signal with the Sampling frequency.

    /* Transfer data from internal memory via SPI from Master to Slave */
        if ( (SWITCHPORTL.IN & PIN2_bm) == 0 )
        {

flip = false;
            j = 0;
            while (j < NUM_BYTES)
            {   
                if (flip == false)
                {
                    // Set slave select line low (active) for Port C
                    PORTC.OUTCLR = PIN4_bm;
                }               
                // Give the data to the data register of the Master
                SPIC.DATA = __far_mem_read(j+SDRAM_ADDR);
                if (flip == true)
                {
// wait for the 2nd 8-bit-block to be send 
-> delay 0.7us
                    _delay_us(0.7);         
                    // Set slave select line high (inactive)
                    PORTC.OUTSET = PIN4_bm;
                // delay to adjust to sampling frequency 
100 kHz -> 6.9us; 200kHz -> 1.9us
                    _delay_us(1.9);                                 }
                flip = !flip;
                j++;
            }   


        }  

How can i call two Slave select for this such that the data in SDRAM should be transferred to these two slaves alternatively one after the other?Lets consider the Data stored in SDRAM as A1A2A3A4A5 etc. so A1 A3 A5 ... is one set of data which should be transferred to my odd slave select and A2 A4 A6... is even set of data to other slave.

1

There are 1 answers

4
UncleO On

As Lundin says, you need to decide how to connect the slaves to your controller. The 128A1 has a few options.

  1. Use the same MISO, MOSI, and SCK lines to run to the slaves. Then use two different pins on the controller to connect to the enable pins on the slaves. Enable one device at a time and send the data over the same bus.
  2. The 128A1 has four separate SPI ports. Connect each slave to a different port using separate buses. Alternate sending between the ports.
  3. You can use the SPI feature of the USART on the microcontroller.

I suggest option 1 or 2. Once you have connected the slaves, the programming will be very similar to what you already have.