[PIC] Pic32mx795f512l Portf configuration :???:

Status
Not open for further replies.

dhakeparag81

Full Member level 2
Joined
Jun 6, 2012
Messages
142
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,298
Location
INDIA
Visit site
Activity points
2,469
Hello there,

I am working on above mentioned CPU from few days, Pic32 is new to me i face lots of problems while coding and i successfully solved it. But now i stuck in configuring PORTF RF3,RF4 and RF5 as an digital input. I pulled down these pins, while running the code all the above mentioned port pins are shown 1 in PORTF register i cross checked the voltage at the same time but its 0v.
I am missing something to configure.
TRISF register shows correct configuration for these pins.

Thanks,
 

RF3 is also USBID and RF4 and RF5 are the U2Rx and TX
have you enabled USB and/or UART2?

I tested with a PIC32MX360F512L and RF3 works as expected - 1 then 0 when I apply 0volts
I have UART2 enabled so RF4 and RF5 read as 1
 

thanks for reply,
I'll check and let u know.
I also heard about port pin damage do u know reasons due to that port pins may damage.
 

never had many problems of damaged IO pins.
Obviously applying a high voltage can cause damage.
Also when a pin is configured as an output driving it from external devices at the same time can result is in high output currents which may damage the chip.
 

Found the solution..:razz:
But the solution is little odd.
I am used the internal macro to set port pin as an input and same for output.
for example

Code:
mPORTGSetPinsDigitalOut(BIT_0);
mPORTESetPinsDigitalIn(BIT_8 | BIT_9);
//definition #define mPORTDSetPinsDigitalOut(_outputs)   (TRISDCLR = (unsigned int)(_outputs))
(Macro are defined in ports.h)

which internally clear or set the bit, this is new method see IO port section of Datasheet.(Generally we used TRIS to set GPIO)
Then i used TRIS to set for input and same for output that's it.
It solve my problem.
Can you explain how it work?

But still i am not able to use pin RF3, as you said i disabled the usb by
Code:
#pragma config FUSBIDIO = OFF           // USB USID Selection (Controlled by Port Function)
#pragma config FVBUSONIO = OFF          // USB VBUS ON Selection (Controlled by Port Function)
but didnt work.
Am i missing something?
and one more thing according to datasheet i pulled-up the VUSB3v3 pin.
Is anyone faced same problem?

Thanks again
 

not sure what is going on - I have used the macros mPORTASetPinsDigitalOut() etc without problems

this is a small test program for an Explorer 16 with a PIC32MX360F512L, sets up the UART, Timer, reads switch clears and sets LEDs etc
Code:
int main(void)
{
    int i;
	// Explorer16 LEDs are on lower 8-bits of PORTA and to use all LEDs, JTAG port must be disabled.
    mJTAGPortEnable(DEBUG_JTAGPORT_OFF);
	// Configure the device for maximum performance but do not change the PBDIV
	// Given the options, this function will change the flash wait states, RAM
	// wait state and enable prefetch cache but will not change the PBDIV.
	// The PBDIV value is already set via the pragma FPBDIV option above..
	SYSTEMConfig(GetSystemClock(), SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);

	mPORTAClearBits(0xff); 			// clear LEDs
	mPORTASetPinsDigitalOut(0xff);	// make LEDs outputt.
	mPORTDSetPinsDigitalIn(BIT_6 | BIT_7);	// make switches input
    for(i=0;i<50;i++)				// blink LEDs on poeer up
      { mPORTAToggleBits(0xff);  delay(1000000ul); }
	mPORTASetBits(0x55); 		// set LEDs
	UART2Init(PC_BAUDRATE);			// initialise UART2 to PC host
   	UART2PrintString("*** UART and LCD tests ***\r\n");
   	printf("\nprintf test \n");
	Timer1init();					// initialise timer 1
    for(i=0;i<20;i++)				// blink LEDs 0.1sec using timer
      { mPORTAToggleBits(0xff);  mSecDelay(100); printf("*");}
    if ( ReadEventWDT() )		// check for watchdog event
		{
         DisableWDT();		 // A WDT event did occur
         ClearEventWDT();    // clear the WDT event flag so a subsequent event can set the event bit
		 printf("watchdog timer event occured \n");
		}
   	UART2PrintString("*** Type some characters and observe echo and RA7 LED toggle ***\r\n");
	mSecElapsed(1,1,1);
	mPORTAClearBits(0xff); 			// clear LEDs
	// loop 
	while (1)
       {
		// if character received from PC echo it and toggle LED
        if(UART2CharReady())
			{
            char ch=UART2GetChar();
            UART2PutChar(ch);;
 			// Toggle LED to indicate UART activity
			mPORTAToggleBits(BIT_7);
			}

		// if 1 second elapted print * and toggle LED
		if(mSecElapsed(1, 0, 1000)) 
			{ 
            mSecElapsed(1,1,1); UART2PutChar('*'); mPORTAToggleBits(BIT_0);
			printf("  PORTF 0x%x TRISF 0x%x\n", PORTF, TRISF);
			}
        // test input from switches RD6 and RD7
        if(PORTD & 0x40) mPORTASetBits(BIT_1); else mPORTAClearBits(BIT_1); 
        if(PORTD & 0x80) mPORTASetBits(BIT_2); else mPORTAClearBits(BIT_2); 
		ClearWDT(); 		// clear watchdog timer - comment out to test
       }
	return 0;
}
this is the output - you can see RF3 changing state as I ground it
Code:
UART2 baud rate 115200 set up
*** UART and LCD tests ***

