-3

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.

Sijo John
  • 1
  • 4
  • 1
    Can you please mention what microcontroller you are using? There are 100's of different AVRs. – John M Jun 09 '15 at 11:31
  • 1
    The question isn't clear. Are these slaves on the same SPI bus? If so, how do you mux between them? It appears you only have one slave select pin in your code. Or is this a "daisy chain" SPI solution? Please clarify what hardware there is. – Lundin Jun 09 '15 at 11:59
  • possible duplicate of [how to write code for transfer data from internal memory via SPI Master to 2 slave](http://stackoverflow.com/questions/30662682/how-to-write-code-for-transfer-data-from-internal-memory-via-spi-master-to-2-sla) – too honest for this site Jun 09 '15 at 11:59
  • Should be obvious that the assignment to PORTC.OUTCLR is the key. Looks possible, given that PIN4_bm sounds like a bitmask, you just have to use a different value that enables MOSI on more than one device. Actual value depends on hardware of course, you can't leave details like that out of a question like this. – Hans Passant Jun 09 '15 at 12:02
  • @johnny_boy My microcontroller is Atxmega 128 a1. – Sijo John Jun 09 '15 at 12:44
  • @Lundin ya you are correct. currently i am using only one slave. i want to use two slaves and assign the data transfer to both these slaves from SDRAM. – Sijo John Jun 09 '15 at 12:48
  • 1
    @SijoJohn Read my previous comment again. There are at least 3 different ways to connect the slaves to the SPI bus, if you don't tell us how MOSI, SS and clock are connected to them and how you plan to mux in between them, nobody can answer. Or if you don't know how to connect them and if that is the actual question here, you need ask on http://electronics.stackexchange.com/ instead. – Lundin Jun 09 '15 at 12:54
  • @Lundin I want to use the slaves on same SPI bus in Port C. The data stored in SDRAM is two different set of data. What i mean is, i want to call the even bits which corresponds to one set values and odd bits another. so these two sets has to be send to slaves independently. – Sijo John Jun 10 '15 at 10:26

1 Answers1

1

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.

UncleO
  • 8,299
  • 21
  • 29
  • yes you are correct, I want to use the slaves on same SPI bus in Port C. The data stored in SDRAM is two different set of data. What i mean is, i want to call the even bits which corresponds to one set values and odd bits another. so these two sets has to be send to slaves independently. – Sijo John Jun 10 '15 at 10:29
  • Use two `EN` lines on your bus, one to each device. In your loop, enable one device on the odd bytes, and the other on the even bytes. – UncleO Jun 10 '15 at 16:10
  • do you me to enable two slave select by bit masking as in above code like PORTC.OUTCLR = PIN4_bm ? If so how to call even and odd bits from SDRAM to Selected slaves. – Sijo John Jun 10 '15 at 22:15
  • Is it possible to split the SPIC.DATA into SPIC.DATA % 2 = =0 for even and else odd transfer these files to the two slave selects? Otherwise is it possible to do the same with defined function variable ? – Sijo John Jun 15 '15 at 17:01