Problem in pin RB2/INT2 - 18F2550

Discussion in 'Embedded Systems and Microcontrollers' started by moahrs, Dec 7, 2011.

  1. moahrs

    Thread Starter New Member

    Dec 5, 2011
    8
    0
    Hi Guys,

    I have a problema very intersting. I use the 18F2550, and i am trying read from PIN RB2 anything, but this pin dont response. In my last try, i am using RB2 as INT2, active in the faling of signal, but i can put 0v, 5v, 2v, 10v, 50v, -150v, and nothing, the pin dont accept the interruption. And the same with reading, the RB2 dont return anithing. It seems he's always in "1", or in three-state.

    I am set all registers of interruptions, in ADCON1, I had put only RA0 and RA1 as analogic (for A/D), all other pin as digital input/output, i disable all interruptions from peripherics, i put INT2 as High Priority, ans other as Low, and nothing.

    Below, my code, make in c++.
    Code ( (Unknown Language)):
    1.  
    2. void main()
    3. {
    4.     unsigned int cc;
    5.        
    6.     // CONFIGURAR PORTAS
    7.     ADCON1 = 0x0D;    // RA0=AN0, RA1=AN1, TODAS AS DEMAIS ANx = DIGITAIS
    8.     PORTA = 0x30;
    9.     PORTB = 0x00;
    10.     PORTC = 0x00;
    11.     TRISA = 0x0B;    // RA7-X, RA6-X, RA5-INTZ80, RA4-CTRWAIT, RA3-PC6, RA2-X+/Y+, RA1-AN1, RA0-AN0
    12.     TRISB = 0xFC;    // RB7 A RB3 - D7 A D3, RB2-INT2/CS2, RB1-SCL, RB0-SCA
    13.     TRISC = 0x97;    // RC7-RX, RC6-TX, RC5-D+, DC4-D-, RC3-X, RC2 A RC0 - D2 A D0, RE3-PC5
    14.  
    15.     RCON = RCON | 0x80;
    16.     PIR1 = 0x00;
    17.     PIR2 = 0x00;
    18.     PIE1 = 0x40;
    19.     PIE2 = 0x20;
    20.     IPR1 = 0x00;
    21.     IPR2 = 0x00;
    22.     INTCON = 0x80;    // 0x80
    23.     INTCON2 = 0xE0;   // 0xE0
    24.     INTCON3 = 0x90;   // 0x90
    25.  
    26.     pbyte = 0xD5;
    27.     OUT_TFFT = 1;
    28.     cc = 0;
    29.  
    30.     while(1)
    31.     {
    32.         if (cc <= 0x06FF)
    33.             OUT_TFFT = 1;
    34.         else
    35.             OUT_TFFT = 0;
    36.  
    37.         cc++;
    38.  
    39.         if (cc > 0x0EFF)
    40.             cc = 0;
    41.     }
    42. }
    43.  
    44. void isr_reset(void) __interrupt 0
    45. {
    46.     main();
    47. }
    48.  
    49. void isr_int2(void) __interrupt 1
    50. {
    51.     unsigned char vINT;
    52.  
    53.     vINT = INTCON3 & 0x02;
    54.  
    55.     if (vINT == 0x02)    // FLAG DE INT2 DISPARADA
    56.     {
    57.         // DESLIGA FLAG DE INT2
    58.         INTCON3 = 0x90;
    59.  
    60. #ifndef debug
    61.         if (IN_PC6 == 0 && IN_PC5 == 1)                // WR DADOS
    62.             pbyte = RecebeByte();
    63.         else if (IN_PC6 == 1 && IN_PC5 == 0)        // RD DADOS
    64.             EnviaByte(pbyte);
    65.         else if (IN_PC6 == 1 && IN_PC5 == 1)        // RD CTRL
    66.             EnviaByte(pbyte);
    67. #endif
    68.     }
    69. }
    70.  
    Some1 have any idea, PLZ.


    Ty a lot
    Moacir Jr.
     
    Last edited by a moderator: Dec 9, 2011
  2. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    2,682
    2,742
    I sure hope this is a typographical error!
     
  3. moahrs

    Thread Starter New Member

    Dec 5, 2011
    8
    0
    Sry, i am junt kidding. Its is only one thing that any signal type do nothing in this pin. I am put only 0v or 5v. I never put more than 5v. Sry for this.
     
  4. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,884
    1,005
    First post your schematic. The circuit for analog inputs is very important.


    Also don't do interrupts for now. Just poll the analog pin every few seconds.

    And I am not seeing anywhere you are setting ANSEL. Have not yet looked at the 18F2550 datasheet but I would think you would have to set it. When I get some time I will try and take a look at the datasheet.
     
  5. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    PortB.2 is used by

    USB Module
    Comparator Module
    ADC input Channel
    Chip Select for Streaming Parallel Port.

    Datasheet has this note:
    One or more of the above should get you going. Make sure all listed peripherals are turned off, or at least not using RB2, and PBADEN is set for digital inputs. Power on reset has them as analog inputs from note directly above.
     
  6. moahrs

    Thread Starter New Member

    Dec 5, 2011
    8
    0
    Hi,

    Thy for help. Problem solved.



    Moacir Jr.
     
  7. River85

    New Member

    Aug 26, 2013
    1
    0
    Hi. I have the same problem, how do you solve it?

    Thanks
     
  8. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,388
    1,605
    It was solved by reading post #5.
     
Loading...