I do have interrupt.You enable interrupts - do you actually have any? I realize that we're looking a just a piece of the code but if you don't and you enable IRQs *boom*
- system ticks, and
- uart rx, this rx just receive char into a buffer untill CR is received, than flag it as ready. mainly for debug at this stage.
Code:
void interrupt ISR(void){
// timer2 interrupt, system tick
if (PIR1bits.TMR2IF == 1){
// clear interrupt flag
PIR1bits.TMR2IF = 0;
// increase ticks
systemTicks++;
}
// uart rx interrupt
if (PIR1bits.RCIF == 1){
// clear interrupt flag
PIR1bits.RCIF = 0;
// if error, clear them
if (RCSTAbits.FERR || RCSTAbits.OERR){
RCSTAbits.CREN = 0;
RCSTAbits.CREN = 1;
}
else{
// read data
static uint8_t data;
data = RCREG;
// if buffer is available
if (uartRXBuff.isReady == 0){
// if this is the end of a packet
if (data == '\r'){
uartRXBuff.isReady = 1;
}
else{
// check of overflow
if (uartRXBuff.ptr >= UART_RX_BUFF_LEN)
uartRXBuff.ptr = 0;
uartRXBuff.data[uartRXBuff.ptr++] = data;
}
}
}
}
}