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
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. (re)start a timer in the UART ISR when it times out you are done. Make the time long there may be pauses in the transmission.
This is a kludge, the correct way is to make the EOR detectable.
Erik
Thank you for the quick reply. That is indeed a nice solution. What do you mean by saying to make EOR detectable? Also(that is a bit off topic) my project is to run code to an mCU downloaded from uart using a binary file. Is there a standard technique for that? I have read about code banking and bootstrapping but i only see complicated stuff. I just want to do a JUMP to the address where the file is saved and continue running code from there.
Furthermore , i managed to use RTX tiny from keil. I figured that an rtos would be usefull for such a project. Is that correct?
"Is that correct?"
For what you've described so far, it's probably more trouble than it's worth!
... when it is REALLY needed and the processor has the needed power.
a RTOS should not be an automatic decision, at least not when working with the '51.