DSPRelated.com
Forums

C6727 SPI Delays

Started by alva...@gmail.com April 13, 2011
Hi,

I´m new in DSP programming. I´m trying to connect a C6727 DSP (master) with a CC2430EM transceiver (slave) through SPI in 4-lines with CS mode, on a custom board. With a very simple code that just sets the SPI registers and make a continuous transfer loop, the communication looks good on the scope. However, there is a delay between transfers of 200ms. I´m not using the WDELAY field of the SPIDAT1 register (spru718), because of the errata commented in sprz232f, and no other delays are used.

So, any suggestions to have a smaller delay between transfers?

Another question regarding this issue is that I am sending one byte each time I write SPIDAT0 register, but I do not know how to send several bytes together, something like a byte stream.

My setup: CCS Version: 4.1.0.02006; SD XDS510USB JTAG emulator.

thanks in advance!

_____________________________________
Alvaro-

> I'm new in DSP programming. I'm trying to connect a
> C6727 DSP (master) with a CC2430EM transceiver (slave)
> through SPI in 4-lines with CS mode, on a custom board.
> With a very simple code that just sets the SPI
> registers and make a continuous transfer loop, the
> communication looks good on the scope. However, there
> is a delay between transfers of 200ms. I'm not using
> the WDELAY field of the SPIDAT1 register (spru718),
> because of the errata commented in sprz232f, and no
> other delays are used.
>
> So, any suggestions to have a smaller delay between
> transfers?
>
> Another question regarding this issue is that I am
> sending one byte each time I write SPIDAT0 register,
> but I do not know how to send several bytes together,
> something like a byte stream.
>
> My setup: CCS Version: 4.1.0.02006; SD XDS510USB
> JTAG emulator.

Have you done a delay "breakdown" to determine separate components? I.e. how much due to software, how much due to
SPI circuitry, etc?

-when you write a byte to SPIDAT0, how do you
know when to write another byte? Are you
polling and if so how long does this take?

-if you set an independent GPIO output at the
moment you write SPIDAT0, then on the scope
how long after the GPIO do you see SPI bits
going out?

-Jeff

_____________________________________
alvaro,

A few questions to clarify your setup..

are you running the BIOS?

What is your write loop source code?

What is your clock rate?

Is the code transferring continuously or waiting for the byte echo before
writing the next byte

Is the next byte being written ahead of time, so the clocking in of the echo is
clocking out the next byte or waiting for the next byte to be completely
received before writing the next byte?

Is the code making use of the 'double buffer' capabilities or writing direct to
the shift register?
R. Williams

---------- Original Message -----------
From: a...@gmail.com
To: c...
Sent: Wed, 13 Apr 2011 06:02:14 -0400
Subject: [c6x] C6727 SPI Delays

> Hi,
>
> I´m new in DSP programming. I´m trying to connect a C6727 DSP
> (master) with a CC2430EM transceiver (slave) through SPI in 4-lines
> with CS mode, on a custom board. With a very simple code that just
> sets the SPI registers and make a continuous transfer loop, the
> communication looks good on the scope. However, there is a delay
> between transfers of 200ms. I´m not using the WDELAY field of the
> SPIDAT1 register (spru718), because of the errata commented in
> sprz232f, and no other delays are used.
>
> So, any suggestions to have a smaller delay between transfers?
>
> Another question regarding this issue is that I am sending one byte
> each time I write SPIDAT0 register, but I do not know how to send
> several bytes together, something like a byte stream.
>
> My setup: CCS Version: 4.1.0.02006; SD XDS510USB JTAG emulator.
>
> thanks in advance!
>
>
>
> _____________________________________

_____________________________________
Hi again,

I will try to answer your questions...

1) I am using polling, and if a I set a GPIO pin when I write SPIDAT0, there is no delay between GPIO is set and SPI bits are out.
2) BIOS is not running.
3) I am using an external 24MHz clock, and due to the SPI prescale I have a bit transfer rate of 48KHz; however PLL is not configured.
4) I wait until RXINTFLAG (SPIFLG) is set to write SPIDAT0 again (this flag is set when a word is received and copied into the buffer register). Code is writing directly to the shift register.

I hope code will clarify my explanations,
-

// Example SPI Code using polling DSP=Master

#include
#include "define.h"

