??? 10/07/10 16:15 Read: times |
#178972 - Port 3 interrupt and input problem, Silicon Labs C8051F020 |
Hello,
I have recently been working with the Silicon Labs C8051f020 development board (C8051f020-DK). I am trying to read either a logic level high voltage, or 5V as high into the 8051. When I attempted this using port 3 (Setting pin 3.7, IE7 to edge trigger high) I could not get the interrupt to trigger. I am now attempting to set pin 3.7 as a digital input (No interrupt) and read in a logic level high. I am following the example code and I have tried setting the pin to open drain and writing a 1 to the pin, as well as setting the pin to open drain and then writing a 0 to the pin. Either way, 3.7 volts always appears on the pin. According to the code the LED should trigger on or off when a ground is applied. Even if the pin is changed from the example to open drain, the LED always turns on or off if you apply ground to pin 3.7. I have read through the crossbar and port configurations and they seem to be set correctly, though I could see how the crossbar could potential cause a problem. I am obviously making some mistake with my configuration, so any ideas would help me out a lot. The example code (after my experimentation) is below. Thank You. //----------------------------------------------------------------------------- // F02x_Ports_SwitchLED.c //----------------------------------------------------------------------------- // Copyright 2005 Silicon Laboratories, Inc. // http://www.silabs.com // // Program Description: // // This program demonstrates how to configure port pins as digital inputs // and outputs. The C8051F020 target board has one push-button switch // connected to a port pin and one LED. The program constantly checks the // status of the switch and if it is pushed, it turns on the LED. // // // How To Test: // // 1) Download code to a 'F020 target board // 2) Ensure that the J1 and J3 headers are shorted // 3) Push the button (P3.7) and see that the LED turns on // // // FID: 02X000002 // Target: C8051F02x // Tool chain: Keil C51 7.50 / Keil EVAL C51 // Command Line: None // // Release 1.0 // -Initial Revision (GP) // -15 NOV 2005 // //----------------------------------------------------------------------------- // Includes //----------------------------------------------------------------------------- #include <c8051f020.h> // SFR declarations //----------------------------------------------------------------------------- // Pin Declarations //----------------------------------------------------------------------------- sbit LED1 = P1^6; // LED1 ='1' means ON sbit SW1 = P3^7; // SW1 ='0' means switch pressed //----------------------------------------------------------------------------- // Function Prototypes //----------------------------------------------------------------------------- void OSCILLATOR_Init (void); void PORT_Init (void); //----------------------------------------------------------------------------- // main() Routine //----------------------------------------------------------------------------- void main (void) { WDTCN = 0xde; // Disable watchdog timer WDTCN = 0xad; PORT_Init(); // Initialize Port I/O OSCILLATOR_Init (); // Initialize Oscillator while (1) { if (SW1 == 0) // If switch depressed { LED1 = 1; // Turn on LED } else { LED1 = 0; // Else, turn it off } } // end of while(1) } // end of main() //----------------------------------------------------------------------------- // Initialization Subroutines //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- // OSCILLATOR_Init //----------------------------------------------------------------------------- // // Return Value : None // Parameters : None // // This function initializes the system clock to use the internal oscillator // at its maximum frequency. // //----------------------------------------------------------------------------- void OSCILLATOR_Init (void) { OSCICN |= 0x03; // Configure internal oscillator for // its maximum frequency (24.5 Mhz) } //----------------------------------------------------------------------------- // PORT_Init //----------------------------------------------------------------------------- // // Return Value : None // Parameters : None // // This function configures the crossbar and ports pins. // // To configure a pin as a digital input, the pin is configured as digital // and open-drain and the port latch should be set to a '1'. The weak-pullups // are used to pull the pins high. Pressing the switch pulls the pins low. // // To configure a pin as a digital output, the pin is configured as digital // and push-pull. // // Some ports pins do not have the option to be configured as analog or digital, // so it not necessary to explicitly configure them as digital. // // An output pin can also be configured to be an open-drain output if system // requires it. For example, if the pin is an output on a multi-device bus, // it will probably be configured as an open-drain output instead of a // push-pull output. For the purposes of this example, the pin is configured // as push-pull output because the pin in only connected to an LED. // // P1.6 digital push-pull LED1 // P3.7 digital open-drain Switch 1 //----------------------------------------------------------------------------- void PORT_Init (void) { P1MDIN |= 0x40; // P1.6 is digital P1MDOUT = 0x40; // P1.6 is push-pull P3MDOUT = 0x00; // P3.7 is open-drain P3 |= 0x80; // Set P3.7 latch to '1' XBR2 = 0x40; // Enable crossbar and enable // weak pull-ups } //----------------------------------------------------------------------------- // End Of File //----------------------------------------------------------------------------- |
Topic | Author | Date |
Port 3 interrupt and input problem, Silicon Labs C8051F020 | 01/01/70 00:00 | |
inconsistency in datasheet | 01/01/70 00:00 | |
Thank you | 01/01/70 00:00 | |
also | 01/01/70 00:00 | |
Clarification on answer | 01/01/70 00:00 | |
for this | 01/01/70 00:00 | |
Confusing replies | 01/01/70 00:00 | |
Not my confusion | 01/01/70 00:00 | |
confused me | 01/01/70 00:00 | |
confused me | 01/01/70 00:00 | |
hm | 01/01/70 00:00 | |
the common method is .... | 01/01/70 00:00 | |
good | 01/01/70 00:00 | |
On Some SiLabs Parts (but not 'F020) | 01/01/70 00:00 | |
interrupt polarity on F020 | 01/01/70 00:00 | |
Correct? | 01/01/70 00:00 | |
EIE2, EA and ISR | 01/01/70 00:00 |