View previous topic :: View next topic |
Author |
Message |
Micronet666
Joined: 28 Aug 2019 Posts: 5
|
interrupts UART2 of pic18f46k42 no work |
Posted: Wed Aug 28, 2019 8:22 am |
|
|
Regards, I am programming pic 18f46k42, using UART1 and UART2, but UART2 does not generate interruption when it comes to data.
Code: |
#pin_select U1TX=pin_C6
#pin_select U1RX=pin_C7
#use rs232(baud=9600,UART1,parity=N,restart_wdt,disable_ints,stream=ETHER,ERRORS) //INT_RDA->Puerto de red UART1
#pin_select U2TX=pin_D3
#pin_select U2RX=pin_D0
#use rs232(baud=9600,UART2,parity=N,bits=8,restart_wdt,disable_ints,stream=SLAVE,ERRORS) //INT_RDA2->Puerto de sincronismo UART2 |
I need to configure something else ? Thank you very much for your help. _________________ Programmer Microcontroller
Last edited by Micronet666 on Wed Aug 28, 2019 4:20 pm; edited 1 time in total |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Aug 28, 2019 1:21 pm |
|
|
1. Post a complete test program that shows your use of RDA2. This
means show the isr routine, show the enable_interrrupts() line in main(),
and the #use delay(), etc.
2. Post your CCS compiler version. It's a 4-digit number given at the top
of the .LST file. The .LST file will be in your project directory after you
compile a program with no errors. Example of version numbers:
http://www.ccsinfo.com/devices.php?page=versioninfo |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19510
|
|
Posted: Wed Aug 28, 2019 1:26 pm |
|
|
I also would try without DISABLE_INTS. This shouldn't do anything with
a hardware UART. Last time I looked it didn't actually change the code
at all when the hardware UART is used, but you definitely don't want
to 'disable interrupts', if you are trying to use them!... |
|
|
Micronet666
Joined: 28 Aug 2019 Posts: 5
|
|
Posted: Wed Aug 28, 2019 2:36 pm |
|
|
This is the code I use, UART2 does not generate interruption when I send a character.
CCS PCH C Compiler, Version 5.076, xxxxx
Code: |
#include <18F46K42.h>
//#device *=16
//#ZERO_RAM
#fuses NOEXTOSC //Oscillator external is not enabled
#fuses RSTOSC_HFINTRC_1MHZ //HFINTOSC with HFFRQ = 4 MHz and CDIV = 4:1
#fuses NOCLKOUT //CLKOUT function is disabled; I/O or oscillator function on OSC2
#fuses NOPRLOCK1WAY //bit can be set and cleared multiple times (subject to the unlock sequence)
#fuses CKS
#fuses NOFCMEN
#fuses MCLR
#fuses NOPUT
#fuses NOMVECEN
#fuses NOIVT1WAY
#fuses NOLPBOR
#fuses NOBROWNOUT
#fuses BORV28
#fuses NOZCDDIS
#fuses NOPPS1WAY
#fuses STVREN
#fuses NODEBUG
#fuses NOXINST
#fuses WDT64
#fuses NOWDT
#fuses NOLVP
#FUSES PROTECT
#use delay(INTERNAL=16M)
#byte ANSELC=getenv("SFR:ANSELC")
#byte ANSELD=getenv("SFR:ANSELD")
#pin_select TX2=pin_D3
#pin_select RX2=pin_D0
#use rs232(baud=9600,UART2,stream=RED2,ERRORS)
#priority rda2
#INT_RDA2
void isr_rda2(){
char c;
c=Fgetc(RED2);
Fputc(c,RED2);
}
void main(){
int m;
setup_oscillator(OSC_HFINTRC_ENABLED |OSC_HFINTRC_16MHZ);
setup_uart(TRUE,RED2);
ANSELC=0;
ANSELD=0;
set_tris_a(0);
set_tris_b(15);
Set_tris_c(135);
set_tris_d(1);
set_tris_e(0);
port_b_pullups(15);
enable_interrupts(int_rda2);
enable_interrupts(GLOBAL);
while(true){
}
}
|
_________________ Programmer Microcontroller
Last edited by Micronet666 on Wed Aug 28, 2019 4:19 pm; edited 2 times in total |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Aug 28, 2019 3:13 pm |
|
|
One ominous observation is that vs. 5.076 is the first version that
supported the 18F47K42. I can compare the code between that vs.
and the current vs. 5.088, but it wouldn't surprise me if there are bugs. |
|
|
Micronet666
Joined: 28 Aug 2019 Posts: 5
|
|
Posted: Wed Aug 28, 2019 3:26 pm |
|
|
if it seems to be a bug, because uart1 works normal with default pins, but uart2 I am assigning pins PIN_D3 and PIN_D0 and it is the one that does not respond to the interruption.
the pic is the 18f46k42 _________________ Programmer Microcontroller |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Wed Aug 28, 2019 3:32 pm |
|
|
Maybe delete the trisx(yyy); lines
Though it may not affect operation, I can't decode decimal into binary too easily.
When using function like Tris, I use binary as it's EASY to lookup the SFR and see what bits are set and cleared.
Also when using 2 UARTs, you should preface the echoing data, say 'from UART #2, ...data....' just so you KNOW where it's from. You could have a hardwre issue ( crossed wires) and wonder why UART1 doesn't work when really it's a UART #2 problem...
Just an observation from an old guy....
Jay |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Aug 29, 2019 12:07 am |
|
|
I used ExamDiff to compare the .LST file code between vs. 5.076 and
vs. 5.085. The #INT_RDA2 code is the same. But there were other
differences as noted below.
Vs. 5.085 (Presumably working code):
Code: |
.................... #use rs232(baud=9600,UART2,stream=RED2,ERRORS)
// UART2 read byte routine:
00062: MOVLB 39
00064: BTFSS xA6.2 // Skip next instruction if PIR6.U2RXIF = 1
00066: BRA 0064 // Wait in loop until bit = 1
00068: MOVLB 3D
0006A: MOVF xE1,W // U2ERRIR ==> W register
0006C: MOVWF 19 // W ==> 0x19
0006E: MOVF xD0,W // U2RXB ==> W (Return W to the caller)
00070: MOVWF 01
00072: BTFSS 19.1 // Did Fifo Overflow occur ?
00074: BRA 007C // If not, jump to exit. If so, flush rcv buffer
00076: BCF xDA.4 // U2CON0.RXEN = 0
00078: BSF xDF.1 // U2FIFO.RXBE = 1 (Flush the receive buffer)
0007A: BSF xDA.4 // U2CON0.RXEN = 1
0007C: MOVLB 0
0007E: GOTO 0096 (RETURN)
// UART2 write byte routine:
00082: MOVLB 39
00084: BTFSS xA6.3 // Skip next instruction if U2TXIF bit = 1
00086: BRA 0084
00088: MOVLB 3D
0008A: MOVWF xD2 // W ==> U2TXB register
0008C: MOVLB 0
0008E: GOTO 009E (RETURN)
|
Vs. 5.076, with differences from above shown in bold, with comments:
Quote: |
.................... #use rs232(baud=9600,UART2,stream=RED2,ERRORS)
00062: MOVLB 39
00064: BTFSS xA6.2
00066: BRA 0064
00068: MOVLB 3D
0006A: MOVF xC9,W // 0x3DC9 is a non-existent register
0006C: MOVWF 19
0006E: MOVF xB8,W // 0x3DB8 is a non-existent register
00070: MOVWF 01
00072: BTFSS 19.1
00074: BRA 007C
00076: BCF xC2.4 // 0x3DC2 is a non-existent register
00078: BSF xC7.1 // 0x3DC7 is a non-existent register
0007A: BSF xC2.4 // 0x3DC2 is a non-existent register
0007C: MOVLB 0
0007E: GOTO 0096 (RETURN)
00082: MOVLB 39
00084: BTFSS xA6.3
00086: BRA 0084
00088: MOVLB 3D
0008A: MOVWF xBA // 0x3DBA is a non-existent register
0008C: MOVLB 0
0008E: GOTO 009E (RETURN)
|
-------------------------------------------------
Vs. 5.085 (Presumably working code):
Code: | .................... setup_uart(TRUE,RED2);
0012E: MOVLB 3D
00130: BSF xDB.7 // Set U2CON1.ON bit
00132: BSF xDA.4 // Set U2CON0.RXEN bit
00134: BSF xDA.5 // Set U2CON1.TXEN bit
|
Vs. 5.076 with differences from above marked in bold, with comments:
Quote: |
.................... setup_uart(TRUE,RED2);
0012E: MOVLB 3D
00130: BSF xC3.7 // 0x3DC3 is a non-existent register
00132: BSF xC2.4 // 0x3DC2 is a non-existent register
00134: BSF xC2.5 // 0x3DC2 is a non-existent register
|
----------------------------------------------
Vs. 5.085 - a portion of the startup code at the beginning of main():
Code: |
000E6: BCF 3FC5.3 // TRISD.3 = 0
000E8: BSF 3FBD.3 // LATD.3 = 0
000EA: MOVLB 3D
000EC: BCF xDB.7 // U2CON1.7 = 0
000EE: MOVLW B0
000F0: MOVWF xDA // U2CON0 = 0xB0
000F2: MOVLW 01
000F4: MOVWF xDE // U2BRGH = 0x01
000F6: MOVLW A0
000F8: MOVWF xDD // U2BRGL = 0xA0
000FA: CLRF xDC // U2CON2 = 0x00
000FC: BSF xDB.7
|
Vs. 5.076 startup code:
Quote: |
000E6: MOVLB 3D
000E8: BCF xC3.7 // 0x3DC3 is a non-existent register
000EA: MOVLW B0
000EC: MOVWF xC2 // 0x3DC2 is a non-existent register
000EE: MOVLW 01
000F0: MOVWF xC6 // 0x3DC6 is a non-existent register
000F2: MOVLW A0
000F4: MOVWF xC5 // 0x3DC5 is a non-existent register
000F6: CLRF xC4 // 0x3DC4 is a non-existent register
000F8: BSF xC3.7 // 0x3DC3 is a non-existent register
|
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19510
|
|
Posted: Thu Aug 29, 2019 2:56 am |
|
|
Thanks PCM.
To the original poster.
Looks as if your compiler version has the wrong register addresses for UART2.
Do you have just the compiler or the IDE?.
If you have the IDE and generate the register list, what is 'odd', is that
this is right. Does not talk to the wrong registers.
Talk to CCS. They will probably do you an updated DLL to fix this. I've had
similar issues in the past, |
|
|
Micronet666
Joined: 28 Aug 2019 Posts: 5
|
|
Posted: Thu Aug 29, 2019 5:38 am |
|
|
Greetings.
In the compiler I found errors in the description of the fuses, they do not match what each fuse means.
In a version of a friend, compile with the CCS version PCH C Compiler, Version 5.083, and configuring the ports has worked!
I have configured the ports with the following functions
Code: |
set_input_level_x(0);
set_open_drain_x(0);
set_slow_slew_x(0);
|
_________________ Programmer Microcontroller |
|
|
nickbd
Joined: 12 Jun 2013 Posts: 7
|
Port D on 46K42 doesn't have interrupts |
Posted: Sun Jan 05, 2020 12:05 pm |
|
|
Maybe I missed something but on the 18F46K42 Port D doesn't have any interrupts. The first UART in the original example is on C6, C7 so is a hardware UART so has built in interrupt but for the second UART this must be a software interrupt and according to the CCS example ex_rs232_buffer.c to use the buffer you have to use an external interrupt so I think INT0, INT1 or INT2 or pins B0, B1, B2. These are PPS remappable but not sure whether you can or how to do that. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19510
|
|
Posted: Sun Jan 05, 2020 12:15 pm |
|
|
No, Nick. He is using the hardware UART2, but mapping this to port D
using PPS. This UART has an interrupt.
With a modern compiler, and the drive/slew configured he has it working. |
|
|
nickbd
Joined: 12 Jun 2013 Posts: 7
|
|
Posted: Sun Jan 05, 2020 2:27 pm |
|
|
Oh, OK. Thanks! I hadn't looked down to see the pin_select for RX2, TX2. I want to have a 3rd UART so software UART (I am using both HW UARTs) but also using a buffer and hence need to use external interrupt. So can the INTx be remapped to one of the port D pins to use for the RX for the software UART? In the specs it says they can. Just not that familiar with the PPS remapping. Thanks Nick |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19510
|
|
Posted: Mon Jan 06, 2020 12:25 am |
|
|
What baud rate?
Problem is that using an ext interrupt to trigger a software RX, results
in the code having to sit in the interrupt handler for the whole character
receive time. Now this gives lots of issues. Any transmit will be stopped
while the receive is occuring (so half duplex only), and possible timing
issues with other interrupts. Generally not a good idea.
Now it can work OK, if the serial channel is significantly the fastest comm
channel, and is half duplex only. Generally not a good solution.
No. Look at table 17-1 in the data sheet 'PPS INPUT REGISTER DETAILS'.
You will see that the INT signals can generally only go to Port A or B.
Only INT1 can be routed to Port D, and only on the 55/56 chips, not the
46.
I posted a while ago, a demo RX using a timer interrupt as an alternative
way of doing this. A search should find it.
Edit:
The thread is here:
<http://www.ccsinfo.com/forum/viewtopic.php?t=39958&highlight=software+rs232+disturbed+interrupts> |
|
|
|