ATtiny20 and TWI(I2C)?

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

Hi all, new here and wondering if anyone can offer some advice.....I'm not really a programmer (RF is my thing) but I have done a bit over years and can get by. Anyway, been doing a small project with an ATtiny20 and I might've painted myself into a corner! I need TWI master and this thing only acts as a slave it would seem. I've only just realised! Being stripped down this device has been a battle for me. I chose it because I want small, the WLCSP version fits the bill. Anybody know of a code workaround perhaps or an alternative device of similar dimensions with 8 I/O pins  plus the I2C or more?

 

Many thanks,

 

FoF

This topic has a solution.
Last Edited: Thu. Jul 16, 2020 - 04:32 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Welcome to AVRFreaks!

 

For I2C, most freaks use Peter Fluery's code, use the i2cmaster.s file to bit bang to any port pin pair along with the i2cmaster.h

Link here: http://www.peterfleury.epizy.com...

his LCD and USART code is good too.

 

Jim

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

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

Can you use another chip?  Maybe the tiny204 which has I2C master and in the 14 pin package will work.

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

Hi Jim,

 

Many thanks for the welcome and also the link. I think this is what I need....appreciated.

 

73s G0ILO

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

14 pin SOIC is waaayyy too big I'm afraid in comparison, but thank you anyway.

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

14 pin SOIC is waaayyy too big

Wow!!   How big is your circuit board? Sounds like premium real estate  I think the tiny20 is the only one in this package....makes me nervous  

 

Try the tiny24/44/84 you can get it in basically the same size UFBGA package.   It has IIC master/slave (datasheet sec 14.3.4)

 

http://ww1.microchip.com/downloads/en/DeviceDoc/doc8183.pdf

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

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

I was looking for something else, but stumbled up on this:

https://www.microchip.com/paramC...

 

You could fill in your needs there and see what chips are left.

I would add the package as last step and check the remaining devices datasheets on package size as it might be a slightly different one that also fits your bill.

 

edit:

not sure by the way how you are code wise, but it should not take to much code to do a bitbang I2C as you are the master you are in control so timing should not be an issue.

Last Edited: Fri. Jul 3, 2020 - 05:07 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

What a goofy site...I originally downloaded the Excel file to do a sort...but that didn't even show the tiny20 in the WLCSP package (hence the Excel has some differences from the webpage).

The website uses the world's widest columns (wasting much of the screen), so you can see as little as possible about the parts. 

 

They waste 6 inches for a $ symbol, "in production" and a pdf symbol, then 4 more inches to give a price & say "8 bits"  ...10 inches of screen gone..that's why I (hope to) use the Excel

 

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Fri. Jul 3, 2020 - 09:24 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Many thanks all for your input. Bit banging is the way to go for me. I can keep the same device and as a bonus can define the I/O to be convenient for my code/hardware. Looks relatively straight forward......famous last words.

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

I've just started working with the Fleury code. When building I get a 'register name or number from 16 to 31 required' error for the following 2 lines of assembler. The correct register is there so I'm not sure. Any ideas?

 

mov    __tmp_reg__,r24

.

.

.

mov    r24,__tmp_reg__

 

Thank you.

Last Edited: Thu. Jul 16, 2020 - 02:31 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Go on.   You have two candidates:  r24 and __tmp_reg__

 

r24 is obviously 'register name or number from 16 to 31 '

 

The Tiny20 has a TWIS peripheral  (as far as I can remember)

Tinys are intended to be used as Slaves.   Megas are intended to be used as Master (and/or Slave)

Tinys are intended to be brain-dead e.g. no MUL

 

Having said that,  the new XTinys seem to be more capable than the old Tinys

 

David.

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

#ifndef __tmp_reg__
#define __tmp_reg__ 0
#endif

 

Yeah I got this in the defines but something obvious I'm not seeing, but hey I'm an RF engineers lol. C and mixing C with assembler is  a bit new to me.

 

Chose this device for the WCSLP package, nothing comes close in size really, but I do understand its a bit stripped down hence the bit banging approach.

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

FieldsOfFire wrote:
#define __tmp_reg__ 0

 

Change the 0 to something between 16 - 31

 

I would think 16 would work here, YMMV

 

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

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

ki0bk wrote:

FieldsOfFire wrote:
#define __tmp_reg__ 0

 

Change the 0 to something between 16 - 31

 

I would think 16 would work here, YMMV

 

 

Ha ha wood for the trees and all that. Within a few minutes I had bus activity and outputting test bytes on some LEDs. Many thanks.