DSPRelated.com
Forums

mcbsp spi receive

Started by Lucy Jordan October 8, 2002
When I transmit over spi it also seems to be receiving (when i don't
want it to).
Should I transmit whatever I need to. _Then_ enable the receive part
of the mcbsp, then send a "dummy" transmit to get the clocks, then
read DRR, then disable receive, and transmit again...? will this give
me the correct data? as of now, i am getting the wrong data despite
the fact that the data is being correctly output on DR by the ext SPI
device (verified on a scope).



Lucy,
Customarily, when you clock data out on an SPI channel, data is
simultaneously
clocked in to your receive register. You have to determine whether this data
is
useful, or should be ignored. It sounds like in your case, the data should
be ignored. Then, when you want to receive data, you need to transmit dummy
data, then immediately do a couple of reads of the SPI receive register to
flush it
out of any buffered data, and then wait for the real receive dat to come in.
Ususlly this is done with interrupts to avoid wasted CPU cycles in a wait
loop.

All of the above assumes that you are programming the *master* SPI device.

Hope this helps,

Best Regards,
Tony
______________________________
Tony Zampini ()
Director of Engineering
DSP Global Inc.
33 Plan Way, Bldg. #4
Warwick, RI 02886
Tel. 401-737-9900
FAX: 401-739-4197
www.dspglobal.com

----- Original Message -----
From: "Lucy Jordan" <>
To: <>
Sent: Monday, October 07, 2002 10:34 PM
Subject: [c54x] mcbsp spi receive > When I transmit over spi it also seems to be receiving (when i don't
> want it to).
> Should I transmit whatever I need to. _Then_ enable the receive part
> of the mcbsp, then send a "dummy" transmit to get the clocks, then
> read DRR, then disable receive, and transmit again...? will this give
> me the correct data? as of now, i am getting the wrong data despite
> the fact that the data is being correctly output on DR by the ext SPI
> device (verified on a scope). > _____________________________________
> Note: If you do a simple "reply" with your email client, only the author
of this message will receive your answer. You need to do a "reply all" if
you want your answer to be distributed to the entire group.
>
> _____________________________________
> About this discussion group:
>
> To Join: Send an email to
>
> To Post: Send an email to
>
> To Leave: Send an email to
>
> Archives: http://www.yahoogroups.com/group/c54x
>
> Other Groups: http://www.dsprelated.com > ">http://docs.yahoo.com/info/terms/ >





Yes don't enable the receive until you expect data back
from the SPI your clocking out to. Also be sure to clear
the DR beforehand its tripple buffered and may contain old
data.
Phil

--- In c54x@y..., "Lucy Jordan" <screaminglucy@y...> wrote:
> When I transmit over spi it also seems to be receiving (when i
don't
> want it to).
> Should I transmit whatever I need to. _Then_ enable the receive
part
> of the mcbsp, then send a "dummy" transmit to get the clocks, then
> read DRR, then disable receive, and transmit again...? will this
give
> me the correct data? as of now, i am getting the wrong data despite
> the fact that the data is being correctly output on DR by the ext
SPI
> device (verified on a scope).



I'm not concerned with wasting cycles while I poll, so do you think the
following would work?
The dsp is the spi master.

void spi_send ()
{
check xrdy
write data to DXR
wait for rrdy //wait for output data to be shifted out
read DRR //clear rrdy for garbage data
} unsigned char spi_receive()
{
check xrdy
write dummy data to DXR
wait for rrdy //wait for receive to complete
read DRR //this should be correct data?
}

-----Original Message-----
From: Tony Zampini
Sent: Tuesday, October 08, 2002 9:02 AM
To: ; Lucy Jordan
Subject: Re: [c54x] mcbsp spi receive

Lucy,
Customarily, when you clock data out on an SPI channel, data is
simultaneously
clocked in to your receive register. You have to determine whether this
data
is
useful, or should be ignored. It sounds like in your case, the data
should
be ignored. Then, when you want to receive data, you need to transmit
dummy
data, then immediately do a couple of reads of the SPI receive register
to
flush it
out of any buffered data, and then wait for the real receive dat to come
in.
Ususlly this is done with interrupts to avoid wasted CPU cycles in a
wait
loop.

