Close

Bitbang of I2C on Attiny10

A project log for Minimalist A-go-go

A project inside Attiny. I will not step out for larger one till I complete it.

kodera2tkodera2t 06/16/2016 at 11:002 Comments

I2C interface is quite useful for extension of small MCU, because it just consume two pins (CLK and DAT). The case of Attiny10, it does not support by its hardware but indeed more than five years ago, some people and guys succeeded to implemented in C. For me, assembly seems to be more straightforward and I made the code from scratch.

Actually bitbang is a kind of "very fast LED blinking". If you can make LED blink program in some MCU, you will be able to implement I2C on it. For implementing it, for example, bit "1" and "0" coding is like this:

bit_high:
	ldi temp1, 0b00
	out PORTB, temp1
	rcall delay
	ldi temp1, 0b01
	out PORTB, temp1
	rcall delay
	ldi temp1, 0b11
	out PORTB, temp1
	rcall delay
	ldi temp1, 0b01
	out PORTB, temp1
	rcall delay
	ldi temp1, 0b00
	out PORTB, temp1
	rcall delay
	ret
	;cl=1 da=0
bit_low:
	ldi temp1, 0b00
	out PORTB, temp1
	rcall delay
	ldi temp1, 0b00
	out PORTB, temp1
	rcall delay
	ldi temp1, 0b10
	out PORTB, temp1
	rcall delay
	ldi temp1, 0b00
	out PORTB, temp1
	rcall delay
	ldi temp1, 0b00
	out PORTB, temp1
	rcall delay
	ret

Here PB0 is SDA and PB1 is SCL of I2C. It is LED blinking, isn't it? If you have logic analyser (not expensive one but just a handy USB based analyser, in my case...) , actual timing and logic level can be confirmed and quite useful for completing bitbang.

This is the LCD display driven by bit banged Attiny10. Currently my assembly code occupies,
Segment   Begin    End      Code   Data   Used    Size   Use%
--------------------------------------------------------
[.cseg] 0x000000 0x0001e6    486      0    486    1024  
[.dseg] 0x000040 0x000060      0      0      0      32  
[.eseg] 0x000000 0x000000      0      0      0       0  
Just 48% of flash and zero SRAM consumption yet (everything is processed in registers). My code (I am so sorry but it is quite dirty and redundant and no-sophisticted) is released on github, again it is combination of "LED blinking".

Actual operation can be found in the following movie.. have fun!

Discussions

kodera2t wrote 06/25/2016 at 13:23 point

Hello, It is ST7032 based LCD, which can be found... for example, http://www.aliexpress.com/wholesale?catId=0&initiative_id=SB_20160625052224&SearchText=0802+i2c

  Are you sure? yes | no

jaromir.sukuba wrote 06/25/2016 at 12:11 point

The LCD looks sweet. Where did you get this one?

  Are you sure? yes | no