ATmega4809 TWI

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello,
i am looking for an example of TWI usage as a master. I do not want to use the code from the MCC or Atmel start, because I find the overloaded. Unfortunately, no application note has yet been published. I had already used it on the ATxmega128. But the controllers are very different. So if anyone has an example ....

 

With my Code, TWI hangs after one Read, it sends no Acknowledge.

Greeting Sascha

Attachment(s): 

Last Edited: Mon. May 13, 2019 - 05:14 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Have look my code in projects and explanation here:
https://www.avrfreaks.net/comment/2677376#comment-2677376
Maybe it helps.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

But the code attached in the first message, comes from it. For example, if I read 32 bytes TWI_Read in a row to read 32 bytes, it works. However,

as soon as i loop through them to store the bytes one at a time after transmission, the master will not give an acknowledgment after the first byte

received, as shown in the picture. Looks like a timeout for me somehow, though switched off.

 

Greeting Sascha

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

sascha_focus wrote:
, if I read 32 bytes TWI_Read in a row to read 32 bytes, it works

Are you NACK'ing the last byte read?  if not the slave is waiting for the master to request more data!

When you read 32 bytes from the slave, the master should ACK the first 31 bytes, then NACK the last byte, this tells the slave the master is done reading and release the buss back to the master.

 

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

Here the Read Loop:

 

 

while(1)

     {

     TWI_Start(0x21);
     for(counter=0;counter>=2;counter++)
        {
        TWI_Read(array[counter],1); 
        }
     TWI_Read(array[counter],0);
     TWI_Stop();
      _delay_ms(200);
     }

 

After the first Byte recieved, the Master send an ACK and then the Bus stops.

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

sascha_focus wrote:
TWI_Start(0x21);

Classic case of not checking the status here to see if address was ACKd!

sascha_focus wrote:
 for(counter=0;counter>=2;counter++)
        {
        TWI_Read(array[counter],1); 
        }
     TWI_Read(array[counter],0);
     TWI_Stop();

Then blow on through as if all  as is OK!

 

In your TWI_Read() function, you check the state of TWI_RIF, but you do not clear it, does it clear automatically as it does on a tiny/mega?

You may also want to check the TWI_Write() function as well.

 

Jim

Edit: Ok, just read the DS, it looks like you do not need to manually clear those bits, although you might try that to see if it helps. DS have been wrong before.

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274

 

 

 

Last Edited: Tue. May 14, 2019 - 05:59 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello,

 

it clears  automatically :

Last Edited: Tue. May 14, 2019 - 06:01 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

sascha_focus wrote:

     for(counter=0;counter>=2;counter++)

err, you probably meant <= 2

 

also , you might want &array[counter] rather than array[counter]