CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Uart interrupts while using PIC18f87j94

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
harel12k



Joined: 26 Nov 2020
Posts: 11

View user's profile Send private message

Uart interrupts while using PIC18f87j94
PostPosted: Tue Dec 14, 2021 6:28 am     Reply with quote

Hi,
I'm dealing with interrupts problem while using PIC18f87j94.

Until three days ago, I worked with pic18f8722 with 2 usart ports and i2c.
Some constraints forced me looking for new uc with 3 usart, so I decided start working with the PIC18F87j94.
I used the same integration board and faced the physical ports place changed with PPS settings.
While I'm writing and reading data from all ports via interrupt it's work as well, but while I'm trying using data interrupt (Int_rda, int_rda2, int_rda3)
I'm not getting any interrupt, I've already enabled global interrupt, and even peripheral...
When I'm using GPIO toggle with timer1 interrupt trigger it's work as well...
What can cause the problem? What should I check?

Thanks
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Tue Dec 14, 2021 6:50 am     Reply with quote

Is it possible your chip has received some data, before you enable the
interrupts?.
Key thing is that if an error occurs on a port, and the interrupt is not
enabled/handled, then the receive part of the UART can become hung.
So long as you have 'ERRORS' in your RS232 declaration, and do not
clear the interrupt(s) before you enable them, the handler should be
called immediately, and the getc, will then clear the error. However if
an error had triggered, and you clear the interrupt before enabling it,
no further interrupts would ever occur from the port(s).... Sad
harel12k



Joined: 26 Nov 2020
Posts: 11

View user's profile Send private message

My chip doesn't get any data before interrupts enabled
PostPosted: Wed Dec 15, 2021 1:26 am     Reply with quote

Thank about you answer,
I checked this and I'm not getting any data before I'm enabling interrupts.
I'm working via Realterm and standard FTDI so I'm controlling the data stream.
I'm working with CCS 5.008
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Dec 15, 2021 6:24 am     Reply with quote

v5.008 is really early in the compiler, it wouldn't surprise me if there's a few 'bugs' in it.
I don't use that PIC, maybe others do and know which compiler version is 'stable' for it.
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Wed Dec 15, 2021 7:03 am     Reply with quote

Have to agree wholeheartedly. Especially with a relatively complex chip.
The first V5 compiler I found that would compile existing V4 code and
generate a result that actually 'worked' for me was mid V5.01x. Anything
before this was a 'beta' at best.
harel12k



Joined: 26 Nov 2020
Posts: 11

View user's profile Send private message

Compiler upgrade hasn't solved the problem
PostPosted: Wed Dec 15, 2021 1:31 pm     Reply with quote

Thank for all answers,
I updated compiler to 5.068, same problem.

More details:
Uart interrupts still doesn't occur.
When I'm reading RCREG1/2 registers, it's stay the same value (0x00) and never updating even I sending data to uc for sure.
GETC function works greats and read correctly data received by uc.


My code:

Code:

include "18f87j94.h"
#include <stdio.h>
#include <stdlib.h>

#fuses PR,nowdt,noprotect,nobrownout,NOIOL1WAY

#use delay(clock=20000000)
#use rs232(STREAM = FIRST_STREAM, baud = 115200, xmit = PIN_C6, rcv = PIN_C7, errors)
#use rs232(STREAM = SECOND_STREAM, baud = 115200,xmit=PIN_G1,rcv=PIN_G2,errors)

#byte PMD1 = 0xEF3
#byte RCSTA2 = 0xF33
#byte TRISG = 0xF98
#byte RCREG2 = 0xF1E
#byte RCREG1 = 0XFAE



#int_RDA2
void recieved_byte(){
    output_toggle(R_LED1); // this is external LED on my board
    putc(RCREG2,SECOND_STREAM);
   clear_interrupts(INT_RDA2);
}

#int_RDA
void recieved_byte(){
    output_toggle(G_LED1); // this is external LED on my board
    putc(RCREG1,FIRST_STREAM);
   clear_interrupts(INT_RDA);
}

void main() {
     pin_select("U2RX",PIN_G2,TRUE,FALSE);
     pin_select("U2TX",PIN_G1,FALSE,TRUE);
    set_tris_g(0b00000100);
    enable_interrupts(global);
    //enable_interrupts(peripheral); // I tried with and without this line
    enable_interrupts(INT_RDA2);
    enable_interrupts(INT_RDA);
   

   //Im receiving an echo check from both channels with those lines:
    putc(getc(FIRST_STREAM), FIRST_STREAM);
    putc(getc(SECOND_STREAM), SECOND_STREAM);
   
     // main loop - waiting for interrupts....
     while(1){
        delay_ms(100);
    }
}


Last edited by harel12k on Wed Dec 15, 2021 2:45 pm; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Dec 15, 2021 2:39 pm     Reply with quote

Quote:

#int_RDA2
void recieved_byte(){
output_toggle(R_LED1); // this is external LED on my board
putc(RCREG2,SECOND_STREAM);
clear_interrupts(INT_RDA2);
}

#int_RDA
void recieved_byte(){
output_toggle(G_LED1); // this is external LED on my board
putc(RCREG1,FIRST_STREAM);
clear_interrupts(INT_RDA);
}

Your interrupt routines are missing the fgetc() statements.
You actually have to get the byte from RCREG1 or RCREG2
inside the isr.

Add the lines of code to do that.

Also, you should be using fputc() when you have streams.
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Wed Dec 15, 2021 11:50 pm     Reply with quote

Absolutely.
Key is that you cannot clear the interrupt until the byte is read,. Without
the read, each interrupt will keep re-triggering....
harel12k



Joined: 26 Nov 2020
Posts: 11

View user's profile Send private message

Data interrupts doesn't happening
PostPosted: Thu Dec 16, 2021 12:26 am     Reply with quote

PCM programmer wrote:
Quote:

#int_RDA2
void recieved_byte(){
output_toggle(R_LED1); // this is external LED on my board
putc(RCREG2,SECOND_STREAM);
clear_interrupts(INT_RDA2);
}

#int_RDA
void recieved_byte(){
output_toggle(G_LED1); // this is external LED on my board
putc(RCREG1,FIRST_STREAM);
clear_interrupts(INT_RDA);
}

Your interrupt routines are missing the fgetc() statements.
You actually have to get the byte from RCREG1 or RCREG2
inside the isr.

Add the lines of code to do that.

Also, you should be using fputc() when you have streams.


Thank.
RCREG1 is the register of communication channel 1, why using fgetc instead can solve the problem? We are not getting into the interrupts...
After one interrupts I should see led turned on (led tested and worked), and in debug mode I'm not seeing any entry to data interrupt...
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Dec 16, 2021 2:18 am     Reply with quote

Just do it.
harel12k



Joined: 26 Nov 2020
Posts: 11

View user's profile Send private message

Problem solved
PostPosted: Mon Dec 20, 2021 5:27 am     Reply with quote

Thanks for answers.
Problem solved by writing the pin_selects rows before #use_rs232.
And in rs232 I'm not calling pin names, I'm calling UART1 or UART2 or UART3 instead.
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Mon Dec 20, 2021 7:04 am     Reply with quote

That is why the sticky at the top of the forum on #PIN_SELECT is so
important.... Smile
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group