void main()
{

volatile unsigned int * spi1_ptr = (unsigned int *) 0x48000000;
unsigned int i=0,flg1=0,tx_master,rx_master;

// SPI registers
/* 1. Take the SPI1 out of reset */
spi1_ptr[SPIGCR0]=0x00;
spi1_ptr[SPIGCR0]=0x01;
/* 2. Configure SPI1 master */
spi1_ptr[SPIGCR1]=0x03;
/* 3. Configure SPI1 for 4-pin mode with CS */
spi1_ptr[SPIPC0]=0x0E01;
/* 4. Chose SPI1 SPIFMT1 */
spi1_ptr[SPIDAT1]=0x01000000;
/* 5. Configure SPI1 for SHIFTDIR=0,POLARITY=1,PHASE=0,CHARLEN=8 */
// Prescale%5,BRG.8KHz
spi1_ptr[SPIFMT1]=0x0002FF08;
/* 7. Configure SPI1 for polling */
spi1_ptr[SPIINT0]=0x00;
/* 8. Enable SPI1 communication */
spi1_ptr[SPIGCR1]|=0x01000003;

while(1){
for(i=1;i<101;++i){

spi1_ptr[SPIDAT0]=(unsigned int)i;
tx_master = spi1_ptr[SPIDAT0]&0xFFFF;

while(1){
flg1=spi1_ptr[SPIFLG];
if(flg1&0x100)
break;
else if(flg1){
printf("Unknown slave error\n");
}
}

rx_master = spi1_ptr[SPIBUF]&0xFFFF;
flg1=0x0000; // clear the spi flag

}
}
}

--

your help is much appreciated.

Best regards,
Alvaro

Hi,
>
>I´m new in DSP programming. I´m trying to connect a C6727 DSP (master) with a CC2430EM transceiver (slave) through SPI in 4-lines with CS mode, on a custom board. With a very simple code that just sets the SPI registers and make a continuous transfer loop, the communication looks good on the scope. However, there is a delay between transfers of 200ms. I´m not using the WDELAY field of the SPIDAT1 register (spru718), because of the errata commented in sprz232f, and no other delays are used.
>
>So, any suggestions to have a smaller delay between transfers?
>
>Another question regarding this issue is that I am sending one byte each time I write SPIDAT0 register, but I do not know how to send several bytes together, something like a byte stream.
>
>My setup: CCS Version: 4.1.0.02006; SD XDS510USB JTAG emulator.
>
>thanks in advance!
>
>_____________________________________

_____________________________________
Alvaro-

> I will try to answer your questions...
>
> 1) I am using polling, and if a I set a GPIO pin when I
> write SPIDAT0, there is no delay between GPIO is set and
> SPI bits are out.
> 2) BIOS is not running.
> 3) I am using an external 24MHz clock, and due to the
> SPI prescale I have a bit transfer rate of 48KHz;
> however PLL is not configured.
> 4) I wait until RXINTFLAG (SPIFLG) is set to write
> SPIDAT0 again (this flag is set when a word is received
> and copied into the buffer register). Code is writing
> directly to the shift register.

Ok, it seems what you're saying is that you:

-wait for SPIFLG

-write SPIDAT0, write a GPIO

-immediately see bit transfers on the dig scope

So where is the 200 msec delay? When you're polling?

-Jeff

