maxsonar Ezo circuitary with atmega16

Status
Not open for further replies.
The sensor should send the distance in this format

"The output is an ASCII capital “R”, followed by three ASCII character
digits representing the range in inches up to a maximum of 255,
followed by a carriage return (ASCII 13)."

In your code you are reading only three characters when the sensor sends five. The first letter is 'R', that is followed by the distance value, and after that comes carriage return '\r'.

You said that the first value is correct.. I don't see how "001400140014cm" would be correct in any situation. I think you have your UART baudrate incorrect.
 
Try change the lines:

#define USART_BAUDRATE 4800
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1)

to

#define USART_BAUDRATE 9600
#define BAUD_PRESCALE (((F_CPU/16)/USART_BAUDRATE)-1)

Notice that I changed the both lines.
 
You have this line:

C:
	UCSRB |= (1<<RXCIE) | (1 << RXEN) | (1 << TXEN); // Turn on the transmission reception ..
	// circuitry and receiver interrupt

The RXCIE bit enables the "receive complete interrupt", but because you do not have that interrupt handler set up... the thing resets your microcontroller when data comes in!

change that line to:
C:
	UCSRB |= (1 << RXEN) | (1 << TXEN); // Turn on the TX and RX .. (You don't need TX)
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…