Hello
I am new to embedded programming and i have been trying to transfer a binary file and save it to flash memory using uart. The problem is that i do not know when to stop reading bytes from uart. That is because in my project the files do not have standard size , nor have a special char in the end. Is there any technique for this to be done. I am using keil compiler and a beautifully "datasheeted" c8051f320. The uart ISR for reading the file is the bellow:
INTERRUPT(Uart_Isr, INTERRUPT_UART0) { if(RI0 == 1 ){ LED = !LED; //Blink LED for each input RI0 = 0; //Reset the uart read flag byte = SBUF0; //Store byte read flashBuffer[buffer_counter] = byte; //save it to a FLASH buffer buffer_counter++; if(byte == 4){ //If End Of Transmition fileTransfered = 1; REN0 = 0; //Disable RX } } }
I also used a c script to write 0x4 (End of transmition byte or EOT) in the end of the files to be downloaded(weird but worked if the file had only char data).
Thank you in advance
P.S some more complex expressions dont seem to work , like flashBuffer[buffer_counter+] = SBUF0; Meaning that i get my code compiled but the program doesnt work