View previous topic :: View next topic |
Author |
Message |
harel12k
Joined: 26 Nov 2020 Posts: 11
|
Uart interrupts while using PIC18f87j94 |
Posted: Tue Dec 14, 2021 6:28 am |
|
|
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: 19537
|
|
Posted: Tue Dec 14, 2021 6:50 am |
|
|
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).... |
|
|
harel12k
Joined: 26 Nov 2020 Posts: 11
|
My chip doesn't get any data before interrupts enabled |
Posted: Wed Dec 15, 2021 1:26 am |
|
|
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: 9241 Location: Greensville,Ontario
|
|
Posted: Wed Dec 15, 2021 6:24 am |
|
|
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: 19537
|
|
Posted: Wed Dec 15, 2021 7:03 am |
|
|
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
|
Compiler upgrade hasn't solved the problem |
Posted: Wed Dec 15, 2021 1:31 pm |
|
|
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
|
|
Posted: Wed Dec 15, 2021 2:39 pm |
|
|
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: 19537
|
|
Posted: Wed Dec 15, 2021 11:50 pm |
|
|
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
|
Data interrupts doesn't happening |
Posted: Thu Dec 16, 2021 12:26 am |
|
|
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
|
|
Posted: Thu Dec 16, 2021 2:18 am |
|
|
Just do it. |
|
|
harel12k
Joined: 26 Nov 2020 Posts: 11
|
Problem solved |
Posted: Mon Dec 20, 2021 5:27 am |
|
|
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: 19537
|
|
Posted: Mon Dec 20, 2021 7:04 am |
|
|
That is why the sticky at the top of the forum on #PIN_SELECT is so
important.... |
|
|
|