printf test
Timer 1 initialised ticks 1000/sec counter is 312
*********************** Type some characters and observe echo and RA7 LED toggle ***
*  PORTF 0x21ff TRISF 0x31ff
*  PORTF 0x21ff TRISF 0x31ff
*  PORTF 0x21ff TRISF 0x31ff
*  PORTF 0x21f7 TRISF 0x31ff
*  PORTF 0x21f7 TRISF 0x31ff
*  PORTF 0x21f7 TRISF 0x31ff
*  PORTF 0x21f7 TRISF 0x31ff
*  PORTF 0x21ff TRISF 0x31ff
*  PORTF 0x21ff TRISF 0x31ff
*  PORTF 0x21ff TRISF 0x31ff
*  PORTF 0x21ff TRISF 0x31ff

I have found a PIC32 Ethernet starter kit with a Pic32mx795f512l - will try that out
 
Last edited:

ran the following code on a PIC32 Ethernet Start Kit with a PIC32MX795F512L

as I gound the RF3 (pin 33?) the BIT_2 LED goes on/off

Code:
// PIC32 Ethernet starter kit
//   test LEDs and switches only

//• SW1: Active-low switch connected to RD6
//• SW2: Active-low switch connected to RD7
//• SW3: Active-low switch connected to RD13
//The RD0 through RD2 LEDs are connected to PORTD of the processor. 

#include <plib.h>					// Peripheral Library

#pragma config FPLLODIV = DIV_1, FPLLMUL = MUL_15, FPLLIDIV = DIV_2, FWDTEN = OFF, FPBDIV = DIV_1, POSCMOD = XT, FNOSC = PRIPLL, CP = OFF
#pragma config FMIIEN = OFF, FETHIO = OFF	// external PHY in RMII/alternate configuration
	
// Clock frequency values
#define GetSystemClock()		(60000000ul)			// Hz


// simple delay loop
void delay(unsigned long int count)
{
   unsigned long int j;
   for(j=0;j<count;j++) Nop();;
}


int main(void)
{
	mPORTDSetPinsDigitalOut(0xff);	// make LEDs outputt.
	mPORTDSetPinsDigitalIn(BIT_6 | BIT_7 | BIT_13);
	mPORTFSetPinsDigitalIn(BIT_3);
	// Enable optimal performance
	SYSTEMConfigPerformance(GetSystemClock());
	mOSCSetPBDIV(OSC_PB_DIV_1);				// Use 1:1 CPU Core:Peripheral clocks
		
    while(1)
      { 
       // blink BIT 0 LED
       mPORTDToggleBits(BIT_0);  
       // copy RD7 switch to BIT 1 LED
       if(PORTD & 0x80) mPORTDSetBits(BIT_1); else mPORTDClearBits(BIT_1); 
	   // copy RF3 to BIT 2 LED
       if(PORTF & 0x8) mPORTDSetBits(BIT_2); else mPORTDClearBits(BIT_2); 
	   delay(1000000ul);
      }
}
no idea what your problem with RF3 is
 
Last edited:

Don't know.
Actually i used that pin in keypad matrix as an input.
6x7 matrix 6 rows as output and pulled to vcc by 10kOhm, 7 column as input and pulled to Gnd by 10kOhm.
Right know i am out of time so i simply used another pin instead of RF3, but when i free i'll try to find out the reason and post it.
But any way Thanks for your time.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…