Before logging an issue, please update to the latest release of Visual Micro from the Downloads Page.

When Logging a Support Issue in the Forum, please ensure you have also:-

  • Enabled vMicro > Compiler > Show Build Properties
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
  • Click the Reply button and attach as .txt file OR
  • Click here to Email us with the file attached, and a link to your post
Support requests without the output above may be impossible to answer, so please help us to help you
 
Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Trouble with terminal! (Read 6433 times)
Hawk_08
Newbies
*
Offline


Posts: 8
Location: Québec, Canada
Joined: Aug 25th, 2013
Trouble with terminal!
Sep 2nd, 2013 at 5:34pm
Print Post  
Hello everyone,

I am trying to detect a carriage return using the serial monitor input, but for some reason when I press 1 + enter it does not seems to detect my carriage return...

Here is the code I use both my function readUART and writeUART work perfectly fine, but not quite when i try to detect the end of my line.

Thank you in advance
M.

Code
Select All
#include <iom328p.h>
#include <io.h>
#include <interrupt.h>

#define xtal 16000000UL
#define baud 9600
#define UBRR_Value ((xtal / (baud * 16UL))) - 1

void setup_Usart(void){

	//Set-up Baudrate
	UBRR0 = UBRR_Value;

	//Enable Reception and Transmission
	UCSR0B |= (0 << RXCIE0) | (0 << TXCIE0) | (1 << RXEN0) |
		(1 << TXEN0);

	//Set-up Asynchronous, 8-bit, No Parity, Stop bit
	UCSR0C |= (0 << UMSEL00) | (0 << UMSEL01); //Asynchronous

	UCSR0C |= (1 << UCSZ01) | (1 << UCSZ00); //8-bit
	UCSR0B |= (0 << UCSZ02);

	UCSR0C |= (0 << UPM01) | (0 << UPM00); // No-Parity
	UCSR0C |= (0 << USBS0); // 1 end bit

	UDR0 = 0; //Make sure the UDR0 is empty

}

void writeUART(unsigned char data){
	while(!(UCSR0A & (1 << UDRE0))){
		//Wait for something to be transmitted
	}
	UDR0 = data;
}

unsigned char readUART(void){
	while(!(UCSR0A & (1 << RXC0))){
		//Wait for something to be read
	}
	return UDR0;
}

int main(void){

	int ptr=48; //Position pointer and counter for the array

	setup_Usart();
	//sei();

	while(1){

		//Lire un nombre entre 1 et 3 caractère
		while(!(readUART() & '\r')){
			writeUART(ptr);
			writeUART(0x0d);
			writeUART(0x0a);
			ptr++;
		}
	}
} 

  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12191
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Trouble with terminal!
Reply #1 - Sep 2nd, 2013 at 5:43pm
Print Post  
Hello, please confirm what you have set the liner terminator to in the serial monitor so that we can replicate the problem?

Thanks
  
Back to top
IP Logged
 
Hawk_08
Newbies
*
Offline


Posts: 8
Location: Québec, Canada
Joined: Aug 25th, 2013
Re: Trouble with terminal!
Reply #2 - Sep 2nd, 2013 at 5:46pm
Print Post  
Tim@Visual Micro wrote on Sep 2nd, 2013 at 5:43pm:
confirm what you have set the liner terminator to in the serial monitor so that we can replicate the problem


It is set to carriage return

M.
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12191
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Trouble with terminal!
Reply #3 - Sep 2nd, 2013 at 6:04pm
Print Post  
I have checked the code and it appears to be terminating correctly.

I'm no expert with micro controller c++ code or your hardware but is this right?

Code
Select All
while(!(readUART() & '\r')) 



should it be this?

Code
Select All
while(!(readUART() == '\r')) 

  
Back to top
IP Logged
 
Hawk_08
Newbies
*
Offline


Posts: 8
Location: Québec, Canada
Joined: Aug 25th, 2013
Re: Trouble with terminal!
Reply #4 - Sep 2nd, 2013 at 6:24pm
Print Post  
Thanks it worked for a single digit, but it brought an new one. But that may be my lack of understanding of the terminal

when I enter 3 numbers let's say '123' instead of printing only one line for one return key press it makes 3 return carriage like if I had entered the number separately. I also changed the setting to No line ending to make sure it was only one carriage return that i was sending

Thanks
M.
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12191
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Trouble with terminal!
Reply #5 - Sep 2nd, 2013 at 6:41pm
Print Post  
Not sure if I understand correctly. These might just be questions about how to code and better answered by all the clever people in micro controller forums.

It might be that I am missing the point and I assume you have changed your code slightly since your original example.

If I do understand you correctly you are saying that you send "123 RETURN" from the pc terminal to the micro controller. The pc terminal status display then shows "1 RETURN 2 RETURN 3 RETURN"?

The status box in the terminal only shows received data, it does not echo what it sends. Therefore this data would come from the micro controller. 

Your earlier example shows that the micro-controller sends a RETURN AND LINEFEED for every character received which would cause the effect you have described. 

Code
Select All
//Lire un nombre entre 1 et 3 caractère
		while(!(readUART() == '\r')){
			writeUART(ptr);
			writeUART(0x0d);
			writeUART(0x0a);
			ptr++;
		}
 


With the terminators outside of the loop this might become:-

Code
Select All
//Lire un nombre entre 1 et 3 caractère
		while(!(readUART() == '\r')){
			writeUART(ptr);
			ptr++;
		}
		writeUART(0x0d);
		writeUART(0x0a);
 

« Last Edit: Sep 5th, 2013 at 12:18am by Tim@Visual Micro »  
Back to top
IP Logged
 
Hawk_08
Newbies
*
Offline


Posts: 8
Location: Québec, Canada
Joined: Aug 25th, 2013
Re: Trouble with terminal!
Reply #6 - Sep 2nd, 2013 at 7:13pm
Print Post  
Thank you for your help!

M.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint