Quantcast
Channel: Forums - Recent Threads
Viewing all articles
Browse latest Browse all 262198

Finding the end of a string being received UART

$
0
0

I am trying to write a programme where it is possible need to trasmit a string of numbers that can be from 1 to 3 digits long. How do I find out when the entire string has been sent and there are no more characters coming so once it's finished I can run the rest of the my code?

This is what my interrupt for receiving currently looks like,

#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{

		charData[++i] = UCA0RXBUF;

			if (menuLevel==1){
					UARTSendArray("Received command: ", 18);
					UARTSendArray(&charData[i], 1);
					UARTSendArray("\n\r", 2);
					modeToEdit=charData[1];
					menuLevel=2;
					i=0;
					UARTSendArray("Enter a value out of 100:", 25);
					UARTSendArray("\n\r", 2);
				} else if (menuLevel==2)
				{
					UARTSendArray("Received command: ", 18);
					for (j=1; j<4; j++)
					{
						intData[j]=charData[j];
						UARTSendArray(&charData[j], 1);
					}

					if (i=1)
					{
						dutyCycle[modeToEdit]=intData[1];
					} else if (i=2)
					{
						dutyCycle[modeToEdit]= concatenate(intData[1], intData[2]);
					}
					else
					{
						dutyCycle[modeToEdit]=100;
					}
					menuLevel=1;
					UARTSendArray("Please select which of the three modes you would like to edit: 1 2 or 3", 73);
					UARTSendArray("\n\r", 2);
				}

}

I was thinking of including an if statement that checks the status of the receive bit in the IFG2 flag. however I'm not entirely sure how the flag works and is set. Is the flag set 1 to whenever there's a charachter in the buffer to be read? Does it get set back to 0 when you read out of the buffer? If so when does it get set back to 0? I tried adding an if statement that said something like

if (~(IFG2&=UCA0RXIFG))

so if thebuffer is empty the flag is 0 so it will then pass the if statement, however this didn't work. Am I vaguely along the right lines? Any and all help is appreciated, let me know if you want the entire code for the programme for whatever reason or if you have any questions.


Viewing all articles
Browse latest Browse all 262198

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>