View previous topic :: View next topic |
Author |
Message |
JerryR
Joined: 07 Feb 2008 Posts: 167
|
Do spi_xfer and SPI_read/write play well with each other? |
Posted: Thu Dec 15, 2016 8:31 am |
|
|
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
|
|
Posted: Thu Dec 15, 2016 11:52 am |
|
|
"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
|
|
Posted: Thu Dec 15, 2016 12:20 pm |
|
|
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
|
|
Posted: Thu Dec 15, 2016 1:15 pm |
|
|
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
|
|
Posted: Thu Dec 15, 2016 1:20 pm |
|
|
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
|
|
Posted: Fri Feb 17, 2017 3:45 am |
|
|
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
|
|
Posted: Fri Feb 17, 2017 5:23 am |
|
|
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. |
|
|
|