Go Down

Topic: (solved)Problem with arduino and attiny2313, same program - different result (Read 256 times) previous topic - next topic

Kralik

Hi,
I was playing with my attiny2313 and UART communication in the way that i uploaded a sketch [sketch1] to my Arduino UNO and sketch [sketch2] to my attiny2313 and connected Tx from attiny to Rx of my Uno. Then i opened up a serial monitor and got some mess - every time it send a signal the arduino received three lines each with one zero.
I tested the same code on my Arduino Nano (arduino nano and attiny was programmed using USBasp and my Uno via built-in USB socket) and got what i wanted - basically there was number 3 showing in serial monitor on each pulse. But with attiny no luck.
Also i noticed (because for UART both uC has to run on the same clock, in this 16Mhz i connected a crystal on Xtal inputs of my attiny) that on serial i get the same result with and without the crystal...even the time between each pulso was the same.
Note: code for my nano was modified because in the way that it could work ex. UDR (On attiny) must be UDR0 (on nano)
The fuses for my attiny i programmed same as standart aruino:

Lfuse: FF
Efuse: FD //typically for arduino is 0x05 but this is the same only with filled up unused bits in register
Hfuse: DE

[sketch1]
Code: [Select]
void setup() {
  //  for  ARDUINO UNO

  Serial.begin(9600);
}

void loop() {

// Print everything thats on serial bus
 
  if(Serial.available() > 0)
    {
      int value = Serial.read();
      Serial.println(value);
    }     

}



[sketch2]
Code: [Select]
#include <avr/io.h>
#include <util/delay.h>

#define F_CPU 16000000  // 16Mhz
#define BAUD 9600          // typical BAUDrate (samo on UNO)
#define BRC ((F_CPU/16/BAUD) - 1)

int main(void)
{
UBRRH = (BRC >> 8);
UBRRL = BRC;

UCSRB = (1 << TXEN);
UCSRC = (1 << UCSZ1) | (3 << UCSZ0); //Setting up Tx & Rx registers, stop bits

while(1)
{

_delay_ms(200);       // Wait
UDR = 0b00000011;  // Write to serial bus


}
}


I assume that it could be something with the crystal but after spending few hours on internet i coulnd find an answer.
Thanks

Coding Badly


This...
Code: [Select]
#define F_CPU 16000000  // 16Mhz
...in your code is suspicious.  Normally F_CPU would be defined in the environment.  For example, if you are using the Arduino IDE to build then F_CPU is defined in boards.txt.  If F_CPU is not defined in the environment / before your includes then things like _delay_ms may not work correctly.

To ensure the fuses and clock are correct upload a simple blink program to the t2313.  Do not include a #define for F_CPU.  If the LED blinks at the expected rate then you can check that off your list.


jremington

Quote
i get the same result with and without the crystal
This strongly suggests that the fuses are not correctly set.

Kralik

To ensure the fuses and clock are correct upload a simple blink program to the t2313.  Do not include a #define for F_CPU.  If the LED blinks at the expected rate then you can check that off your list.
I tried, LED is blinking but the period is MUCH longer that it should be but i think something more important is wrong here...
the LED is blinking like i said but it doesnt matter which clock speed i select, its always blinking at same speed, with crystal or not.

Yes, i think that too but after flashing the chip pogrammer wrote (H and E fuses are most likely switched in this verion like i read on web) BUT the Low fuses might be the problem.
in my program "Makefile" i specified the fuses but Lfuse is definnitelly not a 64...

DEVICE     = attiny2313
CLOCK      = 16000000
PROGRAMMER = -c USBasp
OBJECTS    = main.o
FUSES      = -U lfuse:w:0xFF:m -U efuse:w:0xfd:m -U hfuse:w:0xde:m


Programmer Output after uploading:

avrdude: 102 bytes of flash verified

avrdude: safemode: Fuses OK (H:FF, E:DF, L:64)

avrdude done.  Thank you.


I tried what i can but the Lfuse i still 64..strange, Thanks

Coding Badly


0x64 is the default.  The processor is running at 1 MHz.

Whatever you are doing to change the fuses is not working.


Kralik

i spend few hours playing with it and really my compiler doesnt compile the fuses i wrote so i downloaded another program and it works! Thanks guys

Go Up