# Digital input ports of the dsPIC30F4011/4013 not working on the dsPICDEM 2 Development Board

I have a Microchip dsPICDEM 2 Development Board with two microcontrollers on it: a dsPIC30F4011 (Motor Control Family) and a dsPIC30F4013 (General Purpose Family). I'm programming in C using the MPLAB IDE.

What I want to do is read the a digital input signal with TTL levels (0-5 V), but the reading of the ports is always 0.

If I set the port to be an output using the corresponding TRIS register and then write to the corresponding LAT register, it works fine. For example:

TRISBbits.TRISB0 = 0; // set RB0 to be an output
LATBbits.LATB0 = 1;


works perfectly.

However, when I set the port to be an input, I keep reading 0 both from the LAT and the PORT register. So, neither of the following code excerpts work:

// This doesn't work:

TRISBbits.TRISB0 = 1; // set RB0 to be an input
value = LATBbits.LATB0;

// This doesn't work either:

TRISBbits.TRISB0 = 1; // set RB0 to be an input
value = PORTBbits.RB0;


My program is as simple as this:

int main(void)
{
TRISBbits.TRISB0 = 1;
TRISBbits.TRISB1 = 0;

while (1)
{
int rb0 = LATBbits.LATB0;
LATBbits.LATB1 = rb0;
}

return 0;
}


so there's no other possible error source in the program.

These are the documents I've used for reference:

What am I doing wrong?

EDIT: After the corrections pointed out by Tut (see accepted answer), the code of the program looks like this:

int main(void)
{
TRISBbits.TRISB0 = 1; // set RB1 as input
TRISBbits.TRISB1 = 0; // set RB1 as output
ADPCFGbits.PCFG0 = 1; // set RB0 as digital input (i.e. disable analog input)

while (1)
{
LATBbits.LATB1 = PORTBbits.RB0;
}

return 0;
}

• Most likely the pins in question are multiplexed with another peripherals or there are some pull-down resistors active on the pins.. – m.Alin Oct 14 '13 at 13:22
• Yes, indeed, they are multiplexed, but the datasheets specify that, after a reset, the pins are configured as digital inputs by default and the pins are only used for the other peripherals if the peripherals are enabled (which is not the case). In addition, I can use them as outputs, but not as inputs. – Genba Oct 14 '13 at 14:28