ATTINY10 TWI Master, can it be bitbanged?

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

I am a bit short on board space and need to make a simple device that monitors a voltage, then sends data to a TWI slave device according to the voltage.

All that works fine on my 128RFA1, but that chip is an overkill for the function, and the little 6pin attiny10 would fit better :)

I have looked at a few TWI examples using bitbanging, but I cannot tell if they will work on the limited platform that is the ATTiny10.

So before I go and get the required hardware to do this, I thought I'd ask if there were any of you that have succeded in making a master TWI on an attiny10.

Thanks
Phil

_________________________________

www.proficnc.com
_________________________________
Go Aussie Go!!!

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

You can bit-bang any Master quite easily. Bit-banging a Slave is virtually impossible.

Fleury:
"i2cMaster.S" // bit-bang
"twiMaster.c" // use the TWI hardware

David.

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

I have used AVR300, it is written in the language of Kings though, not the C-ommon people's.

Quote:
**** A P P L I C A T I O N N O T E A V R 3 0 0 ************************
;*
;* Title : I2C (Single) Master Implementation
;* Version : 1.0 (BETA)
;* Last updated : 97.08.27
;* Target : AT90Sxxxx (any AVR device)
;*
;* Support email : avr@atmel.com
;*
;* DESCRIPTION
;* Basic routines for communicating with I2C slave devices. This
;* "single" master implementation is limited to one bus master on the
;* I2C bus. Most applications do not need the multimaster ability
;* the I2C bus provides. A single master implementation uses, by far,
;* less resources and is less XTAL frequency dependent.
;*
;* Some features :
;* * All interrupts are free, and can be used for other activities.
;* * Supports normal and fast mode.
;* * Supports both 7-bit and 10-bit addressing.
;* * Supports the entire AVR microcontroller family.
;*
;* Main I2C functions :
;* 'i2c_start' - Issues a start condition and sends address
;* and transfer direction.
;* 'i2c_rep_start' - Issues a repeated start condition and sends
;* address and transfer direction.
;* 'i2c_do_transfer' - Sends or receives data depending on
;* direction given in address/dir byte.
;* 'i2c_stop' - Terminates the data transfer by issue a
;* stop condition.
;*
;* USAGE
;* Transfer formats is described in the AVR300 documentation.
;* (An example is shown in the 'main' code).
;*
;* NOTES
;* The I2C routines can be called either from non-interrupt or
;* interrupt routines, not both.
;*
;* STATISTICS
;* Code Size : 81 words (maximum)
;* Register Usage : 4 High, 0 Low
;* Interrupt Usage : None
;* Other Usage : Uses two I/O pins on port D
;* XTAL Range : N/A
;*
;***************************************************************************

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

That should be OK, the program will be quite short, it is just a battery level display, so I should be able to cope with ASM :)

_________________________________

www.proficnc.com
_________________________________
Go Aussie Go!!!

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

Quote:
device that monitors a voltage
Do you have a comparator or so on the board already ? If not think about using a Tiny25 , it comes with an onboard ADC and has the same footprint.

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

Quote:
has the same footprint.
Think again. The old-never-born Tiny10 had the same footprint not the new Tiny10. :-)

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