> I hope code will clarify my explanations,
> -
>
> // Example SPI Code using polling DSP=Master
>
> #include
> #include "define.h"
>
> void main()
> {
>
> volatile unsigned int * spi1_ptr = (unsigned int *) 0x48000000;
> unsigned int i=0,flg1=0,tx_master,rx_master;
>
> // SPI registers
> /* 1. Take the SPI1 out of reset */
> spi1_ptr[SPIGCR0]=0x00;
> spi1_ptr[SPIGCR0]=0x01;
> /* 2. Configure SPI1 master */
> spi1_ptr[SPIGCR1]=0x03;
> /* 3. Configure SPI1 for 4-pin mode with CS */
> spi1_ptr[SPIPC0]=0x0E01;
> /* 4. Chose SPI1 SPIFMT1 */
> spi1_ptr[SPIDAT1]=0x01000000;
> /* 5. Configure SPI1 for SHIFTDIR=0,POLARITY=1,PHASE=0,CHARLEN=8 */
> // Prescale%5,BRG.8KHz
> spi1_ptr[SPIFMT1]=0x0002FF08;
> /* 7. Configure SPI1 for polling */
> spi1_ptr[SPIINT0]=0x00;
> /* 8. Enable SPI1 communication */
> spi1_ptr[SPIGCR1]|=0x01000003;
>
> while(1){
> for(i=1;i<101;++i){
>
> spi1_ptr[SPIDAT0]=(unsigned int)i;
> tx_master = spi1_ptr[SPIDAT0]&0xFFFF;
>
> while(1){
> flg1=spi1_ptr[SPIFLG];
> if(flg1&0x100)
> break;
> else if(flg1){
> printf("Unknown slave error\n");
> }
> }
>
> rx_master = spi1_ptr[SPIBUF]&0xFFFF;
> flg1=0x0000; // clear the spi flag
>
> }
> }
> }
>
> --
>
> your help is much appreciated.
>
> Best regards,
> Alvaro
>
> Hi,
>>
>>I´m new in DSP programming. I´m trying to connect a C6727 DSP (master) with a CC2430EM transceiver (slave) through
>> SPI in 4-lines with CS mode, on a custom board. With a very simple code that just sets the SPI registers and make a
>> continuous transfer loop, the communication looks good on the scope. However, there is a delay between transfers of
>> 200ms. I´m not using the WDELAY field of the SPIDAT1 register (spru718), because of the errata commented in
>> sprz232f, and no other delays are used.
>>
>>So, any suggestions to have a smaller delay between transfers?
>>
>>Another question regarding this issue is that I am sending one byte each time I write SPIDAT0 register, but I do not
>> know how to send several bytes together, something like a byte stream.
>>
>>My setup: CCS Version: 4.1.0.02006; SD XDS510USB JTAG emulator.
>>
>>thanks in advance!

_____________________________________
alvaro,

you might want to read SPRS268E.pdf and SPRU733A.pdf and SPRU718.pdf
which are a free download at ti.com

Especially read the spru718 document as it has all the details about the SPI
interface.

for a performance boost, I would suggest keeping the device enabled and making
use of the SPI DMA capabilities.

R. Williams

---------- Original Message -----------
From: a...@gmail.com
To: c...
Sent: Fri, 15 Apr 2011 11:56:21 -0400
Subject: [c6x] Re: C6727 SPI Delays

> Hi again,
>
> I will try to answer your questions...
>
> 1) I am using polling, and if a I set a GPIO pin when I write SPIDAT0,
> there is no delay between GPIO is set and SPI bits are out. 2) BIOS is
> not running. 3) I am using an external 24MHz clock, and due to the SPI
> prescale I have a bit transfer rate of 48KHz; however PLL is not configured.
> 4) I wait until RXINTFLAG (SPIFLG) is set to write SPIDAT0 again (this
> flag is set when a word is received and copied into the buffer
> register). Code is writing directly to the shift register.
>
> I hope code will clarify my explanations,
> -
>
> // Example SPI Code using polling DSP=Master
>
> #include
> #include "define.h"
>
> void main()
> {
>
> volatile unsigned int * spi1_ptr = (unsigned int *) 0x48000000;
> unsigned int i=0,flg1=0,tx_master,rx_master;
>
> // SPI registers
> /* 1. Take the SPI1 out of reset */
> spi1_ptr[SPIGCR0]=0x00;
> spi1_ptr[SPIGCR0]=0x01;
> /* 2. Configure SPI1 master */
> spi1_ptr[SPIGCR1]=0x03;
> /* 3. Configure SPI1 for 4-pin mode with CS */
> spi1_ptr[SPIPC0]=0x0E01;
> /* 4. Chose SPI1 SPIFMT1 */
> spi1_ptr[SPIDAT1]=0x01000000;
> /* 5. Configure SPI1 for SHIFTDIR=0,POLARITY=1,PHASE=0,CHARLEN=8 */
> // Prescale%5,BRG.8KHz
> spi1_ptr[SPIFMT1]=0x0002FF08;
> /* 7. Configure SPI1 for polling */
> spi1_ptr[SPIINT0]=0x00;
> /* 8. Enable SPI1 communication */
> spi1_ptr[SPIGCR1]|=0x01000003;
>
> while(1){
> for(i=1;i<101;++i){
>
> spi1_ptr[SPIDAT0]=(unsigned int)i;
> tx_master = spi1_ptr[SPIDAT0]&0xFFFF;
>
> while(1){
> flg1=spi1_ptr[SPIFLG];
> if(flg1&0x100)
> break;
> else if(flg1){
> printf("Unknown slave error\n");
> }
> }
>
> rx_master = spi1_ptr[SPIBUF]&0xFFFF;
> flg1=0x0000; // clear the spi flag
>
> }
> }
> }
>
> --
>
> your help is much appreciated.
>
> Best regards,
> Alvaro
>
> Hi,
> >
> >I´m new in DSP programming. I´m trying to connect a C6727 DSP (master) with
a CC2430EM transceiver (slave) through SPI in 4-lines with CS mode, on a custom
board. With a very simple code that just sets the SPI registers and make a
continuous transfer loop, the communication looks good on the scope. However,
there is a delay between transfers of 200ms. I´m not using the WDELAY field of
the SPIDAT1 register (spru718), because of the errata commented in sprz232f, and
no other delays are used.
> >
> >So, any suggestions to have a smaller delay between transfers?
> >
> >Another question regarding this issue is that I am sending one byte each time
I write SPIDAT0 register, but I do not know how to send several bytes together,
something like a byte stream.
> >
> >My setup: CCS Version: 4.1.0.02006; SD XDS510USB JTAG emulator.
> >
> >thanks in advance!
> >
> >_____________________________________
> >
> >
>
> _____________________________________

