Communicating dsPIC with PC application through UART. Receiver interrupt handling -
i'm communicating c# applications dspic x16 microcontroller using uart. want send/receive fixed size frames , tried manage in following way:
if(readframe) { iec0bits.u1rxie=0; //turn off u1rx interrupts readframe = false; while(indexer < 8 ) { while(!u1stabits.urxda); modbusbuffer[indexer]=u1rxreg; indexer++; } if(indexer == 8) { modbusrecvtask(modbusbuffer); indexer=0; } iec0bits.u1rxie=1; //turn on u1rx interrupts } void _isr_nap _u1rxinterrupt() { if(ifs0bits.u1rxif) { ifs0bits.u1rxif = 0; //set interrupt flag false if(u1stabits.oerr==1) //check overload error { u1stabits.oerr=0; //clear error flag } else { readframe = true; } }
}
the thing works fine first received frame. after program goes receiver interrupt again , sets flag readframe true though no bytes send , getting stuck in line:
while(!u1stabits.urxda);
i've read advices clear read buffer of uart in order prevent program go isr again couldn't find way it.
Comments
Post a Comment