Hi,
Recently I had an issue that the UART interrupt was not reading the whole message from the sensor correctly but now that is fixed. However, at the time all processing was kept inside the ISR which is not good practice and I want to move that part out of the ISR into main loop by flicking the flag. Unfortunately, I seem to have an issue that the UART port starts reading junk (the data that is read, is always the same byte values). I suspected maybe memory leak, but all variables are cleared and memory for the pointers freed after every cycle, therefore I ran out of ideas what could be an issue. Note that in the code below UART0 will be used for reading initial message from the host but it is not being used atm. The variables z and l are just used to check how many loops have been made, this is where I get the number of 58 successful reads but after the 59th, it will always be junk data. The data from sensor comes in correct form all the time (checked by oscilloscope), thus the code for Tiva has to be an issue. I have TM4C123GXL.
This is the main loop:
int main(void) { ROM_FPUEnable(); ROM_FPULazyStackingEnable(); r_v.received_from_master = 0; reserve_memory_master(); clock_init(); gpio_init(); setting_up(); y = SysCtlClockGet()/1000; while(1) { reserve_memory(4); eeprom_write(); r_v.transmitCounter_sensor = 0; delayMs(16); //15ms delay at 50MHz request_config_data(); r_v.transmitCounter_sensor = 0; if(k==1) { master_transmit(); free(r_v.receiveUART_sensor); free(r_v.transmit_receiveUART_sensor); // free(r_v.receiveUART_master); k=0; z++; if(r_v.measure_array[0]!=0x40) { z=0; } memset(r_v.arr, 0, sizeof(r_v.arr)); memset(r_v.measure_array, 0, sizeof(r_v.measure_array)); ROM_UARTIntEnable(UART2_BASE, UART_INT_RX); } //delayMs(1); } }
This is the interrupt:
void UART2IntHandler(void) { uint32_t ui32Status; // Get the interrrupt status. // ui32Status = ROM_UARTIntStatus(UART2_BASE, true); // // Clear the asserted interrupts. // ROM_UARTIntClear(UART2_BASE, ui32Status); // // Loop while there are characters in the receive FIFO. // if(ui32Status & UART_INT_RX) { while(ROM_UARTCharsAvail(UART2_BASE)) { if(r_v.read_eeprom) { sensor_read(); r_v.read_eeprom = false; } else { measurements(); } } if(r_v.receiveCounter_sensor==r_v.sensor_receive_length) { r_v.receiveCounter_sensor=0; k=1; l++; ROM_UARTIntDisable(UART2_BASE, UART_INT_RX); } } }
Below are the images for read values. First one has correct value on loop counter 58 (the correct data does come correct at every loop prior this):
The second image is incorrect data read at 59th loop (all other readings after this point will have exact same value):