|
|
View previous topic :: View next topic |
Author |
Message |
charliumi
Joined: 03 Nov 2016 Posts: 11
|
PIC24FJ256GB406 - UART RX no Interrupt |
Posted: Sun Jan 01, 2017 5:26 pm |
|
|
I'm trying to enable bi-dir communication between XBEE module and PIC24FJ256GB406. it works fine with several others component (PIC16 and PIC18) but cannot make it work with PIC24FJ. With the PIC24FJ256GB406, the TX works fine but there's no interrupt triggered on the PIC upon reception on RX.
I found one inconsistency between PIC24 documentation and CCS compiler and really looking for guidance. According to the PIC24FJ256GB406 documentation, UART5_TX is on PIN_D1 and UART5_RX is on PIN_D6. However, When I tried to configure the #pin_select U1RX=PIN_D6, I go an error message from the compiler, which looks inconsistent.
I tried 2 options:
Option1: a board with XBEE connected to PIN_D1(TX) and PIN_D6(RX) and a software UART configuration.
Code: |
#use rs232(UART1, baud=57600, xmit=PIN_D1, rcv=PIN_D6, RESTART_WDT, ERRORS, stream=XBEE)
main()
..
enable_interrupts(INT_RDA);
enable_interrupts(INTR_GLOBAL);
|
Option2: a board with XBEE connected to PIN_D1(TX) and PIN_D5(RX) and a hardware UART configuration:
Code: |
#pin_select U1TX=PIN_D1
#pin_select U1RX=PIN_D5
#use rs232(UART1, baud=57600, RESTART_WDT, ERRORS, stream=XBEE)
main()
..
enable_interrupts(INT_RDA);
enable_interrupts(INTR_GLOBAL);
|
I have consistent behavior with both Options: TX works fine and RX doesn't interrupt. I validated with an oscilloscope that XBEE is sending data to the PIC.
I'm using the latest version (5.066) of the compiler.
I'm clueless, Any ideas ?
Thanks |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9229 Location: Greensville,Ontario
|
|
Posted: Sun Jan 01, 2017 5:51 pm |
|
|
I don't use that PIC but..
have you tried just a 'getc(...)' type of code to confirm that data IS getting to the correct PIC pin ? a basic program, wait for a character, display on LCD or send back to PC ?
IE: a non interrrupt program ?
Just because a scope 'shows' the Xbee is sending doesn't mean it got 'into' the PIC....
Jay |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1349
|
|
Posted: Sun Jan 01, 2017 5:55 pm |
|
|
Why try to assign UART5 to UART1? You should stick with UART5
I would recommend:
Code: |
#use rs232(UART5, baud=57600, ERRORS, stream=XBEE)
|
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Mon Jan 02, 2017 12:28 am |
|
|
Have to agree with Temtronic's comment.
The pins you are using have Schmitt input levels. Require the signal to go up to 0.65*Vdd. Depending on the supply voltage you are using, and your wiring, your module may well not be taking the signals high enough..... |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Mon Jan 02, 2017 9:50 am |
|
|
Going through:
Code: |
#use rs232(UART1, baud=57600, xmit=PIN_D1, rcv=PIN_D6, RESTART_WDT, ERRORS, stream=XBEE)
main()
..
enable_interrupts(INT_RDA);
enable_interrupts(INTR_GLOBAL);
|
Won't work. You are trying to say to use a hardware UART and also define the pins. You have to have selected the pins first. Look at the sticky at the start of the forum.
The compiler should complain here.
Code: |
#pin_select U1TX=PIN_D1
#pin_select U1RX=PIN_D5
#use rs232(UART1, baud=57600, RESTART_WDT, ERRORS, stream=XBEE)
main()
..
enable_interrupts(INT_RDA);
enable_interrupts(INTR_GLOBAL);
|
This will work, but only if you disable the LCD. By default this is mapped at SEG24. If you look at the pin function table for this pin:
SEG24/RP20/PMRD/PMWR/RD5
Devices have priority 'left to right'. On the TX pin, changing the TRIS overrides this, but on the receive pin it doesn't.
However as Jeremiah says it does seem insane to map the relocatable UART to use one of the same pins as already used by UART5. Use the #USE as he posts, INT_RDA5, connect the input signal to D6, instead of D5, and disable the LCD at the start of your code. INT_RDA5, is now available (it was missing a few compiler versions ago, but CCS fixed this).
It might well also be worth adding a pullup resistor on the RX line to help ensure the signal does get high enough to trigger the UART. Perhaps 2K2R. |
|
|
|
|
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
|