CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Do spi_xfer and SPI_read/write play well with each other?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
JerryR



Joined: 07 Feb 2008
Posts: 167

View user's profile Send private message

Do spi_xfer and SPI_read/write play well with each other?
PostPosted: Thu Dec 15, 2016 8:31 am     Reply with quote

I have a project that is attempting to use both SPI_xfer AND SPI_read/write commands with their own setup_spi and #use spi. They don't appear to work together. Should they?

Thanks group
jeremiah



Joined: 20 Jul 2010
Posts: 1345

View user's profile Send private message

PostPosted: Thu Dec 15, 2016 11:52 am     Reply with quote

"Should they" is more of a philosophical question. They aren't designed to work together at all. spi_write() and spi_read() are intended to only work with designs that use the setup_spi() method to configure the SPI. spi_xfer() is used for both reads and writes and is intended to only work with designs that use the #use spi() directive. Generally you pick one or the other but do not mix them.
JerryR



Joined: 07 Feb 2008
Posts: 167

View user's profile Send private message

PostPosted: Thu Dec 15, 2016 12:20 pm     Reply with quote

jeremiah:

Thanks for your reply and interest in my question. OK, that's what I thought. I'll have to modify my code to use only one or the other SPI communications method.

Many thanks!
Ttelmah



Joined: 11 Mar 2010
Posts: 19499

View user's profile Send private message

PostPosted: Thu Dec 15, 2016 1:15 pm     Reply with quote

The key is if you look at the manual, #use spi, only refers to spi_xfer. spi_read/write, both only refer to setup_spi.

The older method only offered setup_spi, and only supported hardware SPI.

The newer method is #use, which supports a lot more options with spi_xfer, including multi byte support, streams, and hardware/software.

There shouldn't be any problem converting code that uses spi_read/write to spi_xfer. A search and replace should be able to change the code in a few seconds.
JerryR



Joined: 07 Feb 2008
Posts: 167

View user's profile Send private message

PostPosted: Thu Dec 15, 2016 1:20 pm     Reply with quote

Ttelmah:

Yes, already doing the search and replace dance. Had a lot of code using both methods, Using hardware SPI.

Thanks and best regards
oxo



Joined: 13 Nov 2012
Posts: 219
Location: France

View user's profile Send private message

PostPosted: Fri Feb 17, 2017 3:45 am     Reply with quote

The help file isn't clear on how to do multibyte transfers using spi_xfer.

It doesn't look like I can pass an array of 8 bytes to it. Presumably the way to do this is with 8 x calls to spi_xfer.
Ttelmah



Joined: 11 Mar 2010
Posts: 19499

View user's profile Send private message

PostPosted: Fri Feb 17, 2017 5:23 am     Reply with quote

Why would you expect it to be able to access an array?.
Functions that do this, need pointers rather than simple variables.
spi_xfer can do 4 bytes at a time if you work using int32's.

Just create a wrapper function, but remember you are then also going to have to handle the returns if you want to read as well.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group