View previous topic :: View next topic |
Author |
Message |
milops3
Joined: 10 May 2012 Posts: 3
|
How to activate a hardware UART on PIC24FJ64GA004 |
Posted: Tue Aug 07, 2012 7:26 am |
|
|
Hello
PIC24FJ64GA004
version 4.130
PIC24 -> PICkit2 UART Tool -> PC
Code: |
#INCLUDE <24FJ64GA004.h>
#INCLUDE <string.h>
#INCLUDE <stdlib.h>
#FUSES NOWDT
#FUSES NOJTAG
#FUSES NOPROTECT
#FUSES NOWRT
#FUSES NODEBUG
#FUSES IOL1WAY
#FUSES NOWINDIS
#FUSES WPOSTS16
#FUSES IESO
#FUSES FRC_PLL//_PS//
#FUSES NOCKSFSM
#FUSES NOOSCIO
#FUSES HS
#use delay(clock=32000000)
//***************************************************************
#Pin_select U1TX=PIN_B13
#Pin_select U1RX=PIN_B12
#use rs232(baud=9600,ERRORS)
//***************************************************************
#INT_RDA
void serial_isr()
{
unsigned char i;
i=getc();
putc(i);
}
//***************************************************************
void main()
{
setup_oscillator(OSC_INTERNAL);
delay_ms(2000);
OUTPUT_high(PIN_A0);
CLEAR_INTERRUPT(INT_RDA);
ENABLE_INTERRUPTS(INT_RDA);
ENABLE_INTERRUPTS(INTR_GLOBAL);
while(true);
} |
I need to use interrupt received by the UART, but it does not work. It is only software UART, UART hardware is not turned on. How to activate and to use hardware UART interrupt?
(This code works with interrupt on the PIC18f2320).
I have connected good. This code works
Code: |
void main()
{
unsigned char i;
setup_oscillator(OSC_INTERNAL);
OUTPUT_high(PIN_A0);
while(true)
{
i=getc();
putc(i);
}
} |
Excuse my English. Use a compiler. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Tue Aug 07, 2012 11:22 am |
|
|
Code: |
#Pin_select U1TX=PIN_B13
#Pin_select U1RX=PIN_B12
#use rs232(UART1,baud=9600,ERRORS)
|
Best Wishes |
|
|
milops3
Joined: 10 May 2012 Posts: 3
|
|
Posted: Wed Aug 08, 2012 2:31 am |
|
|
Yes, work it
I used the "STREAM=UART1 "
in help is written
Quote: | UART1 Sets the XMIT= and RCV= to the chips first hardware UART
| I understood it wrong
thank you very much |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Wed Aug 08, 2012 4:57 am |
|
|
It is slightly confusing, on chips with peripheral remapping like this.
'UART1', basically tells the #use RS232 to talk to the UART hardware. Normally (on chips with fixed I/O pins), you can get the same result by selecting TX= and RX= with the pins matching the fixed peripheral pins.
On the chips with re-mappable pins, you have to do the two separate operations, tell #use RS232, to talk to the UART hardware (hence UART1, or UART2), and then use #pin select to actually specify what pins this hardware is to use.
Best Wishes |
|
|
|