Go Down

Topic: [solved] Code runs on attiny45 but doesnt on attiny25 (Read 370 times) previous topic - next topic

milkpirate

Mar 11, 2013, 11:56 pm Last Edit: Apr 04, 2013, 12:30 pm by milkpirate Reason: 1
hello,

I wrote a sketch to controll an LCD and it works pretty well with a (per tinytuner) calibrated attiny45 running at 1Mhz. I'm using this arduino tiny core: http://code.google.com/p/arduino-tiny/. The compiled code is smaller than 2k, so I thought its a good idea to save my t45 (maybe for an USB project) and use a attiny25 instead. I changed the settings and uploaded successfully.

BUT:

After uploading my sketch to the t25 it seems to initialize the LCD but nothing more. Nothing appears, nothing happens. Already checked if I might run out of SRAM but it doesnt seem so:

Code: [Select]

C:\>avr-size %temp%\build...\lcd_octopus.cpp.elf -C --mcu=attiny25
AVR Memory Usage
----------------
Device: attiny25

Program:    1932 bytes (94.3% Full)
(.text + .data + .bootloader)

Data:         92 bytes (71.9% Full)
(.data + .bss + .noinit)


More project details:
Its a little sketch to show a moving octopus on the LCD (like this: https://vimeo.com/32284689). Its supposed to be a gift :). The problem is the original code was for an LCD with UART (?) interface. I was trying to connect my LCD in 4-Bit mode (so 6 pins should be enough) directly to my t45 to use it with the generic LCD lib. But I couldnt, because the reset pin seems not to work as output (any advice?). So I used a PCF8574 with the TinyWireM lib. I had to rewrite the LCD routines because of my weird wiring (wanted to stay single layered). So... in the nutshell:

Sketch < 2k works @ t45; doesnt @ t25 :(

Ill be grateful for any help!

lny

[EDIT]
Ok I stopped using the tinywire lib and implemented my own I2C write rountines like here: http://www.robot-electronics.co.uk/acatalog/I2C_Tutorial.html. This turned out in the end:

Code: [Select]

#define SDA        PB0        // i2c Serial data
#define SCL        PB2        // i2c Serial clock
#define pcf_addr   0x40       // 00100000 slave address write

//------------------- library I2C --------------------------
void i2c_start() {
// |-[S]-|  ;Start Condition
  PORTB &= ~(1 << SDA);      // SDA=0
  delayMicroseconds(1);
  PORTB &= ~(1 << SCL);      // SCL=0
  delayMicroseconds(1);
}

void i2c_ack() {
// |-[A]-|  ;Active LOW
  PORTB &= ~(1 << SDA);      // SDA=0
  delayMicroseconds(1);
  PORTB |= (1<<SCL);      // SCL=1
  delayMicroseconds(1);
  PORTB &= ~(1 << SCL);      // SCL=0
  delayMicroseconds(1);
  PORTB &= ~(1 << SDA);      // SDA=0
  delayMicroseconds(1);
}

void i2c_stop() {
  // |-[P]-|  ;Stop Condition
  PORTB |= (1<<SCL);      // SCL=1
  delayMicroseconds(1);
  PORTB |= (1<<SDA);      // SDA=1
}

void i2c_byte(byte data) {  // actually write a data byte
  byte iBit = 0;
  for(byte iloop = 0 ; iloop < 8 ; iloop++)
  {
    iBit = ((data & 0x80) >> 7 ) ;
    delayMicroseconds(1);

    if (iBit) PORTB |= (1 << SDA);  // SDA=iBit
    else      PORTB &= ~(1 << SCL); // SDA=iBit

    delayMicroseconds(1);
    PORTB |= (1<<SCL);      // SCL=1
    delayMicroseconds(1);
    PORTB &= ~(1 << SCL);      // SCL=0
    delayMicroseconds(1);
    PORTB &= ~(1 << SDA);      // SDA=0
    data = data << 1 ;
  }
  delayMicroseconds(1);
}
//------------------- end library I2C -------------------------


Thx to everyone anyway.

Lny

Osgeld

Quote
Sketch < 2k


that is irrelevant as its just how much space its going to take in flash, how much ram is it using? the 25 only has 128 bytes
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

milkpirate

Quote
Code: [Select]
Data:         92 bytes (71.9% Full)
(.data + .bss + .noinit)


Doesnt that mean SRAM usage? Once I saw another command which lists all variables which will be used, but I cant remember it. Maybe you know it?

fungus


Quote
Code: [Select]
Data:         92 bytes (71.9% Full)
(.data + .bss + .noinit)


Doesnt that mean SRAM usage? Once I saw another command which lists all variables which will be used, but I cant remember it. Maybe you know it?


SRAM also has to store the return stack, local variables, etc. 36 bytes probably isn't enough for that.
No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Go Up