Go Down

Topic: ATTiny85 port (work in progress) (Read 43990 times) previous topic - next topic

Coding Badly


Are you able to upload using the IDE?  With the Pololu programmer?

Hyperjer

:) I knew my break out board was a good idea

http://jertechonline.com/product_info.php/products_id/30

how functional is the code for the 85 now?
what needs work? I want to jump in and help

CBX

nice work  ;)

does the servo library work here?

bill2009

#48
Aug 29, 2010, 02:06 pm Last Edit: Aug 29, 2010, 03:21 pm by bill2009 Reason: 1
"Are you able to upload using the IDE?  With the Pololu programmer?"

sorry, the pololu programmer is cute but it doesn't provide +V to the target so I stalled a bit til I rtfm.  I'll post an update today but so far things are great,

bill2009

ok, so as of just now I have the attiny85 core working well with the ide driving the pololu programmer.  For the record, my setup looks like the following:
http://sites.google.com/site/elettronicaarduinoesperimenti/Home/arduino-ide-and-attiny45
installed in the sketchbook folder
Code: [Select]
What seems to work is
>sketchbook folder
>sketchbook folder\hardware
>sketchbook folder\hardware\arduino
>sketchbook folder\hardware\arduino\boards.txt //**see below
>sketchbook folder\hardware\arduino\programmers.txt //**see below
>sketchbook folder\hardware\arduino\cores
>sketchbook folder\hardware\arduino\cores\WProgram.h
etc... (the other core files)

Code: [Select]

**Boards.txt contains
attiny85.name=Arduino w ATtiny85  via avrispv2 Aug 31
attiny85.upload.using=avrispv2
attiny85.upload.maximum_size=8192
attiny85.upload.speed=19200
attiny85.bootloader.low_fuses=0xE2
attiny85.bootloader.high_fuses=0xDF
attiny85.bootloader.path= attiny85
attiny85.bootloader.file=ATmegaBOOT.hex
attiny85.bootloader.unlock_bits=0x3F
attiny85.bootloader.lock_bits=0x0F
attiny85.build.mcu=attiny85
attiny85.build.f_cpu=8000000L
attiny85.build.core=attiny85

Code: [Select]

**programmers.txt contains
avrispv2.name=AVR ISP V2 per Bill Aug 31
avrispv2.communication=serial
avrispv2.protocol=stk500v2
avrispv2.speed=19200


note that programmers.txt only exists because boards.txt is in the sketchbook directory.  If you modified the boards.txt in the original arduino directory it would use the programmers.txt from there.

I suspect my description of the setup is still confusing so if anyone has a better way of describing the structure please chime in.

I have not tried analog read/write but I have done all the digital pins, software serial at 4800 baud, native interrupts, and pin change interrupts - everything worked without a hitch. Here's a "blink" sketch as an example:
Code: [Select]

/*Thanks for the work on the tiny cores
 28-08-2009 for attiny84 R.Wiersma
 09-10-2009 for attiny45 A.Saporetti
and to Bill Roy at bitlash for the pin change interrupt code
*/
// ATMEL ATTINY85 / ARDUINO
//
//                  +-\/-+
// Ain0 (D5) PB5* 1|    |8  Vcc
// Ain3 (D3) PB3  2|    |7  PB2 (D2) Ain1 sck INT0
// Ain2 (D4) PB4  3|    |6  PB1 (D1) pwm1 miso PCINT1
//           GND  4|    |5  PB0 (D0) pwm0 mosi PCINT0
//                 +----+
//* Pin 1 is Reset and tied high on my boards
//available digital pins are D0-D4

int ledpin=3; //IC pin 2
void setup(){
 pinMode(ledpin,OUTPUT); //IC pin 2
}
void loop(){
 digitalWrite(ledpin,HIGH);
 delay(250);
 digitalWrite(ledpin,LOW);
 delay(750);
}


Coding Badly

Quote
I have not tried analog read
...
28-08-2009 for attiny84 R.Wiersma

I believe this is the original core...
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1236434254/94#94

In which case the analog reference constants may be wrong.  I vaguely recall that incorrectly setting the analog reference can lead to a short-circuit.  I suggest carefully reviewing the three constants and, if you have the patience, the source code before connecting anything to the processor.

Beyond knowing that the constants may be wrong, I probably can't provide much help.  But, if you'd like, I'm willing to do what I can.

Osgeld

looks like I need to order some 85's, keep up the good work bill
http://arduino.cc/forum/index.php?action=unread;boards=2,3,4,5,67,6,7,8,9,10,11,66,12,13,15,14,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,86,87,89,1;ALL

bill2009

