EUSART2 and Timer1 interrupts

Discussion in 'Embedded Systems and Microcontrollers' started by spinnaker, Feb 16, 2012.

  1. spinnaker

    Thread Starter AAC Fanatic!

    Oct 29, 2009
    4,887
    1,012
    I have a Pic 18F27J53. I am using EUSART2 in async mode. The chip is kind of cool in that it allows me to map the pins for EUSART2 and a few other peripherals.

    All works well until I enable Timer1 interrupts. When I enable interrupts for timer1, I get no output from EUSART2 TX. Any ideas why? I checked the datasheet and I find nothing mentioned about timer 1 having an effect on USART.
     
    Last edited: Feb 17, 2012
  2. nsaspook

    AAC Fanatic!

    Aug 27, 2009
    2,908
    2,169
    What pin is EUSART2 TX mapped to?
     
  3. spinnaker

    Thread Starter AAC Fanatic!

    Oct 29, 2009
    4,887
    1,012
    RP1 is TX2


    But now I have another issue entirely. I am currently powering the Pic with the PicKit 3 and I am getting Unable to set power.

    This was just working an hout ago. I have seen this issue before. And some how got it to work. This chip seems awfully flaky with the PicKit 3. You have to put a resistor between Ground and PGD.
     
  4. spinnaker

    Thread Starter AAC Fanatic!

    Oct 29, 2009
    4,887
    1,012
    OK Back up and running. Not sure what the issue was. I rewired my connection to my Rs232 interface and that seemed to fix the issue with the power.


    I have developed a test program and that seems to work OK so it must me something in my other code. Maybe.

    It gets stranger with this code. I started to clean up the code to make a presentable example. So I started to delete those unused variable declarations. If I delete any variable, it does not matter where it is in the code, the Timer 1 interrupt no longer works. For example I can delete static int x = 0; then timer 1 interrupt no longer gets called. But I can delete weekdays or any other unused variable and timer 1 interrupt or any low priority interrupts get called.

    Very strange.





    main.c
    Code ( (Unknown Language)):
    1.  
    2. #include <P18F27J53.h>
    3. #include <stdio.h>
    4. #include <usart.h>
    5.    
    6.    
    7. #pragma config WDTEN = OFF
    8. #pragma config XINST = OFF
    9. #pragma config CFGPLLEN = OFF
    10. #pragma config CPUDIV = OSC1
    11. #pragma config OSC = INTOSCO
    12. #pragma config FCMEN = OFF
    13. #pragma config CLKOEC = ON
    14. #pragma config RTCOSC = INTOSCREF
    15.    
    16.  
    17. char weekdays[7][4] = {"Sun", "Mon", "Tue", "Wed","Thr","Fri","Sat"};
    18.  
    19.  
    20.  
    21.  
    22.    
    23.    
    24. void main()
    25. {
    26.     int i;
    27.     char c;
    28.     char m;
    29.     char s;
    30.    
    31.  
    32.     i=0;    
    33.  
    34.     TRISBbits.TRISB3 = 0;
    35.     LATBbits.LATB3 = 0;
    36.  
    37.     // 8MHZ  for 18F27J53
    38.     OSCCONbits.IRCF0 = 1;  
    39.     OSCCONbits.IRCF1 = 1;
    40.     OSCCONbits.IRCF2 = 1;
    41.  
    42.     // 18F27J53 configuration
    43.     EECON2 = 0x55;
    44.     EECON2 = 0xAA;
    45.  
    46.     PPSCONbits.IOLOCK = 0;        // Unlock mappable registers
    47.     RPOR1 = 0x06;                // Set RP1 as TX2 EUSART
    48.     RPINR16 = 0x00;
    49.     PPSCONbits.IOLOCK = 1;
    50.    
    51.     ANCON0bits.PCFG1 = 1;        // Configure AN1 as digital
    52.     TRISAbits.TRISA1 = 0;        // Set A1 as output
    53.    
    54.     TRISAbits.TRISA0 = 1;        // Set A1 as input
    55.     ANCON0bits.PCFG0 = 1;
    56.  
    57.     Open2USART( USART_TX_INT_OFF &
    58.                 USART_RX_INT_OFF &
    59.                 USART_ASYNCH_MODE &
    60.                 USART_EIGHT_BIT &
    61.                 USART_CONT_RX &
    62.                 USART_BRGH_HIGH,
    63.                 51);  // 51 = 9600 Baud for 4MHZ clock 103 = 9600 baud for 8MHZ clock
    64.  
    65.  
    66.    
    67.     putrs2USART("I am here 1\n\r");
    68.  
    69.     //Timer1 Registers Prescaler= 1 - TMR1 Preset = 65475 - Freq = 32786.89 Hz - Period = 0.000030 seconds
    70.     T1CONbits.T1CKPS1 = 0;   // bits 5-4  Prescaler Rate Select bits
    71.     T1CONbits.T1CKPS0 = 0;   // bit 4
    72.     T1CONbits.T1OSCEN = 1;   // bit 3 Timer1 Oscillator Enable Control bit 1 = on
    73.     T1CONbits.NOT_T1SYNC = 1;    // bit 2 Timer1 External Clock Input Synchronization Control bit...1 = Do not synchronize external clock input
    74.     T1CONbits.TMR1CS = 0;    // bit 1 Timer1 Clock Source Select bit...0 = Internal clock (FOSC/4)
    75.     TMR1H = 255;             // preset for timer1 MSB register
    76.     TMR1L = 195;             // preset for timer1 LSB register
    77.     T1CONbits.TMR1ON = 1;    // bit 0 enables timer
    78.    
    79.  
    80.     IPR1bits.TMR1IP = 1;    // Timer1 is low priority interrupt  
    81.     PIE1bits.TMR1IE = 1;    // Enable interrupts for Timer 1
    82.  
    83.      INTCONbits.GIEL = 1;            // Low priority interrupts allowed
    84.      INTCONbits.GIEH = 1;
    85.    
    86.     putrs2USART("I am here 2\n\r");
    87.  
    88.     while(1);
    89.  
    90.    
    91.    
    92. }
    93.  
    Code ( (Unknown Language)):
    1.  
    2. #include <P18F27J53.h>
    3.  
    4.  
    5. void InterruptServiceLow(void);
    6.  
    7.  
    8. // Low priority interrupt vector
    9. #pragma code InterruptVectorLow = 0x18
    10. void InterruptVectorLow (void)
    11. {
    12.   _asm
    13.     goto InterruptServiceLow //jump to interrupt routine
    14.   _endasm
    15. }
    16.  
    17. /** D E C L A R A T I O N S *******************************************/
    18. #pragma code    // declare executable instructions
    19.  
    20.  
    21.  
    22.  
    23. #pragma interruptlow InterruptServiceLow
    24. void InterruptServiceLow(void)
    25. {
    26.     static int x = 0;  
    27.    
    28.     // Check for Timer1 Overflow Interrupt
    29.     if  (PIR1bits.TMR1IF)
    30.     {        
    31.        
    32.         LATBbits.LATB3 =~ LATBbits.LATB3;
    33.         TMR1H = 255;             // preload for timer1 MSB register
    34.         TMR1L = 195;             // preload for timer1 LSB register
    35.         PIR1bits.TMR1IF = 0;     // clear flag        
    36.     }
    37.  
    38. }
    39.  
     
  5. spinnaker

    Thread Starter AAC Fanatic!

    Oct 29, 2009
    4,887
    1,012
    There must be memory issues with this particular chip. It does not run at all in release build and when I try a bank check I get

    Blank Checking...
    The following memory regions failed blank check:
    Program Memory
    Address: 00000000 Expected Value: 000000ff Received Value: 00000012
    Blank check failed
     
  6. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,388
    1,605
    Failed blank checks mean either the programmer, the chip, or the connections between these devices is bad. Or all 3. I noticed somewhere you needed to add a pull down resistor to the data line to get the programmer to work: you should not have to do that.
     
  7. spinnaker

    Thread Starter AAC Fanatic!

    Oct 29, 2009
    4,887
    1,012
    Originally the chip would not connect at all.

    It was recommend by Microchip for this chip. They had a PDF on it somewhere. It had something to do with voltage levels. The actually recommended modifying the programmer itself but I found a post that you could simply add a resistor to the ICSP connector.

    Funny though I just removed the resistor and it still connects and programs but it does not bank check.

    I have a ribbon connector for the ICSP. With that in place the chip refuses to connect no matter what I do. Other chips are fine with the ribbon connector.
     
Loading...