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

5.125 / #use spi

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



Joined: 24 Jun 2004
Posts: 1946

View user's profile Send private message

5.125 / #use spi
PostPosted: Tue Nov 17, 2026 7:41 am     Reply with quote

18F56Q43 - SPI peripherals. I'm curious if anyone knows the proper keyword to use in the #use spi directive to tell the compiler that you just want a TX only implementation or a RX only implementation.

As it is the compiler will properly set up the peripheral but it always enables both TX and RX. I cannot find in the help file any mention of a keyword(s) that would encourage the compiler to use one or the other.

I can easily enough get my way round this by setting the appropriate registers myself but was curious if there's some sort of magic handshake I'm not privy to?
Ttelmah



Joined: 11 Mar 2010
Posts: 20156

View user's profile Send private message

PostPosted: Wed Nov 18, 2026 5:31 am     Reply with quote

SPI is normally always a bi-directional interface.
How you do this depends a little on what your chip allows with PPS.

On some chips:
All you do is set the SPI up with with PPS and both SDO and SDI
implemented. Use a pin that will not matter at the moment of boot for
the SDI pin. Then at the start of your code use an inline PPS command to
say the SDI is connected to NULL In fact you can simply leave the SDI
connected to another pin that you use as an input. It'll just read this pin
and get garbage. This is usually the easiest route.
On other chips they will accept a pin as both input and output for PPS, and
all you do is setup the PPS sop the same pin is used for both SDO and SDI.
That way the SDI will read what is sent.

I'd suspect being a PIC18, you will need to use the former approach. It
is normal only the PIC24's and on that support using the single pin as
both input and output.
asmallri



Joined: 12 Aug 2004
Posts: 1679
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

Re: 5.125 / #use spi
PostPosted: Mon Nov 23, 2026 3:25 am     Reply with quote

newguy wrote:
18F56Q43 - SPI peripherals. I'm curious if anyone knows the proper keyword to use in the #use spi directive to tell the compiler that you just want a TX only implementation or a RX only implementation.

As it is the compiler will properly set up the peripheral but it always enables both TX and RX. I cannot find in the help file any mention of a keyword(s) that would encourage the compiler to use one or the other.

I can easily enough get my way round this by setting the appropriate registers myself but was curious if there's some sort of magic handshake I'm not privy to?


This specific PIC supports the PPS and does allow a single PIN to be used for inout and output but you have to handle the direction change.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
newguy



Joined: 24 Jun 2004
Posts: 1946

View user's profile Send private message

PostPosted: Mon Nov 23, 2026 3:57 pm     Reply with quote

Thank you for the input. I'm writing code now but I'm optimistically 3 weeks away from having HW in hand to test; pessimistically 2+ months.

What I've done is to set up the #use spi directives with the NOINIT option, then manually set the registers myself. In code I've been using spi_transfer(). The disassembly looks okay but of course I need to test with real HW.

The project is pretty straightforward: PIC interfaces to a master controller and in turn probes a delta-sigma ADC and a DAC. The interface back to the master controller is a write only SPI interface for the DAC and a read only SPI interface for the ADC. The interface is 'set in stone' and cannot be changed, so my hands are tied, so to speak.
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