EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Topics / TWI doesnt generate interrupt in slave mode, using micro Atmega32

TWI doesnt generate interrupt in slave mode, using micro Atmega32

|

Microcontroller › AVR › TWI doesnt generate interrupt in slave mode, using micro Atmega32

  • This topic has 2 replies, 3 voices, and was last updated 11 years, 7 months ago by Ashutosh Bhatt.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • August 4, 2014 at 4:29 pm #3205
    Mojtaba
    Participant

    Hi all, I try to have communicate between two Atmega32. at first master should send zero to the slave, the code is:
    start:
             senddata=0;
             address=10;
             master_transmitter(senddata,address);

    void master_transmitter(unsigned char senddata1,unsigned char address1)
    {
        TWCR=0b10100100;                                  //start condition
        while(!(TWCR &(0b10000000)));                      //wait for TWINT flag
        if((TWSR & 0xF8)==0x08 || (TWSR & 0xF8)==0x10)  //check TWSR
            {
                TWDR=((address1 << 1) & (0xFE));          //send SLA+W
                TWCR=0b10000100;
                while(!(TWCR & (0b10000000)));
            }
        if((TWSR & 0xF8)==0x18)
            {
                TWDR=senddata1;
                TWCR=0b10000100;
                while(!(TWCR & (0b10000000)));
            }
            TWCR=0b10010100;    //stop condition
    }

    and the slave code is:

    start:
    TWSR=0x00;
    TWCR=0x45;
    #asm(“sei”)
    while(1)
        {
            if(receiveddata==0)
                {
            [do something]
            }
         }

    interrupt [TWI] void twi_isr(void)
    {
        unsigned char Sreg;
        Sreg=TWSR;
        switch(Sreg)
            {
                case 0x90:
                    receiveddata=TWDR;
                    sprintf(buff,”global:%d”,receiveddata);
                    lcd_puts(buff);
                    break;
                case 0x98:
                    TWCR=0b10000000;
                    break;
                case 0x80:
                    receiveddata=TWDR;
                    break;
                case 0xA8:
                    TWDR=sendeddata;
                    TWCR=TWCR|(0b10000000);
                    break;
                    
            }
            TWCR|=(0b10000000);
    }

    but I found that there isnt any interrupt in the slave when the master send zero to it! I really confused whit this! please help me.
     

    August 6, 2014 at 4:15 am #11984
    AJISH ALFRED
    Participant

    Hi Mojtaba,

    In TWI the start and stop bits have some speciality than other bits. They happen when the clock is enabled, while the data bits happen when the clock is disabled. Suggest you to learn the TWI in more detail and check it with your code.

    August 19, 2014 at 9:30 am #12037
    Ashutosh Bhatt
    Participant

    follow the tutorial on TWI given for AVR micro controller on

    EG labs / micro controller / AVR

  • Author
    Posts
Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • isolating S-params in of PCB board without connectors April 11, 2026
  • Assistance locating a 'trail' camera gadget, please ? April 10, 2026
  • Raise your hand if your car had one of these: April 10, 2026
  • Some opamp advice please April 10, 2026
  • Voltage comparator circuit verification April 10, 2026

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2026 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise