Forums

read User Jumpers, 56F8357 eval. board, code snippets

Started by Corey, Rick May 13, 2004
Hi

Here's 2 trivial code snippets for configuring and reading the "User
Jumpers" on a 56F8357 evaluation board. These are jumpers JG15 and JG16. I
configure them as GPIO inputs (open drain). See figure 2-12, section 2.14
of the '357 EVM Hardware User Manual. The alternate functions for these two
pins are SPIbus SCLK0 and /SS0.

--> It is necessary to configure them for NO PULLUP resistors. <--

I include code for assuring that interrupts are turned off for these pins.
You probably don't need to set IENR, IAR or IESR. This code is based on
Processor-Expert-style macros, and changes *only* those bits in each cfg
registers that you need to change - it leaves the other bits as they were.

This isn't efficient code, or clever, but it took me a while to figure out
that the external pull-ups (10K according to the EVM Manual) do not (always)
overcome the internal pull-ups, so you have to disable the internal pull-ups
if you want to read the jumper reliably.

Rick Corey

void Cfg_ReadGpio_PE4_PE7( void)
{

// init code for eval board User Jumpers. JG15=PortE_4 JG16=PortE_7
// jumper 1-2 to SET bit. jumper 2-3 for CLEAR bit

// first block taken from PE Port D setup, unchanged: no IRQs
setReg( *GPIO_E_IENR, getReg( *GPIO_E_IENR ) & ~0x90 ); //
GPIO_E_IENR: IEN=0
setReg( *GPIO_E_IAR, getReg( *GPIO_E_IAR ) & ~0x90 ); //
GPIO_E_IAR: IA=0
setReg( *GPIO_E_IESR, getReg( *GPIO_E_IESR ) | 0x90 ); //
GPIO_E_IESR: IESR=1 ?
setReg( *GPIO_E_PPMODE, getReg( *GPIO_E_PPMODE ) | 0x90 ); //
GPIO_E_PPMODE: 1=OpenDrain

// make pins 4 & 7 of Port E GPIO INPUTS
setReg( *GPIO_E_PUR, getReg( *GPIO_E_PUR ) & ~0x90 ); // --> DISABLE
the two pull-up resistors on pins 4&7 (PUR=0) <--
setReg( *GPIO_E_DDR, getReg( *GPIO_E_DDR ) & ~0x90 ); // set pins
4&7 to INPUTS (DDR=0)
setReg( *GPIO_E_PER, getReg( *GPIO_E_PER ) & ~0x90 ); // pins 4&7
are GPIO (PER=0)

} // end Cfg_ReadGpio_PE4_PE7() ushort ReadPortE_Bit( ushort BitNum )
{
ushort PortE_DRvalue=0;

PortE_DRvalue = *GPIO_E_DR & (1 << BitNum) ;

if (PortE_DRvalue)
return( TRUE );
else
return( FALSE );

/*
ushort PortE_DRvalue=0;
for (;;)
{
PortE_DRvalue = *GPIO_E_DR ;
PortE_DRvalue &= (1 << BitNum) ;
return( PortE_DRvalue );
}
*/

}

Rick Corey
Senior Software Engineer
DPC Instrument Systems Division