core13: An Arduino core for the Attiny13 *testers wanted*

Hello i just tried this in arduino 1.0.6 and i get this when i try to compile:

C:\Users\stefan\Documents\Arduino\hardware\tiny13\cores\core13_021\events.cpp: In function 'long unsigned int pulseIn(unsigned char, unsigned char, long unsigned int)':
C:\Users\stefan\Documents\Arduino\hardware\tiny13\cores\core13_021\events.cpp:22: error: expected primary-expression before ']' token
C:\Users\stefan\Documents\Arduino\hardware\tiny13\cores\core13_021\events.cpp:22: error: expected `;' before ']' token
C:\Users\stefan\Documents\Arduino\hardware\tiny13\cores\core13_021\events.cpp:27: error: expected `}' at end of input
C:\Users\stefan\Documents\Arduino\hardware\tiny13\cores\core13_021\events.cpp:27: error: expected `}' at end of input

it compiles OK in version 0.20 and 0.19

just found the problem...
this linewhile(digitalRead(pin) == stat){if((micros() - st) > timeout){return 0;}]
change to

while(digitalRead(pin) == stat){if((micros() - st) > timeout){return 0;}}

And its all good.

Any new functions or big changes from last version?

swe-dude:
just found the problem...
this linewhile(digitalRead(pin) == stat){if((micros() - st) > timeout){return 0;}]
change to

while(digitalRead(pin) == stat){if((micros() - st) > timeout){return 0;}}

And its all good.

Any new functions or big changes from last version?

Somehow I uploaded a broken copy of that file. It's weird because
the current version compiled fine here. Anyway, it's fixed now.

Nothing too big. One of the fixes was actually that function (pulseIn)
Besides bug fixes, I worked on some on the ADC code a bit. The next release
should include boards.txt and platform.txt (or whatever it's called) and
hopefully some of the functions will be a few bytes smaller.

Hi,

while having a look at the just mentioned events.cpp, I wonder whether all these comparisons are a typo.

    to = micros();
    while(digitalRead(pin) == stat){if((micros() - st) > timeout){return 0;}}
    while(digitalRead(pin) != stat){if((micros() - st) > timeout){return 0;}}
    st = micros();
    while(digitalRead(pin) == stat){if((micros() - st) > timeout){return 0;}}
    return micros()-st;

to is initialized but never used, and st used before being initialized. I assume, to stands for “start timeout” and all three comparisons with “timeout” should read:

{if((micros() - to) > timeout){return 0;}}

instead to cover an overall timeout.

-- Reuti

Guys I need help porting over to Arduino 1.6. It's extremely convoluted and I can't even figure out what is required an what is not

It was rough but I finally got it done.

Core13 0.22 released!

Features:

Native compatibility with Arduino 1.6.x
Size optimization
pulseIn fixed (again)

It would be very nice to be able to use attachinterrupt.... as I want to implement a quadrature encoder to pulse and direction sketch. Basically A and B in on change interrupt pins... and direction and increment pulses out on another pin. Alternatively reading out position counters via i2c on the USI port.

766 bytes for my current sketch (although attachinterrupt is missing and I'm just calling the pin read functions from the main loop so it doesn't optimize them out).

Looks like a cool port... I'm glad to see it working in 1.6.5 also (I found 1.6.4 to be rather buggy)!

Arduino IDE 1.6.4
USBasp programmer

On the native "Core 13 0.22" boards.txt I got:

Error while burning bootloader: missing 'bootloader.tool' configuration parameter

so, I trying to solve this and make own boards.txt
Please could someone check it.

# boards.txt for Arduino 1.6.4

menu.flag=GCC Flags
menu.cpu=Processor
menu.clock=Clock

attiny13.name=Attiny13
attiny13.bootloader.tool=arduino:avrdude
attiny13.upload.tool=arduino:avrdude
attiny13.upload.tool=arduino:arduinoisp
attiny13.upload.using=arduino:usbasp
attiny13.bootloader.unlock_bits=0xff
attiny13.bootloader.lock_bits=0xff
attiny13.build.core=arduino:core13
attiny13.build.board=attiny

attiny13.menu.cpu.attiny13=ATtiny13
attiny13.menu.cpu.attiny13.upload.maximum_size=1024
attiny13.menu.cpu.attiny13.upload.maximum_data_size=64
attiny13.menu.cpu.attiny13.build.mcu=attiny13
attiny13.menu.cpu.attiny13.build.core=core13
# attiny13.menu.cpu.attiny13.build.variant=core13

#################################################
############## clock speeds #####################
#################################################

#### 9.6 MHz
############
attiny13.menu.clock.t13_9M6=9.6MHz (internal clock, Preserve EEPROM, BOD disable)
attiny13.menu.clock.t13_9M6.bootloader.low_fuses=0x3A
attiny13.menu.clock.t13_9M6.bootloader.high_fuses=0xFF
attiny13.menu.clock.t13_9M6.upload.speed=57600L
attiny13.menu.clock.t13_9M6.build.f_cpu=9600000L

#### 9.6 MHz - 2.7V
attiny13.menu.clock.t13_9M6_bod=9.6MHz (internal clock, Preserve EEPROM, BOD - 2.7V)
attiny13.menu.clock.t13_9M6_bod.bootloader.low_fuses=0x32
attiny13.menu.clock.t13_9M6_bod.bootloader.high_fuses=0xFB
attiny13.menu.clock.t13_9M6_bod.upload.speed=57600L
attiny13.menu.clock.t13_9M6_bod.build.f_cpu=9600000L

#### 4.8 MHz - 2.7V
attiny13.menu.clock.t13_4M8_bod=4.8 MHz (int 4.8 MHz clock, Preserve_EEPROM, BOD - 2.7V)
attiny13.menu.clock.t13_4M8_bod.bootloader.low_fuses=0x31
attiny13.menu.clock.t13_4M8_bod.bootloader.high_fuses=0xFB
attiny13.menu.clock.t13_4M8_bod.upload.speed=57600L
attiny13.menu.clock.t13_4M8_bod.build.f_cpu=4800000L

#### 1.2 MHz
attiny13.menu.clock.t13_1M2=1.2 MHz (int 9.6 MHz divided by 8,Preserve_EEPROM, BOD - 2.7V)
attiny13.menu.clock.t13_1M2.bootloader.low_fuses=0x2A
attiny13.menu.clock.t13_1M2.bootloader.high_fuses=0xFB
attiny13.menu.clock.t13_1M2.upload.speed=9600L
attiny13.menu.clock.t13_1M2.build.f_cpu=1200000L

#### 600 kHz
attiny13.menu.clock.t13_0M6=600 kHz (int 4.8 MHz divided by 8, Preserve_EEPROM, BOD disable)
attiny13.menu.clock.t13_0M6.bootloader.low_fuses=0x29
attiny13.menu.clock.t13_0M6.bootloader.high_fuses=0xFF
attiny13.menu.clock.t13_0M6.upload.speed=9600L
attiny13.menu.clock.t13_0M6.build.f_cpu=600000L

## 128 kHz
attiny13.menu.clock.t13_128k=128 KHz (internal watchdog oscillator)
attiny13.menu.clock.t13_128k.bootloader.low_fuses=0x7B
attiny13.menu.clock.t13_128k.bootloader.high_fuses=0xFF
attiny13.menu.clock.t13_128k.upload.speed=250
attiny13.menu.clock.t13_128k.build.f_cpu=128000L

## 16 kHz
attiny13.menu.clock.t13_16k=16 KHz (internal watchdog oscillator, Preserve_EEPROM, BOD disable)
attiny13.menu.clock.t13_16k.bootloader.low_fuses=0x2B
attiny13.menu.clock.t13_16k.bootloader.high_fuses=0xFF
attiny13.menu.clock.t13_16k.upload.speed=250
attiny13.menu.clock.t13_16k.build.f_cpu=16000L



##-----------------------------------
##--------- compiler flags ----------
##-----------------------------------

attiny13.menu.flag.Os=Default
attiny13.menu.flag.Os.compiler.c.extra_flags=
attiny13.menu.flag.Os.compiler.c.elf.extra_flags=
attiny13.menu.flag.Os.compiler.cpp.extra_flags=

attiny13.menu.flag.Os_flto=Default -flto
attiny13.menu.flag.Os_flto.compiler.c.extra_flags=-Wextra -flto
attiny13.menu.flag.Os_flto.compiler.c.elf.extra_flags=-w -flto
attiny13.menu.flag.Os_flto.compiler.cpp.extra_flags=-Wextra -flto

attiny13.menu.flag.O1=-O1
attiny13.menu.flag.O1.compiler.c.extra_flags=-O1
attiny13.menu.flag.O1.compiler.c.elf.extra_flags=-O1
attiny13.menu.flag.O1.compiler.cpp.extra_flags=-O1

attiny13.menu.flag.O1_flto=-O1 -flto
attiny13.menu.flag.O1_flto.compiler.c.extra_flags=-O1 -Wextra -flto
attiny13.menu.flag.O1_flto.compiler.c.elf.extra_flags=-O1 -w -flto
attiny13.menu.flag.O1_flto.compiler.cpp.extra_flags=-O1 -Wextra -flto

attiny13.menu.flag.O3=-O3
attiny13.menu.flag.O3.compiler.c.extra_flags=-O3
attiny13.menu.flag.O3.compiler.c.elf.extra_flags=-O3
attiny13.menu.flag.O3.compiler.cpp.extra_flags=-O3

attiny13.menu.flag.O3_flto=-O3 -flto
attiny13.menu.flag.O3_flto.compiler.c.extra_flags=-O3 -Wextra -flto
attiny13.menu.flag.O3_flto.compiler.c.elf.extra_flags=-O3 -w -flto
attiny13.menu.flag.O3_flto.compiler.cpp.extra_flags=-O3 -Wextra -flto

I have tested this with "Arduino as ISP" and "USBasp programmer" (I would like to use my USBasp programmer in many cases.)

I got an error on the "burn bootloader" stage:

avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x0000
0x3f != 0xff
avrdude: verification error; content mismatch

but tiny13 was burned and blinking is working now.

P.S. I use a low speed USBasp in the D:\Program Files\Arduino\hardware\arduino\avr\programmers.txt

############ USBasp (16 kHz) ##############

usbasp_2.name=USBasp (-B 32: 16 kHz)
usbasp_2.communication=usb
usbasp_2.protocol=usbasp
usbasp_2.program.protocol=usbasp
usbasp_2.program.tool=avrdude
usbasp_2.program.speed=32
usbasp_2.program.extra_params=-B{program.speed}

attiny13-aleksey_ua-20_08_2015.zip (17.2 KB)

analogRead(); working only on PB3

aleksey_ua:
analogRead(); working only on PB3

I just tested it. analogRead() works on all the ADC pins (except I didn't test the reset pin).
Make sure you use the ADC numbers and not the pin numbers for analogRead

PB2 = ADC1
PB3 = ADC3
PB4 = ADC2
PB5 = ADC0

I requested ATTiny13A pin change library support here ATTiny13A support · Issue #4 · NicoHood/PinChangeInterrupt · GitHub

The code there might be compact enough to make sense on the ATtiny13.

So for some reason the delay function is not doing what I expect.

So I programmed an ATTiny13A with the blink demo. Changed it to blink on pin 0. The delay I see is acutally 10 seconds + some change.

If I do delay(100) I see 1 second and some change so its off by a factor of 10.

Edit:

I've investigated a bit further. Apparently my fuses were set to 0x6A 0xFF ... which enables dividing the clock by 8. With the fuse bits set to 0x7A 0xFF I now get delay(1000) = 1.31 seconds. delay(770) = 1 second.

Hi! I fixed all of the firmware uploading warnings, and changed menu.

Changes in boards.txt and platforms.txt

Isn't it possible to minimize the footprint of this core even more? a "blank" sketch (empty setup() and loop() ) takes up 172 bytes. Thats 17% of the memory without doing anything!

Wouldn't it be possible to instead have to start things like millis and micros manually, using #define? This would make this core a little more "manual", but the footprint would be much smaller.

(This core should also be hosted on Github rather than SourceForge, for obvious reasons)

hansibull:
Isn't it possible to minimize the footprint of this core even more? a "blank" sketch (empty setup() and loop() ) takes up 172 bytes. Thats 17% of the memory without doing anything!

172 bytes isn't a lot. The memory on the Tiny13 is just very small.
It might be possible with an optimized rewrite in assembly. But in C while remaining Arduino compatible, I doubt it.

Wouldn't it be possible to instead have to start things like millis and micros manually, using #define? This would make this core a little more "manual", but the footprint would be much smaller.

For fixed delays. For variable delays, probably not.

(This core should also be hosted on Github rather than SourceForge, for obvious reasons)

To be quite honest, they are both bad

aleksey_ua:
Arduino IDE 1.6.4
USBasp programmer

Got my ATtiny13A working with your changes, aleksey_ua. Great job! Before I could even burn the bootloder, I had to set proper fuse bits with:

avrdude -p attiny13 -P usb -c usbasp -b 9600 -q -U lfuse:w:0x7a:m -U hfuse:w:0xff:m

If you don't mind - I've just put your changes to my github repo:

with a note, that these changes were made by you.

I'm having some trouble with core13, using in internal pullup resistor. I have a led/resistor on pin 6 (PB1) which fades in and out. I want to ground pin 5 (PB0) to toggle fast/slow fading, but it doesn't seem to be working with an attiny13a. In the following code, the LED flashes fast when pin 5 is open. When pin 5 is grounded, the LED does not light at all. I see your INPUT_PULLUP workaround, and think I'm accounting for it in the code below. For the life of me, I can't see the problem. Any ideas?

int led = 1; // the pin that the LED is attached to
int tswitch = 0; // user selectable switch
int brightness = 0; // how bright the LED is
int fadeAmount = 1; // how many points to fade the LED by
int dtime = 100;

void setup() {
pinMode(led, OUTPUT);
pinMode(tswitch, INPUT);
digitalWrite(tswitch, 1);
}

void loop() {
if (digitalRead(tswitch)) {
dtime = 10;
} else {
dtime = 100;
}
// set the brightness
analogWrite(led, brightness);

// change the brightness for next time through the loop:
brightness = brightness + fadeAmount;

// reverse the direction of the fading at the ends of the fade:
if (brightness == 0 || brightness == 255) {
fadeAmount = -fadeAmount ;
}
// wait to see the dimming effect
delay(dtime);
}

This sketch works on my setup with ATtiny13a.
You should check your hardware.

By the way: the changes are v e r y slow when the button is pressed, so i have changed the dtimes to

if (digitalRead(tswitch)) {
    dtime = 1;     // original: 10
  } else {
    dtime = 10;   // original: 100
  }

so you can see the changes (button not pressed / button pressed) much better.

Hi SmeezeKitty,
I'm just about to test my ATTiny13a hardware for some software I have written, I am using 1.6.3 and the code is written in assembler within a main() loop. Hopefully all will go well and I can report back soonish

mcnobby:
Hi SmeezeKitty,
I'm just about to test my ATTiny13a hardware for some software I have written, I am using 1.6.3 and the code is written in assembler within a main() loop. Hopefully all will go well and I can report back soonish

Any news?