0
\$\begingroup\$

I've been having a very strange problem with my PIC16F15345 microcontrollers. I'm trying to read a digital input state from a specific pin on the microcontroller (Pin2, or RA5). My setup code is below:

#include <xc.h>
#include <pic.h>
#include <pic16F15345.h>

#define _XTAL_FREQ 32000000

#pragma config WDTE = OFF

void main(void){
    OSCFRQbits.HFFRQ = 0b110; //set HFINTOSC to 32MHz
    OSCCON1bits.NOSC = 0b110; //set clock to HFINTOSC
    TRISA = 0b11111111; //set all portA bits to input
    ANSELA = 0b00000000; //set all portA bits to digital input
    while(1)
    {
        //loop forever;
    }
    return;
}

I'm using the latest XC8 compiler, MPLABx IDE, and a PICKIT3 programmer. I'm using an arduino's output pins to toggle the state of the input pin on the PIC, so I don't have to worry about debouncing and can trigger state changes via software.

If I want to measure RA4, or pin3, I can use the debugger to check the value of the PORTA register, and it shows a change of state corresponding to what I'd expect. PORTB and PORTC are also working normally.

However, for some reason, RA5 will always read 0, no matter what the input voltage at the pin is (I've verified 4.8V at the pin with a multimeter). At first I thought maybe I damaged my input via ESD, so I changed to another IC of the same model (I ordered 3 from Digikey), and the problem persisted. I changed to the 3rd and final chip, but the problem was still there.

I've been trawling the microchip forums for answers, but no avail so far. Any advice is appreciated!

\$\endgroup\$
3
  • \$\begingroup\$ You are not indeed reading nothing anywhere. I would expect something within the while(1) loop. \$\endgroup\$ Oct 9, 2017 at 6:00
  • \$\begingroup\$ To clarify, stuff would normally be going on in the main loop of the program, but I cut it out for clarity's sake here. I'm using the debugger in the IDE to view the registers, not a variable in the program itself (I've tried that also, but it doesn't change the results) \$\endgroup\$
    – Platytude
    Oct 9, 2017 at 6:14
  • \$\begingroup\$ If you are using MCC, then select Internal oSC with clockout function I/O \$\endgroup\$
    – Hemjal
    May 28, 2020 at 13:48

3 Answers 3

1
\$\begingroup\$

http://www.mouser.com/ds/2/268/40001865B-1082596.pdf Check TABLE 1-2: PIC16(L)F15325 PINOUT DESCRIPTION (CONTINUED) Only Select GPIO function Disable all other functions.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Could you clarify slightly? The setup code would indicate that I have the pin set up to be a GPIO only, no? None of the other modules that this pin is interfaced to have been initialized. Even so, RA4 has similar extra functionality, but it's working just fine. \$\endgroup\$
    – Platytude
    Oct 9, 2017 at 6:21
1
\$\begingroup\$

Solved it myself after some more digging. Turns out the RA5 pin will default to the external oscillator input by default, and to allow GPIO function you need to add the following line to the beginning of your code:

#pragma config FEXTOSC = OFF

This resolved the problem for me.

\$\endgroup\$
1
\$\begingroup\$

on my 12F1822 RA5 also defaults to the external oscillator input. if FOSC.intsoc is set to 1 and OSCCONbits.SCS = 00;, it does not solve the problem. You must also put in a delay after OSCCONbits.SCS = 00;. This is because when the Oscillator pins is instructed to be switched from the default setting, the process takes some time to take effect.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Welcome to EE.SE, Robert. Just a tip: capitalise and punctuate your sentences properly. Your answer lacks credibility because it is carelessly written. Your compiler won't let you away with it. Why should we? \$\endgroup\$
    – Transistor
    Mar 8, 2018 at 13:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.