Quote
I believe this is the original core...
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1236434254/94#94

In which case the analog reference constants may be wrong.  I vaguely recall that incorrectly setting the analog reference can lead to a short-circuit.  I suggest carefully reviewing the three constants and, if you have the patience, the source code before connecting anything to the processor.


I used that core for the '84 and definitely tried at least some analog pins with no issues.  Is there another name for the analog reference constants?  google draws a blank

Coding Badly

#53
Sep 01, 2010, 07:51 am Last Edit: Sep 01, 2010, 07:54 am by bcook Reason: 1

There are four keywords that may help in your searching...
analogReference
INTERNAL
DEFAULT
EXTERNAL

Unfortunately, the last three are extremely generic words.  But it may not matter.  After looking over the datasheets and the header files, I'm starting to remember the details...

These are the analogReference constants from the Arduino core (wiring.h)...

#define INTERNAL 3
#define DEFAULT 1
#define EXTERNAL 0

For the 84/85 processors "3" is reserved (shouldn't be used) so INTERNAL is wrong.  The closest match is "2".  I can't tell for certain but I believe there is supposed to be a capacitor connected to AREF in this mode.

EXTERNAL for the 84/85 processors is "1" not "0".

That leaves DEFAULT.  There isn't an exact match on the 84/85 processors.  The closest is "0" which uses VCC (internally I assume) and the AREF pin becomes a normal digital pin.  I believe this is the power-up default.

In my case, I made certain analogReference was NOT called during initialization so I could use the AREF pin as a normal digital pin.  I believe this also gives the closest matching behaviour to the existing Arduino core.

bill2009

#54
Sep 02, 2010, 01:59 am Last Edit: Sep 02, 2010, 03:41 pm by bill2009 Reason: 1
Ok, I still haven't tried analogRead but I'm not afraid to - I think it's all right.  Looking at wiring_analog.c I find
Code: [Select]
uint8_t analog_reference = DEFAULT;

void analogReference(uint8_t mode)
{
     // can't actually set the register here because the default setting
     // will connect AVCC and the AREF pin, which would cause a short if
     // there's something connected to AREF.
     analog_reference = mode;
}

int analogRead(uint8_t pin)
{
     uint8_t low, high;

     // set the analog reference (high two bits of ADMUX) and select the
     // channel (low 4 bits).  this also sets ADLAR (left-adjust result)
     // to 0 (the default).
//      ADMUX = (analog_reference << 6) | (pin & 0x3f); // more MUX
// sapo per tiny45
     ADMUX = pin & 0x3f;


and looking at the data sheet I see that the hard coded 0x3f set to admux sets the adc to use vcc as a reference and ignore any value set to analogReference.

I also see that we need to add saposoft to the list of those to thank for the attiny45/85 core.

graynomad

Quote
I vaguely recall that incorrectly setting the analog reference can lead to a short-circuit.

I think that when choosing an internal reference it is routed to the AREF pin so you can decouple it, however if you already had say 5v on AREF that would create the "short circuit" when connected to 2.56 or 1.1v
Rob Gray aka the GRAYnomad www.robgray.com

bill2009

#56
Sep 03, 2010, 05:22 pm Last Edit: Sep 03, 2010, 05:34 pm by bill2009 Reason: 1
In the case of the attiny85 port though, the analogRead deliberately forces selection of vcc as the reference so it's safe as long as you don't go poking at the registers directly.

I'm using analogRead now by the way and it's fine.

I've now ported a fairly serious application from the atmega168 to the attiny85.  The circuit board is gratifyingly smaller and less complex.

The major downsides to using the 'tiny are:
1) the timing is a bit off (maybe 3-5%)
2) I can only run softserial at 4800 baud (maybe because of 1).  This may seem like carping but it bogs everything down when debugging to the point where it interferes with other timing.
3) I pretty well have to pop the chip out to re-program it to prevent the target circuit connections from interfering with the programmer and vice-versa.

So the tradeoff is worth it in my mind but the selection of the atmega for the arduino just saves everyone a whole bunch of grief.

Coding Badly

Quote
I'm using analogRead now by the way and it's fine.

Excellent!

Quote
The major downsides to using the 'tiny are:
1) the timing is a bit off (maybe 3-5%)

Are you using a crystal or the internal oscillator?

graynomad

Quote
I pretty well have to pop the chip out to re-program it to prevent the target circuit connections from interfering with the programmer and vice-versa.

Has anyone built an "emulator" for the 85? By that I mean a small board that muxes the ISP pins so you don't have to remove the chip. I've had one on the drawing board for ages but never got around to building it.
Rob Gray aka the GRAYnomad www.robgray.com

mellis


Go Up