Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

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.

Latest threads

New Articles From Microcontroller Tips

Back
Top