All of the above assumes that you are programming the *master* SPI
device.

Hope this helps,

Best Regards,
Tony
______________________________
Tony Zampini ()
Director of Engineering
DSP Global Inc.
33 Plan Way, Bldg. #4
Warwick, RI 02886
Tel. 401-737-9900
FAX: 401-739-4197
www.dspglobal.com

----- Original Message -----
From: "Lucy Jordan" <>
To: <>
Sent: Monday, October 07, 2002 10:34 PM
Subject: [c54x] mcbsp spi receive > When I transmit over spi it also seems to be receiving (when i don't
> want it to).
> Should I transmit whatever I need to. _Then_ enable the receive part
> of the mcbsp, then send a "dummy" transmit to get the clocks, then
> read DRR, then disable receive, and transmit again...? will this give
> me the correct data? as of now, i am getting the wrong data despite
> the fact that the data is being correctly output on DR by the ext SPI
> device (verified on a scope). > _____________________________________
> Note: If you do a simple "reply" with your email client, only the
author
of this message will receive your answer. You need to do a "reply all"
if
you want your answer to be distributed to the entire group.
>
> _____________________________________
> About this discussion group:
>
> To Join: Send an email to
>
> To Post: Send an email to
>
> To Leave: Send an email to
>
> Archives: http://www.yahoogroups.com/group/c54x
>
> Other Groups: http://www.dsprelated.com > ">http://docs.yahoo.com/info/terms/





Yes, I would just add one thing to your spi_send() function
to insure that no old receive data is sitting in the receive
fifo:

void spi_send ()
{
check xrdy
write data to DXR
-> read DRR
-> read DRR
wait for rrdy //wait for output data to be shifted out
read DRR //clear rrdy for garbage data
}

Tony

----- Original Message -----
From: "Lucy Jordan" <>
To: "'Tony Zampini'" <>
Cc: <>
Sent: Tuesday, October 08, 2002 3:48 PM
Subject: RE: [c54x] mcbsp spi receive >
> I'm not concerned with wasting cycles while I poll, so do you think the
> following would work?
> The dsp is the spi master.
>
> void spi_send ()
> {
> check xrdy
> write data to DXR
> wait for rrdy //wait for output data to be shifted out
> read DRR //clear rrdy for garbage data
> } > unsigned char spi_receive()
> {
> check xrdy
> write dummy data to DXR
> wait for rrdy //wait for receive to complete
> read DRR //this should be correct data?
> }
>
> -----Original Message-----
> From: Tony Zampini
> Sent: Tuesday, October 08, 2002 9:02 AM
> To: ; Lucy Jordan
> Subject: Re: [c54x] mcbsp spi receive
>
> Lucy,
> Customarily, when you clock data out on an SPI channel, data is
> simultaneously
> clocked in to your receive register. You have to determine whether this
> data
> is
> useful, or should be ignored. It sounds like in your case, the data
> should
> be ignored. Then, when you want to receive data, you need to transmit
> dummy
> data, then immediately do a couple of reads of the SPI receive register
> to
> flush it
> out of any buffered data, and then wait for the real receive dat to come
> in.
> Ususlly this is done with interrupts to avoid wasted CPU cycles in a
> wait
> loop.
>
> All of the above assumes that you are programming the *master* SPI
> device.
>
> Hope this helps,
>
> Best Regards,
> Tony
> ______________________________
> Tony Zampini ()
> Director of Engineering
> DSP Global Inc.
> 33 Plan Way, Bldg. #4
> Warwick, RI 02886
> Tel. 401-737-9900
> FAX: 401-739-4197
> www.dspglobal.com
>
> ----- Original Message -----
> From: "Lucy Jordan" <>
> To: <>
> Sent: Monday, October 07, 2002 10:34 PM
> Subject: [c54x] mcbsp spi receive > > When I transmit over spi it also seems to be receiving (when i don't
> > want it to).
> > Should I transmit whatever I need to. _Then_ enable the receive part
> > of the mcbsp, then send a "dummy" transmit to get the clocks, then
> > read DRR, then disable receive, and transmit again...? will this give
> > me the correct data? as of now, i am getting the wrong data despite
> > the fact that the data is being correctly output on DR by the ext SPI
> > device (verified on a scope).
> >
> >
> >
> >
> >
> > _____________________________________
> > Note: If you do a simple "reply" with your email client, only the
> author
> of this message will receive your answer. You need to do a "reply all"
> if
> you want your answer to be distributed to the entire group.
> >
> > _____________________________________
> > About this discussion group:
> >
> > To Join: Send an email to
> >
> > To Post: Send an email to
> >
> > To Leave: Send an email to
> >
> > Archives: http://www.yahoogroups.com/group/c54x
> >
> > Other Groups: http://www.dsprelated.com
> >
> >
> > ">http://docs.yahoo.com/info/terms/
> >
> >
>



