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 support@ccsinfo.com

Disabling UART TX output on a PIC with PPS

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



Joined: 25 Aug 2004
Posts: 66

View user's profile Send private message

Disabling UART TX output on a PIC with PPS
PostPosted: Mon Nov 19, 2018 2:38 am     Reply with quote

I've just begun using the PIC18LF27K40 which is the first chip I've used with PPS. In my design I have a wireless module which can be powered off completely. Consequently, it's critical not to back power the module through the TX line (which of course idles high).

Previously, I simply enabled/disabled the UART using setup_uart() which controls SPEN which in turn determines whether the USART module has control of the pin.

From what I observe with PPS, whether the pin is controlled by the USART module is strictly determined by PPS regardless of whether the USART module is enabled by SPEN (which makes sense).

The catch though is that the #use_rs232 directive seems to require that the RX/TX pins already be assigned with #pin_select first (even with noinit). I can subsequently use pin_select() to remove the output for TX, but there will be at least a glitch during reset which I'd prefer to avoid.

The only solution I can see is to have #pin_select set the TX pin to another unused/unimportant pin and then change it later. This is a hack. Is there a better way?

Perhaps the noinit option really should cause the compiler check (on pin_select) to be skipped.

/Ross
Ttelmah



Joined: 11 Mar 2010
Posts: 19217

View user's profile Send private message

PostPosted: Mon Nov 19, 2018 4:05 am     Reply with quote

What you do, is setup select to a pin temporarily.
Then deselect it.

On output devices, the data is stored on a 'pin' basis. This is why there is a
'NULL' selection offered. So:
Code:

#pin_select U1TX=PIN_B1
#pin_select U1RX=PIN_B0
#use RS232(UART1, ERRORS, BAUD=9600)
//setup for boot

//Then in your main:

   //deselect U1TX
   pin_select("NULL", PIN_B1);

This connects PIN_B1 back to the LATxy device (the standard output...).

It is an 'issue', since as you say it would possibly make sense to have NOINIT, skip the check, but this then leaves you with the possibility of having a device enabled, without it's pins configured. Since this is a 'compile time' check, they want to ensure this cannot happen.
Ideally, they perhaps ought to accept a #PIN_SELECT, set to a 'NULL' pin for a device using NOINIT. Suggest this to CCS. Explain the reason.

Possibly even 'better' would be if #USE RS232 supported just enabling the RX hardware. Given you can't enable the UART and have TX only, but can have RX only by turning off the TXEN bit, it'd be lovely is #USE RS232 had a RX_ONLY option, since this would then remove the problem.
asmallri



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

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

PostPosted: Mon Nov 19, 2018 9:34 am     Reply with quote

You could always tell the compiler that the UART is enabled by PPS, then in your code when you want the peripheral to go to sleep you manually manipulate the PPS registers to disconnect the UART from the pin. However you will need to use fast/io mode to ensure the LAT output remains low.
_________________
Regards, Andrew

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



Joined: 11 Mar 2010
Posts: 19217

View user's profile Send private message

PostPosted: Mon Nov 19, 2018 11:28 am     Reply with quote

Problem is, he is worried about the glitch at boot, when the TX signal drives the pin high, before he takes over control of the pin.
asmallri



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

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

PostPosted: Mon Nov 19, 2018 2:30 pm     Reply with quote

Ttelmah wrote:
Problem is, he is worried about the glitch at boot, when the TX signal drives the pin high, before he takes over control of the pin.


Ah, missed that. I had a similar issue for one of my products. I addressed it by using an analog MUX to disconnect the serial interface logic using the same control line that was the power enable for the peripheral. The trick is naturally to ensure the control inputs to the MUX have appropriate pull-up or pull-down resistors so the inputs do not float while the PIC is powering up. The solution worked very well.
_________________
Regards, Andrew

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



Joined: 25 Aug 2004
Posts: 66

View user's profile Send private message

PostPosted: Mon Nov 19, 2018 4:13 pm     Reply with quote

Thanks everyone for your input. Looks like the best available option for me is to set the TX up on a dummy output then relocate it as required. Just seems a little clunky.

(I've been running with 5.070 which has bugs in the pin_select() function (but #pin_select is okay) for the PIC18LF27K40 (wrong SFR addresses). I've just renewed my maintenance plan so hopefully it is fixed).

Cheers, Ross
Ttelmah



Joined: 11 Mar 2010
Posts: 19217

View user's profile Send private message

PostPosted: Tue Nov 20, 2018 7:54 am     Reply with quote

I would honestly talk to CCS, and suggest that they either allow the hardware UART to be programmed for receive only, or offer the option to bypass the PIN_SELECT testing when NOINIT is used.
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