Oops, i was really thinking the old Tiny10, not the 6-pin one. Sorry if that was confusing :(

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

Confusing allright!! I even have a debugger for the old Tiny10 which never saw the distributor's shelf.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

The 10 has 4 adc's and a comparator doesn't it? It's the 9 that hasn't

_________________________________

www.proficnc.com
_________________________________
Go Aussie Go!!!

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

The next issue is programming it, which programmer do I need for studio 4? I have a jtag mk ii but the I am assuming I need a jtag mk iii or an stk600, any other options?

_________________________________

www.proficnc.com
_________________________________
Go Aussie Go!!!

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

The avrisp mkii works well, I've tried it.

I tend to post off-topic replies when I've noticed some interesting detail.
Feel free to stop me.

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

I have ordered my avrisp mkii from Atmel, and will give it a go. looks like a great little chip.

_________________________________

www.proficnc.com
_________________________________
Go Aussie Go!!!

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

A bit OT, but I love the T10, great cheap solution for a a lot of niggly pains I've had on many boards. Recently used it for encoding 3-bits of data across a differing-ground (30V) link, saves the day so many times (yes, could have used digital-isolators, but $0.60 vs $4 ... :D

Good luck with the bit-banging, it should work fine as a master as others have mentioned.

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

Quote:
I have ordered my avrisp mkii from Atmel,
Does it work out cheaper overall than Farnell at $66.00?

http://au.element14.com/jsp/sear...

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

Yep
US$ 55 including freight.

_________________________________

www.proficnc.com
_________________________________
Go Aussie Go!!!

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

OK, it is basically working, (I am using a 128RFA1 for testing this, using port B pins 3 and 4)
here is the working code

#include 
#include "i2cmaster.h"
//#include 

#define D_BARS_ADD  	0x5003
#define D_BARS_VALUE  	0b10000001
#define OCTET_MASK		0xFFU
// Prototypes
int i2c_write_string (uint16_t address_D, uint8_t value_D);
//int wait_one_second(void);
//Main
int main(void)
{
     DDRB  = 0xff;
    i2c_init();                                // init I2C interface
      i2c_write_string(0x5003,0x81);
	return 1;
}
//Functions
int i2c_write_string (uint16_t address_D, uint8_t value_D)
{
		uint8_t il;
		uint8_t ih;
		il = address_D & 0xFF; 
		ih = address_D >> 8UL;
    	i2c_start_wait(0b10000000);     // set device address and write mode
        i2c_write(0x50);
		i2c_write(0x03); 
        i2c_write(0b10000001);                       
        i2c_stop(); \
return 1;	
}

however when I change to using the variables for the data, it wont work, can anyone see what I have done wrong?

#include 
#include "i2cmaster.h"
//#include 

#define D_BARS_ADD  	0x5003
#define D_BARS_VALUE  	0b10000001
#define OCTET_MASK		0xFFU
// Prototypes
int i2c_write_string (uint16_t address_D, uint8_t value_D);
//int wait_one_second(void);
//Main
int main(void)
{
     DDRB  = 0xff;
    i2c_init();                                // init I2C interface
      i2c_write_string(0x5003,0x81);
	return 1;
}
//Functions
int i2c_write_string (uint16_t address_D, uint8_t value_D)
{
		uint8_t il;
		uint8_t ih;
		il = address_D & 0xFF; 
		ih = address_D >> 8UL;
    	i2c_start_wait(0b10000000);     // set device address and write mode



        i2c_write(ih);       ///////////Here is the change
	i2c_write(il);



        i2c_write(0b10000001);                       
        i2c_stop(); \
return 1;	
}

_________________________________

www.proficnc.com
_________________________________
Go Aussie Go!!!

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

Your functions should both work the same. However, you make no attempt to read the return values of any of the library calls. This would show you exactly where anything goes wrong.

I suggest that you use the i2c_start() function rather than i2c_start_wait() which can hang indefinitely.

David.

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

Will look at the returns and see what's going on,
The ATTiny10's showed up today, now I just have to wait for the programmer.

_________________________________

www.proficnc.com
_________________________________
Go Aussie Go!!!

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

Quote:

The 10 has 4 adc's and a comparator doesn't it? It's the 9 that hasn't

Side note: We were working on a project in the Tiny10 range, and have not applied the family before.

So a trip to DigiKey was in order to see what models are not phantoms, and a check on pricing.

Atmel carefully created the family with 4-5-9-10 having different combinations of flash space and A/D. Right?

Now let's go to a US distributor and purchase 100 of the little beasties...

Tiny4 -- .75/1; .4655/100; .420/reel
Tiny5 -- .77/1; .4788/100; .432/reel
Tiny9 -- .77/1; .4788/100; .432/reel
Tiny10-- .80/1; .4921/100; .444/reel [100k+ in stock)
Tiny13A -- 1.07/1; .5964/100 (for comparison)

Not much differentiation in modest quantities.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

I suppose in a batch of one million, $0.01 per device is a saving of $10,000.00. so assuming the savings between each device is 1 cent, between the tiny 10 and the tiny 4 there could be a 40K diference in production cost.

For me... the 10 wins out :)

_________________________________

www.proficnc.com
_________________________________
Go Aussie Go!!!