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

Cannot set some pins to digital when #pin_select is used

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



Joined: 08 Sep 2010
Posts: 8

View user's profile Send private message

Cannot set some pins to digital when #pin_select is used
PostPosted: Mon Jun 18, 2018 3:08 pm     Reply with quote

I am working on a PIC18F97J94 with CCS PCH 5.075. I am trying, and failing, to set several pins on the H port to digital when I use #pin_select. I have no issues setting the non-H-port pins to digital when #pin_select is used. I also have no problems changing the H-port pins to digital when #pin_select isn't used. The H-port pins all use ANCON3. I've tried using set_analog_pins() to do this as well as directly setting the ANCON3 register.

The only thing that I could do to get it working is using the pin_select() function. The problem with this is that there is more overhead, requires the fuse IOL1WAY to be off, and I cannot use the #use spi() and #use UART() helpers.

An example of the non-working code is:
Code:
#include <18F97J94.h>

#pin_select SDI1=PIN_D0

#byte ANCON1 = getenv("SFR:ANCON1") /* ADC inputs 0 - 7 */
#byte ANCON3 = getenv("SFR:ANCON3") /* ADC inputs 16 - 23*/

void main()
{
    //pin_select("SDI1", PIN_D0);
    ANCON1 = 0x11;
    ANCON3 = 0x55;
    for(;;){}
}


Running the debugger on the chip, and placing a breakpoint at the start of main() I see that ANCON3 is 0x00 when #pin_select isn't used and 0xFF when it is. The two other ANCON registers are 0x00 in both instances. The same code does what it should when debugging on the simulator.

Any insight would be greatly appreciated.
newguy



Joined: 24 Jun 2004
Posts: 1899

View user's profile Send private message

PostPosted: Mon Jun 18, 2018 5:29 pm     Reply with quote

I had similar issues with 5.073 and 5.074 last year with a PIC18F25K40. I had to implement the PPS assembly unlock procedure along with the proper fuse (forget the name) to allow it all. I then had to take direct control of the PPS registers to do what I needed it to do. I haven't tried that code with a newer release as it works and the thought of playing with it just to get it to work with the CCS functions honestly turns my stomach.

Try "doing it the hard way" and see if you can gain full control of port H.
dcm684



Joined: 08 Sep 2010
Posts: 8

View user's profile Send private message

PostPosted: Tue Jun 19, 2018 10:39 am     Reply with quote

Thanks newguy.

I went deeper into it and found that if I clear the bit, IOLOCK, I can change the values in ANCON3. I then re-set IOLOCK. This requires the fuse NOIOL1WAY.

Another interesting tidbit is that I can set the bits of ANCON3 even if IOLOCK is set. I just cannot clear the bits unless IOLOCK is clear.
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Wed Jun 20, 2018 3:15 am     Reply with quote

That is really odd!...

IOLOCK is not meant to affect ANCON, just the PPS control. Wow.
I would suggest reporting this to CCS and possibly MicroChip.
Presumably, since you were seeing the problem only with PortH, it is not happening with the other ANCON registers?.
It does sound as if you have found a chip 'oddity'.
Certainly one designed to drive you mad.

Just a teeny bit 'puzzled' though by your comment about not being able to use the #USE SPI 'helper' and #PIN_SELECT. Of course you can use #PIN select and #USE RS232 and #USE SPI. Just select the pins, and then use the port name in these. Look at the sticky at the head of the forum for how to do this.
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