Tiny85 USIC questions

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

Hi,

I'm trying to implement a I2C master using the attiny85's USIC.

The datasheet is confusing regarding some aspects.

1)What   makes the counter increase:USICLK or USITC (both bits are in USICR)?

2)Can i pull SDA low from PORTB even tho it's controlled by the output latch from USIDR?

3)I see that i can clock the thing from Timer 0 compare match? What register/channel from Timer 0? (OCR0A or OCR0B or both)

4)If i toggle only the USITC bit i assume the data won't be shifted from the USIDR,only the SCL line will transition from whatever state i left it in.USIDR shiftout should be done with USICLK...

5)I read the if i enable the 2 wire mode if i have the DDRB bits set to 1 and i write one to PORTB's corresponding bits i wont drive the line ,just release it and i can pull it down by writing 0 to PORTB's bits?

6)If i want to receive i basically set the DDRB bit for SDA to 0 thus making it an input and i'll find the data in USIDR? (Since if i want to output i just make DDRB to 1 and i output the data from USIDR )

Thx in advance :)

This topic has a solution.
Last Edited: Mon. Dec 16, 2019 - 05:10 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

USI is far better as a I2C slave than a master, beater to bit bang a master, even better to use a proven lib then do it yourself.  I’m on my tablet now but I’m sure another freak will offer you some proven code.

jim

 

 

 

 

 

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

Thx.I still want to use the USIC to understand the inner workings of it in case i'll also implement a slave side.Also i want to do it myself than to learn something.Usually if i can make sense of the datasheet i can do it but on the USIC side they aren't very detailed or friendly.

I found example codes.They toggle USICLK and USITC toghether but that does not make sense unless  I need to double write to 1(USICR|=1<<USICLK x2) USICLK for data shiftout of 1 bit.

Most likely i'll do it bigbang if i can't figure it out but at least using the USIC i had the shiftout sorted so START/STOP cond. error checking.

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

There is an USI I2C code application in the Projects section that might help. Search under: USI I2C   Check also for the "I2C sniffer" (by Danni), which also uses USB I2C.

 

Usually people "bit-bang" the I2C interface when there is no TWI module.   Assert the SDA:SCL by first writing a 0 to the PORT bit, then a 1 to the DDR bit to make it output logic low. To release the SDA:SCL lines, make them be an input by writing a 0 to the DDR bit of the port being used.  Wait about 10 microseconds between each change to get the standard 100KHz I2C speed (or 2.5 uS for 400KHz).

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Simonetta wrote:

There is an USI I2C code application in the Projects section that might help. Search under: USI I2C   Check also for the "I2C sniffer" (by Danni), which also uses USB I2C.

 

Usually people "bit-bang" the I2C interface when there is no TWI module.   Assert the SDA:SCL by first writing a 0 to the PORT bit, then a 1 to the DDR bit to make it output logic low. To release the SDA:SCL lines, make them be an input by writing a 0 to the DDR bit of the port being used.  Wait about 10 microseconds between each change to get the standard 100KHz I2C speed (or 2.5 uS for 400KHz).

Thx.I'll look into that code and maybe manage to make a library.

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

santalklaus wrote:
I still want to use the USIC to understand the inner workings of it

Your first step should be to go to the Product Page:

 

https://www.microchip.com/wwwproducts/en/ATtiny85

 

Look on the 'Documents' Tab; there are three App Notes on using the USI Module:

 

AN_2560 - AVR312: Using the USI Module as a I2C Slave

 

AN_2561 - AVR310: Using the USI Module as a I2C Master

 

AN_2582 - AVR319: Using the USI module for SPI communication on tinyAVR and megaAVR devices

 

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thx.Did that before asking here.

Now i wired a Tiny85 with an MPLAB Snap and I'm happily debugging to see the outcome on my scope.

I'll post my findings and library when done.

PS:I'm starting to think the USI isn't the best way to go for i2c.Most likely I'll end up doing it bit-bang as someone mentioned above :)