_____________________________________
alvaro,

You can cut the overall transfer time by eliminating 1/2 of the inter byte
delays by transferring 16 bits at a time rather than only 8 bits.

R. Williams
---------- Original Message -----------
From: a...@gmail.com
To: c...
Sent: Fri, 15 Apr 2011 11:56:21 -0400
Subject: [c6x] Re: C6727 SPI Delays

> Hi again,
>
> I will try to answer your questions...
>
> 1) I am using polling, and if a I set a GPIO pin when I write SPIDAT0,
> there is no delay between GPIO is set and SPI bits are out. 2) BIOS is
> not running. 3) I am using an external 24MHz clock, and due to the SPI
> prescale I have a bit transfer rate of 48KHz; however PLL is not configured.
> 4) I wait until RXINTFLAG (SPIFLG) is set to write SPIDAT0 again (this
> flag is set when a word is received and copied into the buffer
> register). Code is writing directly to the shift register.
>
> I hope code will clarify my explanations,
> -
>
> // Example SPI Code using polling DSP=Master
>
> #include
> #include "define.h"
>
> void main()
> {
>
> volatile unsigned int * spi1_ptr = (unsigned int *) 0x48000000;
> unsigned int i=0,flg1=0,tx_master,rx_master;
>
> // SPI registers
> /* 1. Take the SPI1 out of reset */
> spi1_ptr[SPIGCR0]=0x00;
> spi1_ptr[SPIGCR0]=0x01;
> /* 2. Configure SPI1 master */
> spi1_ptr[SPIGCR1]=0x03;
> /* 3. Configure SPI1 for 4-pin mode with CS */
> spi1_ptr[SPIPC0]=0x0E01;
> /* 4. Chose SPI1 SPIFMT1 */
> spi1_ptr[SPIDAT1]=0x01000000;
> /* 5. Configure SPI1 for SHIFTDIR=0,POLARITY=1,PHASE=0,CHARLEN=8 */
> // Prescale%5,BRG.8KHz
> spi1_ptr[SPIFMT1]=0x0002FF08;
> /* 7. Configure SPI1 for polling */
> spi1_ptr[SPIINT0]=0x00;
> /* 8. Enable SPI1 communication */
> spi1_ptr[SPIGCR1]|=0x01000003;
>
> while(1){
> for(i=1;i<101;++i){
>
> spi1_ptr[SPIDAT0]=(unsigned int)i;
> tx_master = spi1_ptr[SPIDAT0]&0xFFFF;
>
> while(1){
> flg1=spi1_ptr[SPIFLG];
> if(flg1&0x100)
> break;
> else if(flg1){
> printf("Unknown slave error\n");
> }
> }
>
> rx_master = spi1_ptr[SPIBUF]&0xFFFF;
> flg1=0x0000; // clear the spi flag
>
> }
> }
> }
>
> --
>
> your help is much appreciated.
>
> Best regards,
> Alvaro
>
> Hi,
> >
> >I´m new in DSP programming. I´m trying to connect a C6727 DSP (master) with
a CC2430EM transceiver (slave) through SPI in 4-lines with CS mode, on a custom
board. With a very simple code that just sets the SPI registers and make a
continuous transfer loop, the communication looks good on the scope. However,
there is a delay between transfers of 200ms. I´m not using the WDELAY field of
the SPIDAT1 register (spru718), because of the errata commented in sprz232f, and
no other delays are used.
> >
> >So, any suggestions to have a smaller delay between transfers?
> >
> >Another question regarding this issue is that I am sending one byte each time
I write SPIDAT0 register, but I do not know how to send several bytes together,
something like a byte stream.
> >
> >My setup: CCS Version: 4.1.0.02006; SD XDS510USB JTAG emulator.
> >
> >thanks in advance!
> >
> >_____________________________________
> >
> >
>
> _____________________________________

