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

interfacing two ATmega16 microcontrollers

Discussion in 'AVR' started by garodriguez, Dec 3, 2007.

  1. garodriguez

    garodriguez New Member

    Joined:
    Dec 3, 2007
    Messages:
    2
    Likes:
    0
    I am doing a project where I need to transfer temperature readings from one microcontroller to another. The readings are obtained from a DS1820 digital thermometer. My goal is to first achieve this using serial communication and then wireless. Any ideas or suggestions on the C code will help a lot.
     
  2. simrantogether

    simrantogether New Member

    Joined:
    May 22, 2006
    Messages:
    433
    Likes:
    4
    Location:
    Bangalore
    Well...

    Well...

    wonderful...

    to interface two microcontrollers... you can follow either of the four things:

    1. interface the parallel ports... that is very simple just using the ribbon wire...

    2. interface it serially... just you have to program it to transfer data serially and another one to receive data serially...

    3. fiber optics: you can see one of the posts started by me as how we can do that...

    http://www.electro-tech-online.com/...face-microcontroller-with-fiber-optics.32000/

    4. wireless: use license free modules that work at 433 MHz for transferring of data...

    Regards,

    Simran..:)
     
  3. garodriguez

    garodriguez New Member

    Joined:
    Dec 3, 2007
    Messages:
    2
    Likes:
    0
    great

    the one that seems to work best for my purpose will be the serial transfer of data between microcontrollers. Unfortunetly, I am not a programming expert but I can tell you that Im using CodeVision AVR as my C compiler. If anybody can help me on starting with the programming I would really appreciate it.
     
  4. dave

    Dave New Member

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


     
  5. Sceadwian

    Sceadwian Banned

    Joined:
    Oct 27, 2006
    Messages:
    14,047
    Likes:
    141
    Location:
    Rochester, US

    Look into code that uses the SPI peripheral. A google search or browsing the code repository on AVRfreaks.net should get you started. SPI is extremely fast and it's a common serial bus. If you add an SPI wireless transmitter at a later time only minor code modifcations would be required.
     
  6. bibinjohn

    bibinjohn New Member

    Joined:
    May 7, 2006
    Messages:
    47
    Likes:
    0
    just connect rx of one uC to tx of another and vice versa. But if one uC should act as a master program then it will be easy. If you are searching for serial port interface, you can use this code
    /*----------------------------------------------------------------
    -----------------MAIN FUNCTION------------------------------------
    -----------------------------------------------------------------*/

    void main()
    {
    unsigned char a;
    //lcd initializationsa
    Init_Ports();

    InitUART( 25 ); /* Set the baudrate to 2400 bps using a 1MHz crystal */
    for(;;) /* Forever */
    {

    TransmitByte(0x99); /* Echo the received character */
    Receive_PORT=ReceiveByte();

    }
    }

    /*----------------------------------------------------------------
    ------------FUNCTIONS TO Initialize UART--------------------------
    -----------------------------------------------------------------*/

    void InitUART( unsigned char baudrate )
    {
    UBRRL = baudrate; /* Set the baud rate */
    UCSRB = (UCSRB | _BV(RXEN) | _BV(TXEN) ); /* Enable UART receiver and transmitter */
    }
    /*----------------------------------------------------------------
    ------------FUNCTIONS TO READ UART-------------------------------
    -----------------------------------------------------------------*/
    unsigned char ReceiveByte( void )
    {
    while ( !(UCSRA & (_BV(RXC))) ); /* Wait for incomming data */
    return UDR;/* Return the data */
    }

    /*----------------------------------------------------------------
    ------------FUNCTIONS TO WRITE UART-------------------------------
    -----------------------------------------------------------------*/
    void TransmitByte( unsigned char data )
    {
    while ( !(UCSRA & (_BV(UDRE))) ); /* Wait for empty transmit buffer */
    UDR = data; /* Start transmittion */
    }



    void Init_Ports(void)
    {
    Receive_DDR=0xFF; //setting that port for output
    Receive_PORT=0XFF; //setting all bits high for starting
    }

    For testing uart of uC you can use this link.
    http://avrmicrocontroller.googlepages.com/TestingUARTofAVRmicrocontroller.html
    See fuse bits to see which frequency you are running microcontroller

    Bibin John
    www.bibinjohn.tk
     
  7. suren123

    suren123 New Member

    Joined:
    Nov 9, 2011
    Messages:
    1
    Likes:
    0
    uart

    How to program for blinking a LED of second microcontroller by using first microcontroller.....i need your help.....thanks


    that LED i am controlling from first microcontroller.
     
  8. wkrug

    wkrug Active Member

    Joined:
    May 30, 2010
    Messages:
    280
    Likes:
    29
    Location:
    Germany
    I think the best way to do this, is to use the USART ( = serial connection ).
    When you want to extend that with wireless option you could use a BTM222 Bluetooth Module, that offers a wireless serial connection.
    Only a few further connections and an initialisation String for the BTM is required.
    When planning this connections at your startup schematic, it's only a thing of programming.
     
    Last edited: Nov 9, 2011

Share This Page