EUSART2 and Timer1 interrupts

Thread Starter

spinnaker

Joined Oct 29, 2009
7,835
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:

Thread Starter

spinnaker

Joined Oct 29, 2009
7,835
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.
 

Thread Starter

spinnaker

Joined Oct 29, 2009
7,835
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
Rich (BB code):
#include <P18F27J53.h>
#include <stdio.h>
#include <usart.h>
    
    
#pragma config WDTEN = OFF
#pragma config XINST = OFF
#pragma config CFGPLLEN = OFF
#pragma config CPUDIV = OSC1
#pragma config OSC = INTOSCO
#pragma config FCMEN = OFF
#pragma config CLKOEC = ON
#pragma config RTCOSC = INTOSCREF
    

char weekdays[7][4] = {"Sun", "Mon", "Tue", "Wed","Thr","Fri","Sat"};




    
    
void main()
{
    int i;
    char c;
    char m;
    char s;
    

    i=0;    

    TRISBbits.TRISB3 = 0;
    LATBbits.LATB3 = 0;

    // 8MHZ  for 18F27J53
    OSCCONbits.IRCF0 = 1;  
    OSCCONbits.IRCF1 = 1;
    OSCCONbits.IRCF2 = 1;

    // 18F27J53 configuration
    EECON2 = 0x55;
    EECON2 = 0xAA;

    PPSCONbits.IOLOCK = 0;        // Unlock mappable registers
    RPOR1 = 0x06;                // Set RP1 as TX2 EUSART 
    RPINR16 = 0x00;
    PPSCONbits.IOLOCK = 1;
    
    ANCON0bits.PCFG1 = 1;        // Configure AN1 as digital 
    TRISAbits.TRISA1 = 0;        // Set A1 as output
    
    TRISAbits.TRISA0 = 1;        // Set A1 as input
    ANCON0bits.PCFG0 = 1;

    Open2USART( USART_TX_INT_OFF &
                USART_RX_INT_OFF &
                USART_ASYNCH_MODE &
                USART_EIGHT_BIT &
                USART_CONT_RX &
                USART_BRGH_HIGH,
                51);  // 51 = 9600 Baud for 4MHZ clock 103 = 9600 baud for 8MHZ clock


    
    putrs2USART("I am here 1\n\r");

    //Timer1 Registers Prescaler= 1 - TMR1 Preset = 65475 - Freq = 32786.89 Hz - Period = 0.000030 seconds
    T1CONbits.T1CKPS1 = 0;   // bits 5-4  Prescaler Rate Select bits
    T1CONbits.T1CKPS0 = 0;   // bit 4
    T1CONbits.T1OSCEN = 1;   // bit 3 Timer1 Oscillator Enable Control bit 1 = on
    T1CONbits.NOT_T1SYNC = 1;    // bit 2 Timer1 External Clock Input Synchronization Control bit...1 = Do not synchronize external clock input
    T1CONbits.TMR1CS = 0;    // bit 1 Timer1 Clock Source Select bit...0 = Internal clock (FOSC/4)
    TMR1H = 255;             // preset for timer1 MSB register
    TMR1L = 195;             // preset for timer1 LSB register
    T1CONbits.TMR1ON = 1;    // bit 0 enables timer
    

    IPR1bits.TMR1IP = 1;    // Timer1 is low priority interrupt  
    PIE1bits.TMR1IE = 1;    // Enable interrupts for Timer 1 

     INTCONbits.GIEL = 1;            // Low priority interrupts allowed
     INTCONbits.GIEH = 1;
    
    putrs2USART("I am here 2\n\r");

    while(1);

    
    
}
Rich (BB code):
#include <P18F27J53.h>


void InterruptServiceLow(void);


// Low priority interrupt vector
#pragma code InterruptVectorLow = 0x18
void InterruptVectorLow (void)
{
  _asm
    goto InterruptServiceLow //jump to interrupt routine
  _endasm
}

/** D E C L A R A T I O N S *******************************************/
#pragma code    // declare executable instructions




#pragma interruptlow InterruptServiceLow
void InterruptServiceLow(void)
{
    static int x = 0;   
    
    // Check for Timer1 Overflow Interrupt
    if  (PIR1bits.TMR1IF)
    {        
        
        LATBbits.LATB3 =~ LATBbits.LATB3;
        TMR1H = 255;             // preload for timer1 MSB register
        TMR1L = 195;             // preload for timer1 LSB register
        PIR1bits.TMR1IF = 0;     // clear flag        
    }

}
 

Thread Starter

spinnaker

Joined Oct 29, 2009
7,835
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
 

ErnieM

Joined Apr 24, 2011
8,040
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.
 

Thread Starter

spinnaker

Joined Oct 29, 2009
7,835
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.
 
Top