_____________________________________
alvaro,

the line
tx_master = spi1_ptr[SPIDAT0]&0xFFFF
is invalid because reads of spidat0 always return 0.

the line
flg1=0x0000; // clear the spi flag
has no effect because the code is writing 0x0000 to a local variable and not to
the spibuf register.

Also, the act of reading the spibuf register clears the flags, writes have no
effect.

To assist you, the SPRU718b.pdf file contains a complete/correct example of how
to initialize and poll the SPI peripheral,

The example only transfers one datum.
so you would eliminate the tx/rx datum compare and put the polling portion of
the code into the desired loop.

R. Williams

---------- Original Message -----------
From: a...@gmail.com
To: c...
Sent: Fri, 15 Apr 2011 11:56:21 -0400
Subject: [c6x] Re: C6727 SPI Delays

> Hi again,
>
> I will try to answer your questions...
>
> 1) I am using polling, and if a I set a GPIO pin when I write SPIDAT0,
> there is no delay between GPIO is set and SPI bits are out. 2) BIOS is
> not running. 3) I am using an external 24MHz clock, and due to the SPI
> prescale I have a bit transfer rate of 48KHz; however PLL is not configured.
> 4) I wait until RXINTFLAG (SPIFLG) is set to write SPIDAT0 again (this
> flag is set when a word is received and copied into the buffer
> register). Code is writing directly to the shift register.
>
> I hope code will clarify my explanations,
> -
>
> // Example SPI Code using polling DSP=Master
>
> #include
> #include "define.h"
>
> void main()
> {
>
> volatile unsigned int * spi1_ptr = (unsigned int *) 0x48000000;
> unsigned int i=0,flg1=0,tx_master,rx_master;
>
> // SPI registers
> /* 1. Take the SPI1 out of reset */
> spi1_ptr[SPIGCR0]=0x00;
> spi1_ptr[SPIGCR0]=0x01;
> /* 2. Configure SPI1 master */
> spi1_ptr[SPIGCR1]=0x03;
> /* 3. Configure SPI1 for 4-pin mode with CS */
> spi1_ptr[SPIPC0]=0x0E01;
> /* 4. Chose SPI1 SPIFMT1 */
> spi1_ptr[SPIDAT1]=0x01000000;
> /* 5. Configure SPI1 for SHIFTDIR=0,POLARITY=1,PHASE=0,CHARLEN=8 */
> // Prescale%5,BRG.8KHz
> spi1_ptr[SPIFMT1]=0x0002FF08;
> /* 7. Configure SPI1 for polling */
> spi1_ptr[SPIINT0]=0x00;
> /* 8. Enable SPI1 communication */
> spi1_ptr[SPIGCR1]|=0x01000003;
>
> while(1){
> for(i=1;i<101;++i){
>
> spi1_ptr[SPIDAT0]=(unsigned int)i;
> tx_master = spi1_ptr[SPIDAT0]&0xFFFF;
>
> while(1){
> flg1=spi1_ptr[SPIFLG];
> if(flg1&0x100)
> break;
> else if(flg1){
> printf("Unknown slave error\n");
> }
> }
>
> rx_master = spi1_ptr[SPIBUF]&0xFFFF;
> flg1=0x0000; // clear the spi flag
>
> }
> }
> }
>
> --
>
> your help is much appreciated.
>
> Best regards,
> Alvaro
>
> Hi,
> >
> >I´m new in DSP programming. I´m trying to connect a C6727 DSP (master) with
a CC2430EM transceiver (slave) through SPI in 4-lines with CS mode, on a custom
board. With a very simple code that just sets the SPI registers and make a
continuous transfer loop, the communication looks good on the scope. However,
there is a delay between transfers of 200ms. I´m not using the WDELAY field of
the SPIDAT1 register (spru718), because of the errata commented in sprz232f, and
no other delays are used.
> >
> >So, any suggestions to have a smaller delay between transfers?
> >
> >Another question regarding this issue is that I am sending one byte each time
I write SPIDAT0 register, but I do not know how to send several bytes together,
something like a byte stream.
> >
> >My setup: CCS Version: 4.1.0.02006; SD XDS510USB JTAG emulator.
> >
> >thanks in advance!
> >
> >_____________________________________
> >
> >
>
> _____________________________________

