1. 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.
    Dismiss Notice

maxsonar Ezo circuitary with atmega16

Discussion in 'AVR' started by jerry1234, Apr 19, 2013.

  1. jerry1234

    jerry1234 New Member

    Joined:
    Mar 9, 2013
    Messages:
    22
    Likes:
    0
    Distance:
    001400140014cm
     
  2. misterT

    misterT Well-Known Member Most Helpful Member

    Joined:
    Apr 19, 2010
    Messages:
    2,697
    Likes:
    368
    Location:
    Finland
    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.
     
  3. jerry1234

    jerry1234 New Member

    Joined:
    Mar 9, 2013
    Messages:
    22
    Likes:
    0
    hmmmmmm.....
    ok I WILL CHANGE THE BAUD RATE
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. misterT

    misterT Well-Known Member Most Helpful Member

    Joined:
    Apr 19, 2010
    Messages:
    2,697
    Likes:
    368
    Location:
    Finland

    It needs to be 9600.
     
  6. misterT

    misterT Well-Known Member Most Helpful Member

    Joined:
    Apr 19, 2010
    Messages:
    2,697
    Likes:
    368
    Location:
    Finland
    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.
     
  7. misterT

    misterT Well-Known Member Most Helpful Member

    Joined:
    Apr 19, 2010
    Messages:
    2,697
    Likes:
    368
    Location:
    Finland
    You have this line:

    Code (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:
    Code (C):

        UCSRB |= (1 << RXEN) | (1 << TXEN); // Turn on the TX and RX .. (You don't need TX)
     
     
    Last edited: Apr 24, 2013

Share This Page