naughty_mark
Joined: 29 Aug 2012 Posts: 97
|
UART RX interrupt problem |
Posted: Mon Sep 03, 2012 1:05 am |
|
|
Hi, there
I come back again with a new problem
I declared a RS232 port and declared a receive interrupt for it. However, once I sent character to micro, it will jump into the default interruption code, which means the code can not find the UART1 RX interruption I defined!
I attach my code below
Code: |
#if defined(__PCD__)
#include <33EP256MU814.h>
//#include <i2c.h>
#fuses HS,PR,NOWDT,ICSP2
//CKSFSM -enable oscillator clock switching mode when a OSC failure has occurred.
//#build (stack=256)
//#build (stack=0x1E00:0x1FFF)
#device ADC=12
#use delay(clock=20000000) // Actual crystal is 20M
#pin_select U1TX = PIN_D0
#pin_select U1RX = PIN_D1
#pin_select U2TX = PIN_D2
#pin_select U2RX = PIN_D3
#use RS232(UART1, /*STREAM = GSM, */BAUD=9600, /*XMIT = PIN_D0 , RCV = PIN_D1 , */BITS = 8, STOP = 1, PARITY = N, ERRORS) // Actual Baud is 38400 due to clock (10M not 20M)
//#use RS232(UART2, STREAM = MODBUS, BAUD=9600, XMIT = PIN_D2 , RCV = PIN_D3 , BITS = 8, STOP = 1, PARITY = N, ERRORS) // Actual Baud is 38400 due to clock (10M not 20M)
//#use spi(MASTER, DO = PIN_G8, CLK = PIN_G6, mode = 3, stream=SPI_STREAM)
#use i2c(MASTER, I2C1,SCL = PIN_D10, SDA = PIN_D9 , FORCE_SW)
#pin_select IC1=PIN_F0
#pin_select C1TX = PIN_D6
#pin_select C1RX = PIN_D5
#endif
|
and for UART1 RX interrupt
Code: |
#INT_RDA
void RDA_isr() // BYTE RECEIVED
{
char tmp;
output_low(PIN_J10);
tmp = getc();
recv[next_RS232_in] = tmp;
next_RS232_in ++;
testDone = TRUE;
clear_interrupt(INT_RDA);
}
|
In my main function, I code
Code: | clear_interrupt(INT_RDA);
enable_interrupts(INT_RDA);
ENABLE_INTERRUPTS(INTR_GLOBAL);
|
to enable the interrupt. Any comments?
Before I declare RS232 like
Code: |
#use RS232(UART1A, BAUD=9600, XMIT = PIN_D0 , RCV = PIN_D1 , BITS = 8, STOP = 1, PARITY = N, ERRORS)
|
without declare its RX and TX pins in advance, and that one can send char to PC, but can not generate RX interrupt at all (even no default interrupt).
Any comments on it? Thanks a lot!
Regards
Mark |
|
naughty_mark
Joined: 29 Aug 2012 Posts: 97
|
|
Posted: Mon Sep 03, 2012 4:00 pm |
|
|
asmboy wrote: | Quote: |
// forget temp and add arg for your stream??
recv[next_RS232_in++] = getc(UART1);
// above index is no wrap protect?? -mem corruption issue ??
// clear_interrupt(INT_RDA);NOT REQ since CCS adds for you @ exit
|
|
Thanks asmboy
I got it, because I didn't include the interrupt header file in the main function so the program can not find RDA interrupt code.. Sorry for my STUPID~~~
Anyway, thanks |
|