| View previous topic :: View next topic |
| Author |
Message |
newguy
Joined: 24 Jun 2004 Posts: 1946
|
| 5.125 / #use spi |
Posted: Tue Nov 17, 2026 7:41 am |
|
|
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
|
|
Posted: Wed Nov 18, 2026 5:31 am |
|
|
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
|
| Re: 5.125 / #use spi |
Posted: Mon Nov 23, 2026 3:25 am |
|
|
| 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
|
|
Posted: Mon Nov 23, 2026 3:57 pm |
|
|
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. |
|
 |
|