Hi Lucy

Looks like that will work.
The only thing I do differnet is disable
the recieve via the RRST in the SPCR1
until I expect data in.

Phil
--- In c54x@y..., "Lucy Jordan" <screaminglucy@y...> wrote:
>
> I'm not concerned with wasting cycles while I poll, so do you think
the
> following would work?
> The dsp is the spi master.
>
> void spi_send ()
> {
> check xrdy
> write data to DXR
> wait for rrdy //wait for output data to be shifted out
> read DRR //clear rrdy for garbage data
> } > unsigned char spi_receive()
> {
> check xrdy
> write dummy data to DXR
> wait for rrdy //wait for receive to complete
> read DRR //this should be correct data?
> }
>
> -----Original Message-----
> From: Tony Zampini
> Sent: Tuesday, October 08, 2002 9:02 AM
> To: c54x@y...; Lucy Jordan
> Subject: Re: [c54x] mcbsp spi receive
>
> Lucy,
> Customarily, when you clock data out on an SPI channel, data is
> simultaneously
> clocked in to your receive register. You have to determine whether
this
> data
> is
> useful, or should be ignored. It sounds like in your case, the data
> should
> be ignored. Then, when you want to receive data, you need to
transmit
> dummy
> data, then immediately do a couple of reads of the SPI receive
register
> to
> flush it
> out of any buffered data, and then wait for the real receive dat to
come
> in.
> Ususlly this is done with interrupts to avoid wasted CPU cycles in a
> wait
> loop.
>
> All of the above assumes that you are programming the *master* SPI
> device.
>
> Hope this helps,
>
> Best Regards,
> Tony
> ______________________________
> Tony Zampini (tony@d...)
> Director of Engineering
> DSP Global Inc.
> 33 Plan Way, Bldg. #4
> Warwick, RI 02886
> Tel. 401-737-9900
> FAX: 401-739-4197
> www.dspglobal.com
>
> ----- Original Message -----
> From: "Lucy Jordan" <screaminglucy@y...>
> To: <c54x@y...>
> Sent: Monday, October 07, 2002 10:34 PM
> Subject: [c54x] mcbsp spi receive > > When I transmit over spi it also seems to be receiving (when i
don't
> > want it to).
> > Should I transmit whatever I need to. _Then_ enable the receive
part
> > of the mcbsp, then send a "dummy" transmit to get the clocks, then
> > read DRR, then disable receive, and transmit again...? will this
give
> > me the correct data? as of now, i am getting the wrong data
despite
> > the fact that the data is being correctly output on DR by the ext
SPI
> > device (verified on a scope).
> >
> >
> >
> >
> >
> > _____________________________________
> > Note: If you do a simple "reply" with your email client, only the
> author
> of this message will receive your answer. You need to do a "reply
all"
> if
> you want your answer to be distributed to the entire group.
> >
> > _____________________________________
> > About this discussion group:
> >
> > To Join: Send an email to c54x-subscribe@y...
> >
> > To Post: Send an email to c54x@y...
> >
> > To Leave: Send an email to c54x-unsubscribe@y...
> >
> > Archives: http://www.yahoogroups.com/group/c54x
> >
> > Other Groups: http://www.dsprelated.com
> >
> >
> > ">http://docs.yahoo.com/info/terms/
> >
> >
> >