c - MicroChip dsPic33, UART RX interrupt is not being called -
good afternoon,
i've configured rx interrupt using following simple function.
char c; void __attribute__((interrupt, no_auto_psv)) _u1rxinterrupt( void ) { ifs0bits.u1rxif = 0; // clear rx interrupt flag c = u1rxreg; }
the problem is, uart transmits fine, interrupt service routine never entered when gets sent character. can trace scope character sent without issues, interrupt not triggered.
the device used communication ttl-232r-3v3. device running @ 3.3v actual model number of dspic33 p33fj128mc802 programming environment mplab 8 , compiled xc16
is there missing setting perhaps enable interrupt? missing?
thanks, here uart initialization code.
u1modebits.uarten = 0; // bit15 tx, rx disabled, enable @ end of func u1modebits.usidl = 0; // bit13 continue in idle u1modebits.iren = 0; // bit12 no ir translation u1modebits.rtsmd = 0; // bit11 simplex mode u1modebits.uen = 0; // bits8,9 tx,rx enabled, cts,rts not u1modebits.wake = 0; // bit7 no wake (since don't sleep here) u1modebits.lpback = 0; // bit6 no loop u1modebits.abaud = 0; // bit5 no autobaud (would require sending '55') u1modebits.urxinv = 0; // bit4 idlestate = 1 (for dspic) u1modebits.brgh = 0; // bit3 16 clocks per bit period u1modebits.pdsel = 0; // bits1,2 8bit, no parity u1modebits.stsel = 0; // bit0 1 stop bit // u1brg = (fcy / (16 * baudrate)) - 1 // u1brg = (36850000 / (16 * 9600)) - 1 // u1brg = 238.908854 //round 239 u1brg = 239; u1stabits.utxisel1 = 0; //bit15 int when char transferred (1/2 config!) u1stabits.utxinv = 0; //bit14 n/a, irda config u1stabits.utxisel0 = 0; //bit13 other half of bit15 u1stabits.utxbrk = 0; //bit11 disabled u1stabits.utxen = 0; //bit10 tx pins controlled periph u1stabits.utxbf = 0; //bit9 *read bit* u1stabits.trmt = 0; //bit8 *read bit* u1stabits.urxisel = 0; //bits6,7 int. on character recieved u1stabits.adden = 0; //bit5 address detect disabled u1stabits.ridle = 0; //bit4 *read bit* u1stabits.perr = 0; //bit3 *read bit* u1stabits.ferr = 0; //bit2 *read bit* u1stabits.oerr = 0; //bit1 *read bit* u1stabits.urxda = 0; //bit0 *read bit* rpinr18bits.u1rxr = 0b00010;//7; //rx pin rp2 rpor1bits.rp3r = 0b00011; //tx pin rp3 u1modebits.uarten = 1; // , turn peripheral on u1stabits.utxen = 1;
check if pin has additional functionality. typically ad (analog pin). make sure turn off analog, via adp or ansel registers (type , number varies depending on exact chip) e.g. have routine (i use both 33f , 33e , high , low pincount 1 of both, hence ifdefs)
void analogoff(void){ #if defined(__dspic33f__) adpcfg =0xffff; ad1pcfgh=0xffff; ad1pcfgl=0xffff; #endif #if defined(__dspic33e__) #if !defined(__dspic33ep256mu806__) ansela=0; #endif anselb=0; anselc=0; anseld=0; ansele=0; anselg=0; #endif }
also, make absolutely sure oscillator , part's speed correct, though if tx has correct baudrate (scope!) ok.
my uart1 init:
u1brg = brgval; u1mode = 0x8000; // reset uart 8-n-1, alt pins, , enable lowspeed (=bit 3) u1modebits.usidl =0; // disable module when device idle. u1modebits.iren =0; // irda disable u1modebits.rtsmd =0; // flow control mode (1= simplex mode) u1modebits.uen =0; // rts en cts controlled portlatches u1modebits.wake =0; // no wakeup enabled; u1modebits.lpback=0; // loopback disabled u1modebits.abaud =0; // no autobaud #if !defined(__pic24f__) u1modebits.urxinv =0; // rxinv inversion rx. (0= idle = '1') #endif u1modebits.brgh =1; // high speed. u1modebits.pdsel =0; // 8 bit no parity u1modebits.stsel =0; // 1 stopbit. u1sta = 0x0440; u1stabits.urxisel0=0;// reset status register , enable tx & rx. u1stabits.urxisel1=0; // rx interrupt on char. _u1rxif=0; // clear uart rx interrupt flag _u1rxie = 1; // interruption active pour la reception _u1rxip=2; _u1txip=2; _u1txif=0; _u1txie=0; // enabled when sending u1modebits.uarten=1;
Comments
Post a Comment