_____________________________________
Hi,

sorry for answer too late, but I was out of my laboratory last week.

Jeff, there are 200ms delay between bits transfer, i.e. there are 8-bit cycles of the SPICLK, and the delay is between the last bit of one cycle and the first bit of the next one.

Richard, I have also think about transferring 16-bits words, but if there is a big delay between words, it will be also too slow for my purposes. The code I posted is based on the spru718 polling example; what do you mean when say "spru718 example only transfer one datum..." ?

Thanks again,
Alvaro

Hi,
>
>I´m new in DSP programming. I´m trying to connect a C6727 DSP (master) with a CC2430EM transceiver (slave) through SPI in 4-lines with CS mode, on a custom board. With a very simple code that just sets the SPI registers and make a continuous transfer loop, the communication looks good on the scope. However, there is a delay between transfers of 200ms. I´m not using the WDELAY field of the SPIDAT1 register (spru718), because of the errata commented in sprz232f, and no other delays are used.
>
>So, any suggestions to have a smaller delay between transfers?
>
>Another question regarding this issue is that I am sending one byte each time I write SPIDAT0 register, but I do not know how to send several bytes together, something like a byte stream.
>
>My setup: CCS Version: 4.1.0.02006; SD XDS510USB JTAG emulator.
>
>thanks in advance!
>
>_____________________________________

_____________________________________
Alvaro-

> sorry for answer too late, but I was out of my
> laboratory last week.
>
> Jeff, there are 200ms delay between bits transfer,
> i.e. there are 8-bit cycles of the SPICLK, and the
> delay is between the last bit of one cycle and the
> first bit of the next one.

Ok, but I had asked you before what happens if you output a GPIO line when your software thinks the transfer is
complete? Did you do that?

My point is you can't just say "there is delay somewhere between transfers", because there are a lot of sub-steps:
software awareness the current transfer is done, software awareness that SPIDAT is ready for more data, software
awareness the next transfer is in progress. So you have to break this down. One way is to use GPIO outputs and a
digital scope. For example you could toggle a GPIO line, or use 3 different lines, etc. It doesn't look to me like
you did anything like that.

-Jeff

> Richard, I have also think about transferring 16-bits words, but if there is a big delay between words, it will be
> also too slow for my purposes. The code I posted is based on the spru718 polling example; what do you mean when say
> "spru718 example only transfer one datum..." ?
>
> Thanks again,
> Alvaro
>
> Hi,
>>
>>I´m new in DSP programming. I´m trying to connect a C6727 DSP (master) with a CC2430EM transceiver (slave) through
>> SPI in 4-lines with CS mode, on a custom board. With a very simple code that just sets the SPI registers and make a
>> continuous transfer loop, the communication looks good on the scope. However, there is a delay between transfers of
>> 200ms. I´m not using the WDELAY field of the SPIDAT1 register (spru718), because of the errata commented in
>> sprz232f, and no other delays are used.
>>
>>So, any suggestions to have a smaller delay between transfers?
>>
>>Another question regarding this issue is that I am sending one byte each time I write SPIDAT0 register, but I do not
>> know how to send several bytes together, something like a byte stream.
>>
>>My setup: CCS Version: 4.1.0.02006; SD XDS510USB JTAG emulator.
>>
>>thanks in advance!

_____________________________________