 |
 |
View previous topic :: View next topic |
Author |
Message |
SkeeterHawk
Joined: 16 Oct 2010 Posts: 52 Location: Florissant, CO
|
Fundamentals of #use spi versus setup_spi() |
Posted: Tue Apr 08, 2025 2:17 pm |
|
|
It is understood that CCS is moving us programmers toward using the #use spi preprocessor over the "legacy" setup_spi() function, but the documentation is not clear on which function goes with which methodology of using the SPI port and you don't dare use the wrong one because disaster will almost certainly occur. The documentation within "Help" needs help. To make matters more confusing, the "SPI Overview" doesn't even mention the #use spi preprocessor that they actually want you to use.
Just going through the documentation, here are the functions and their assiciations
#use spi
spi_xfer() - Listed as the primary suggested function for R/W in the #use spi documentation. In the most recent compiler version 5.114, this function has issues in Slave mode and should not be used
spi_prewrite() - Not listed anywhere in the documentation, but is used within multiple Example programs within the compiler
spi_init() - This function says that it uses #use spi, but is not used in any of the Example files for SPI. This function appears to do the same thing as the preprocessor by setting the baud rate, so is this already obsolete?
spi_speed() - This function also says that it uses #use spi, but is not used in any of the Example files for SPI. This function appears to do the same thing as the preprocessor by setting the baud rate and clock, so is this already obsolete too?
spi_xfer_in() - Also not listed anywhere in the documentation, but is used within the Example program within the compiler
When #use spi is used and the chip has an SPI Peripheral and not a MSSP:
spi_transfer() - Listed as another suggested function at the bottom of the #use spi documentation
spi_transfer_write() - Listed as another suggested function at the bottom of the #use spi documentation
spi_transfer_read() - Listed as another suggested function at the bottom of the #use spi documentation
spi_transfer_done() - Listed as another suggested function at the bottom of the #use spi documentation
spi_transfer_clear() - Listed as another suggested function at the bottom of the #use spi documentation
setup_spi()
spi_write() - Listed as another suggested function at the bottom of the setup_spi() documentation
spi_read() - Listed as another suggested function at the bottom of the setup_spi() documentation
spi_data_is_in() - Listed as another suggested function at the bottom of the setup_spi() documentation
spi_set_txcnt() - Listed as another suggested function at the bottom of the setup_spi() documentation _________________ Life is too short to only write code in assembly...
Last edited by SkeeterHawk on Sat Apr 12, 2025 12:38 pm; edited 3 times in total |
|
 |
temtronic
Joined: 01 Jul 2010 Posts: 9453 Location: Greensville,Ontario
|
|
Posted: Tue Apr 08, 2025 2:31 pm |
|
|
just a comment , while waiting for SPRING to arrive.....
Since CCS wants everyone to use the 'new' way, perhaps they should remove the 'old' functions ?
This seems 'good' in my head and anyone with 'legacy' programs should be able to 'upgrade' to the newer functions ?
Then again, I still have a Window98SE PC up and running here...... |
|
 |
SkeeterHawk
Joined: 16 Oct 2010 Posts: 52 Location: Florissant, CO
|
|
Posted: Tue Apr 08, 2025 3:02 pm |
|
|
temtronic wrote: | just a comment , while waiting for SPRING to arrive..... |
Where I live, we jump through Spring and wind up in Summer for a few weeks, a week of fall, and back to winter. It is 55F outside right now.
temtronic wrote: | Since CCS wants everyone to use the 'new' way, perhaps they should remove the 'old' functions ? |
I hear you, and at some point they will have to. The buzz on this forum is that they are pretty much not supported and are buggy.
temtronic wrote: | This seems 'good' in my head and anyone with 'legacy' programs should be able to 'upgrade' to the newer functions ? |
Agreed. Sometimes you have to "take that pill".
temtronic wrote: | Then again, I still have a Window98SE PC up and running here...... |
LOL! I have an XP laptop still going here for "emergencies".
I'm interested in what feedback we get on spi_init() and spi_speed(). They seem to have been replaced by functionality within the #use spi preprocessor. _________________ Life is too short to only write code in assembly... |
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 19769
|
|
Posted: Sat Apr 12, 2025 9:36 am |
|
|
There are a couple of other things here.
CCS always retain old functions, so you can still compile 'historical'
programs with the newer compilers.
The spi_transfer functions were added when chips arrived with the
SPI peripheral rather than the MSSP. This peripheral supports block
transfers of a number of bytes. Initially these only worked with these
peripherals. These were also hard to make emulate the older xfer
functions. After a few releases, CCS wrote versions that worked on
both peripherals, and managed to get the reverse emulation working. |
|
 |
SkeeterHawk
Joined: 16 Oct 2010 Posts: 52 Location: Florissant, CO
|
|
Posted: Sat Apr 12, 2025 12:42 pm |
|
|
Ttelmah wrote: | There are a couple of other things here.
CCS always retain old functions, so you can still compile 'historical'
programs with the newer compilers. |
Yes, and we hope that those functions will work with all newer chips in perpetuity (If there was a "Fingers Crossed" emoticon, I would lay that bad boy down right here).
Ttelmah wrote: | The spi_transfer functions were added when chips arrived with the SPI peripheral rather than the MSSP. This peripheral supports block
transfers of a number of bytes. Initially these only worked with these
peripherals. These were also hard to make emulate the older xfer
functions. After a few releases, CCS wrote versions that worked on
both peripherals, and managed to get the reverse emulation working. |
I appreciate the clarification and I updated the original post so someone won't have to read the whole thread to get the gist. Does this sound right now? _________________ Life is too short to only write code in assembly... |
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 19769
|
|
Posted: Sun Apr 13, 2025 1:48 am |
|
|
Not quite.
They now offer spi_transfer on chips using the MSSP. They updated
the function so the emulation is now 'two way'. The older peripheral
can not use the spa_transfer function as well as the newer peripheral,
and they managed to produce an emulation of the standard spi_xfer
on the newer peripheral as well (this is quite hard to do if you look at the
data sheet for this).
There are some interesting 'hidden extras' on the newer function
(this is where a better demo and documentation would help massivly).
If you setup 'enable' in the #use spi, and use spi_transfer, it'll now
operate the enable at the start of the whole transaction, instead of
byte by byte. Undocumented....  |
|
 |
|
|
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
|