• AVR Freaks

using 2 SPI channels quicker then 1?

Author
vespine
Starting Member
  • Total Posts : 55
  • Reward points : 0
  • Joined: 2009/05/13 01:24:20
  • Location: 0
  • Status: offline
2010/05/31 05:54:41 (permalink)
0

using 2 SPI channels quicker then 1?

This is probably a stupid question so i apologize in advance, it's probably very obvious but I'm not certain, hopefully someone can give me a quick answer.

Say you send some data with one SPI module, would it take half as long to send half the data with one SPI module and send the other half with the 2nd SPI module? Or does it take just as long?
Don't worry about the receiving end, the receivers can be either series or parallel; series at the moment and i'm wondering if putting them parallel is worth it.
I'm talking about a pic24 specifically if that makes a difference.
Also without using DMA (the data I'm sending doesn't fit in DMA).

Thanks for your time.
#1

10 Replies Related Threads

    vespine
    Starting Member
    • Total Posts : 55
    • Reward points : 0
    • Joined: 2009/05/13 01:24:20
    • Location: 0
    • Status: offline
    RE: using 2 SPI channels quicker then 1? 2010/06/01 01:42:20 (permalink)
    0
    what if i put it like this:

    i want to shift data_array(0,1,2,3,4,5,6,7)

    the way i have it now is

    for (x=0; x<8; x++)
    {
    -wait for previous transfer to complete-
    SPI1BUF=data_array(x);
    }

    would it be appreciably quicker to do this
    for (x=0; x<4; x++)
    {
    -wait for previous transfer to complete-
    SPI0BUF=data_array(x);
    SPI1BUF=data_array(x+4);
    }


    Ignore my syntax, just the process flow.
    Essentially i need to know if spi1buf transfer will start before spi0buf transfer is finished.
    My guess is yes, that both should run at the same time, maybe not halving the transfer time, but taking a decent chunk out of it.
    Can anyone give me more then a "guess"? :) thanks.
    #2
    MarkT
    Super Member
    • Total Posts : 650
    • Reward points : 0
    • Joined: 2008/12/10 14:18:25
    • Location: Australia
    • Status: offline
    RE: using 2 SPI channels quicker then 1? 2010/06/01 16:02:00 (permalink)
    0
    You are correct; assuming your SSP module(s) are set up correctly, as soon as a byte is written to the SPI buffer the hardware SPI engine takes over the transaction.  The MCU can continue to execute code (including firing another byte via another SSP module) while any SPI transaction(s) take place.

    non illegitimi carborundorum
    #3
    vespine
    Starting Member
    • Total Posts : 55
    • Reward points : 0
    • Joined: 2009/05/13 01:24:20
    • Location: 0
    • Status: offline
    RE: using 2 SPI channels quicker then 1? 2010/06/01 17:43:00 (permalink)
    0
    Thanks heaps. I'm not much of a programmer so i'd waste a lot of time if I went to all the effort to rewire the code, just to realise it wasn't any better. This has given me some renewed hope in my project.  :) Cheers.


    8x8x8 LED Cube www.vespine.com
    #4
    MarkT
    Super Member
    • Total Posts : 650
    • Reward points : 0
    • Joined: 2008/12/10 14:18:25
    • Location: Australia
    • Status: offline
    RE: using 2 SPI channels quicker then 1? 2010/06/01 18:28:22 (permalink)
    0
    Note that I didn't say that I thought it was a good idea :)

    non illegitimi carborundorum
    #5
    Aussie Susan
    Super Member
    • Total Posts : 3810
    • Reward points : 0
    • Joined: 2008/08/18 22:20:40
    • Location: Melbourne, Australia
    • Status: offline
    RE: using 2 SPI channels quicker then 1? 2010/06/01 19:38:01 (permalink)
    0
    What is on the receiving end of the SPI transfers?

    If it is a single device then it had better have 2 SPI interfaces as well and "know" how to interleave the received bytes (as necessary).

    If there are 2 devices, each with an SPI interface, then you would need to send the right bytes out to each device.

    Remember that the "S" in SPI stands for "Serial"

    Susan
    #6
    vespine
    Starting Member
    • Total Posts : 55
    • Reward points : 0
    • Joined: 2009/05/13 01:24:20
    • Location: 0
    • Status: offline
    RE: using 2 SPI channels quicker then 1? 2010/06/01 20:49:20 (permalink)
    0
    On the receiving end I have 12 devices (tlc5940 LED drivers) all hooked up in series. Currently the PIC is shifting out ''12devices x 16channels x 12bits (per channel) data'' = 2304 bits at about 50Hz. But it's taking too long and subsequently the "on" period, when data is not being shifted and the LEDs are actually lit, is very short and my LEDs appear too dim.

    So instead, I plan to split the TLCs into two groups of 6, in which case each SPI module will only need to shift 1152 bits per "send", hopefully speeding up that step of the process and consequently allowing me to have a longer "on" time between transfers.

    It'll take me a while to work out all the details but I think have the basic idea of how to do it. Thanks for your help.

    If anyone can see any flaws with my reasoning, or has other suggestions, please feel free to let me know.

    I've already investigated using multiple PICs or ping ponging DMA channels and a few other similar ideas, however they're all beyond what i'm currently capable of programming wise.

    #7
    vespine
    Starting Member
    • Total Posts : 55
    • Reward points : 0
    • Joined: 2009/05/13 01:24:20
    • Location: 0
    • Status: offline
    RE: using 2 SPI channels quicker then 1? 2010/06/02 03:18:55 (permalink)
    0
    can someone give me a little hand with some of the code? I'm still really hopeless with pointers..

    so i started with this, since my 12 bit "values" are actually stored in 16 bit array elements.

    static inline void shiftRow(unsigned char row) //4 *12bit TLC values sent in 3 x 16 bit SPI sends
    {
    int *p = display_array[row];
    int * const end = p + NUM_TLCS * 16;
    while (p < end)
    {
    unsigned int a = *p++;//pull out 4 array elements into int a,b,c and d
    unsigned int b = *p++;
    unsigned int c = *p++;
    unsigned int d = *p++;

    shift16((a << 4) | (b >> 8)); //pack and send only the 1st 12 bits of those elements into 3 * 16 bit SPI shifts
    shift16((b << 8) | (c >> 4));
    shift16((c << 12) | d);
    }//while
    }//shiftROW


    so, the part i'm stuck on is i want to do 2 sends; one from the start to the middle of the array, and one from the middle to the end.
    i make the "loop" half the length by making it int * const end = p + (NUM_TLCS * 16)/2;

    Now how do i point to the middle of the array without changing the value of p?


    unsigned int a0 = //start from the middle point, something like *p + (NUM_TLCS * 16)/2 ?
    unsigned int a1 = *p++; //start from the 1st element and increment p

    unsigned int b0 = //p is now incremented so same thing as line 1
    unsigned int b1 = *p++;

    unsigned int c0 =
    unsigned int c1 = *p++;

    unsigned int d0 =
    unsigned int d1 = *p++;


    then i'll just pack and send the int0 values using spi0 and the int1 values using spi1...
    post edited by vespine - 2010/06/02 04:58:58
    #8
    MarkT
    Super Member
    • Total Posts : 650
    • Reward points : 0
    • Joined: 2008/12/10 14:18:25
    • Location: Australia
    • Status: offline
    RE: using 2 SPI channels quicker then 1? 2010/06/02 17:14:11 (permalink)
    0
    Now that you've explained what you're doing, I think I agree with your 2-channel SPI solution.
     

    unsigned int a0 = *p;
    unsigned int a1 = *(p++ + (NUM_TLCS * 8));
     
    unsigned int b0 = *p;
    unsigned int b1 = *(p++ + (NUM_TLCS * 8));
     
    etc

     
    Make sure your offset is calculated correctly, i.e. allows for 2 bytes per TLC, not one.  The pointer calculation may be too complex for the compiler to catch it.

    non illegitimi carborundorum
    #9
    vespine
    Starting Member
    • Total Posts : 55
    • Reward points : 0
    • Joined: 2009/05/13 01:24:20
    • Location: 0
    • Status: offline
    RE: using 2 SPI channels quicker then 1? 2010/06/02 17:30:43 (permalink)
    0
    Thanks heaps! I was pretty close, didn't realize you could write it like this *(p++ + stuff) , that's great, thanks for taking the time to answer.

    #10
    MarkT
    Super Member
    • Total Posts : 650
    • Reward points : 0
    • Joined: 2008/12/10 14:18:25
    • Location: Australia
    • Status: offline
    RE: using 2 SPI channels quicker then 1? 2010/06/02 21:45:32 (permalink)
    0
    I didn't mind spending a few minutes, your solution amuses me Smile
     
    If you're going to be doing a bit of C programming, read up on pointers and their syntax - the time will not be wasted.

    non illegitimi carborundorum
    #11
    Jump to:
    © 2021 APG vNext Commercial Version 4.5