Electronic – AVR USART wait for AVR’s reponse to continue text stream

atmegaavrcommunicationdataterminal

AVR USART wait for AVR's reponse to continue protocol

I am doing a senior project, and I need to send a large text file line by line to an AVR (atmega32) which will control a piano using ~36 solenoids and shift registers. This needs to be done automatically and very fast. I cannot mannually input the text in the terminal. I need to send 3 strings, line by line to an AVR and wait between each line for a confirmation to continue form the AVR.

  • The text file is a converted midi file which contains 3 usefull information (the time of the event, the note, and the status (press note or unpress). The text file looks like this:

    213, 25, ON
    321, 25, OFF
    521, 36, ON –> which represents play the Note C at time = 521 ms

Where the first string is the time of the event, the second is the note and the third is the status of the note

The protocol would need to look like this:

  • The PC sends 3 string to the AVR. So total of 3 USART transfers.
  • The PC waits for AVR to send an aknowledgement to continue transfering the next line of text
  • The AVR plays the "event" on the piano and at the end send a confirmation to the PC to send the next lines of text

How is this achievable?

Why am I doing this?

The problem is that I can't store all the text file in an array of because the AVR is too small(the largest atmega is 512Kb if I recall well)
I need to stream the text file using the terminal (Hyperterminal) line by line.
BUT how to send a line using the terminal, wait until the atmega finished the process –> send a confirmation back to the PC to stream the next line?

Best Answer

What you need is "flow control" or "handshaking".

For USART, you can use hardware flow control with RTS/CTS, but many USART implementations today omit them. If you've finished you hardware and without these pins connected, you may try "software flow control" with "XON/XOFF", because these two codes won't appear in your text file (they are non-printable character). So use them as flow control is possible. But compared to hardware flow control, the later may be a little slower.

The main limitation with you it's your MCU is not strong enough to handle the entire file, so parse the file on PC end is reasonable.

If you don't want to dive into a complicated USART programm on PC, you can try Tera Term, an open-source, programmable, handy "Hyperterminal" killer.