unsigned int getsUART3(unsigned int length,unsigned int *buffer, unsigned int uart_data_wait) { int wait = 0; char *temp_ptr = (char *) buffer; while(length) /* read till length is 0 */ { while(!DataRdyUART3()) { if(wait < uart_data_wait) wait++ ; /*wait for more data */ else return(length); /*Time out- Return words/bytes to be read */ } wait=0; if(U3MODEbits.PDSEL == 3) /* check if TX/RX is 8bits or 9bits */ *buffer++ = U3RXREG; /* data word from HW buffer to SW buffer */ else *temp_ptr++ = U3RXREG & 0xFF; /* data byte from HW buffer to SW buffer */ length--; } return(length); /* number of data yet to be received i.e.,0 */ }
// UART3 RX ISR void __attribute__ ((interrupt,no_auto_psv)) _U3RXInterrupt(void) { // Clear the interrupt status of UART1 RX U3RX_Clear_Intr_Status_Bit; if(DataRdyUART3()) { incoming_char = ReadUART3(); // Get the character coming from USB UART while(BusyUART1()); WriteUART1(incoming_char); // Send the character to the GSM UART while(BusyUART3()); WriteUART3(incoming_char); // Send the character to the USB UART } }