News:

;) This forum is the property of Proton software developers

Main Menu

Annoying hangup

Started by charliecoutas, Today at 09:57 AM

Previous topic - Next topic

charliecoutas

This is driving me nuts. The simplest code, I'm missing something obvious, probably a bad sign of old age.

I have cut this back to the minimum: the output of UART1 is wired to the input of UART1. The code below should blink the led every time UART1 receives a character. The ISR should clear the int and return. Characters are  being sent but the LED comes on and stays on.

If I disable UART1 interrupts (RX1IE=0), the LED never lights.

Could somebody put me straight please?

    Device = 24HJ128GP504                          ;24 bit jobbie
    Declare Xtal = 79.23
    Declare Hserial1_Baud = 9600                   
    Declare Hserial2_Baud = 9600                   
    Declare HRSOut1_Pin = PORTB.8                 
    Declare HRSOut2_Pin = PORTB.10                 
 
    PLL_Setup(43, 2, 2, $0300)                      ;Configure the Oscillator to operate at 79.23MHz
                                               
    PPS_Output(cOut_Pin_RP8, cOut_Fn_U1TX)          ;put uart1 output on RB8 (Peripheral remapping PPS)
    PPS_Input(cIn_Pin_RP9, cIn_Fn_U1RX)            ; ..  ..  input  on RB9

    PPS_Output(cOut_Pin_RP10, cOut_Fn_U2TX)        ;put uart2 output on RB10
    PPS_Input(cIn_Pin_RP11, cIn_Fn_U2RX)            ; ..  ..  input  on RB11                                               


    Symbol    led        PORTA.4                  ;diagnostic led


    Symbol    U1RXIF      IFS0.11                  ;UART1 int flag
    Symbol    U2RXIF      IFS1.14                  ;UART2 has interripted
    Symbol    U2RXIE      IEC1.14                  ;enable interrupts on UART2 (HVC board)
    Symbol    U1RXIE      IEC0.11                  ;  ..      ..    .. UART1 (rs232 terminal)
                                           
    Dim      Emul  As  Byte
   
    TRISA = %0000000000000000                     
    TRISB = %0000101010010000                     

            Clear                                  ;clear ram         

            U1MODE = %1000100000000000              ;enable uart2, RTS is simplex mode         
            U1STA  = %0000010000000000              ;turn xmittr on
            U2MODE = %1000100000000000              ;enable uart2, RTS is simplex mode           
            U2STA  = %0000010000000000              ;turn xmittr on
                       
            U1RXIE = 1                              ;allow RX1 ints  only
            U2RXIE = 0

            While
              HRSOut1 $01                          ;xmit a char
              DelayMS 100                          ;delay
            Wend 

    Isr - U1rxinterrupt                           
          Emul = U1RXREG                          ;take char from UART                     
          Toggle led
          U1RXIF = 0                              ;clear interrupt flag   
    EndIsr
   
    Isr - U2rxinterrupt
          IFS1.14 = 0                              ;clear interrupt flag
    EndIsr

    Config FBS = BWRP_WRPROTECT_OFF, BSS_NO_FLASH, BSS_NO_BOOT_CODE
    Config FSS = SWRP_WRPROTECT_OFF, SSS_NO_FLASH, RSS_NO_SEC_RAM
    Config FGS = GWRP_OFF, GCP_OFF
    Config FOSCSEL = FNOSC_FRCPLL, IESO_OFF
    Config FOSC = POSCMD_NONE, OSCIOFNC_ON, IOL1WAY_OFF, FCKSM_CSDCMD
    Config FWDT = WDTPOST_PS256, WINDIS_OFF, FWDTEN_OFF
    Config FPOR = FPWRT_PWR128, ALTI2C_OFF
    Config FICD = ICS_PGD1, JTAGEN_OFF

Charlie (almost all hair now on floor)

RGV250

#1
Hi Charlie,
The only thing I would try is to extend the 100ms timer as it might be toggling the LED but too fast. I would make it 1 second for the test.

Also I would do an incrementing number to make sure it is actually doing what you want.

Are you monitoring what is being sent by a serial terminal?

Regards,
Bob

charliecoutas

Hi Bob,

Serial terminal? No, I'm looking at the scope, the char being sent looks right, about 100uS bit time so the baud stuff is OK. The bigger version of this code, much much bigger, worked and I have used it and the pcb for another use. You can almost count the 10 blinks/sec so I don't think it's that. It's some damn setting that I overlooked I suspect. It's as though the UART1 interrupt is not being cleared so the processor keeps going back to it.

Are you keeping well?

Charlie

charliecoutas

Found it!!! It's not the code, it's the wiring on the board. If I set LOOPBACK on both uarts everything behaves.

Charlie