Pages: [1]   Go Down
Author Topic: ATtiny libraries conflicts with Wire.h  (Read 2912 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 50
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
I want to upload a sketch onto the ATtiny4313 with the Arduino ISP from my Arduino UNO.
First a uploaded the ISP sketch with no ATtiny4313 connected. The works fine.
Then I uploaded the Blink sketch which works fine too.

However, when I try to upload the master_reader sketch from the examples I get the following errors:

In file included from master_reader.cpp:13:0:
/usr/share/arduino/libraries/Wire/Wire.h:55:20: error: conflicting return type specified for ‘virtual size_t TwoWire::write(uint8_t)’
/usr/share/arduino/hardware/tiny/cores/tiny/Print.h:71:18: error:   overriding ‘virtual void Print::write(uint8_t)’
/usr/share/arduino/libraries/Wire/Wire.h:56:20: error: conflicting return type specified for ‘virtual size_t TwoWire::write(const uint8_t*, size_t)’
/usr/share/arduino/hardware/tiny/cores/tiny/Print.h:73:18: error:   overriding ‘virtual void Print::write(const uint8_t*, size_t)’

There seems to be a return type conflict within the libraries used for my Attiny4313. I got them from http://code.google.com/p/arduino-tiny/downloads/detail?name=arduino-tiny-0100-0012.zip&can=2&q=.
My setup: Ubuntu 12.04, Arduino UNO,

Are there any newer libs for the ATTiny available which do not cause any compilation problems ?

Thank you
Regards
AgeBee
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
virtual size_t TwoWire::write(uint8_t)
...
virtual void Print::write(uint8_t)

They changed what "write" returns. You need to open up the library file (/usr/share/arduino/hardware/tiny/cores/tiny/Print.h), and in about two places change "void" to "size_t".

Then find the corresponding part of the Print.cpp file and make the same change. Then add a return to the end of those functions because you are supposed to return the number of bytes written. Something like this ...

Change:

Code:
/* default implementation: may be overridden */
void Print::write(const char *str)
{
  while (*str)
    write(*str++);
}

/* default implementation: may be overridden */
void Print::write(const uint8_t *buffer, size_t size)
{
  while (size--)
    write(*buffer++);
}

to:

Code:
/* default implementation: may be overridden */
size_t Print::write(const char *str)
{
  size_t n = 0;
  while (*str)
    n+= write(*str++);
  return n;
}

/* default implementation: may be overridden */
size_t Print::write(const uint8_t *buffer, size_t size)
{
  size_t n = 0;
  while (size--) {
    n += write(*buffer++);
  }
  return n;
}
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 50
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks a lot Nick,
that is definitely the right direction.
But I am only half way down because I now ran into several errors coming from TinyDebugSerial.h.
And there are heaps of write function which also need that changes.
But first I have to set up a 'sound' IDE for changing the code there. Otherwise it's always tapping around in the dark.
Regards
AgeBee
Logged

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 178
Posts: 12288
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Even if you get past the current round of compiler errors, the ATtiny4313 does not have the necessary hardware for the Wire Library to work.  This is the alternative for ATtiny processors...
http://arduino.cc/playground/Code/USIi2c

I have no idea if it has been made to work on the ATtiny4313.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 50
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@Coding Badly:
That is a very good hint to save a lot of work, thanks a lot for that.
I thought having a SDA and SCL for a chip is sufficient to work with the libs.
So, why does these libs do not work with the ATtiny4313 ? The docs show that the ATtiny85 and the ATtiny4313 do have a SDA and a SLC and TWI (I2C) is supported.
Sorry for my questions but I am not a hardware specialist.
Logged

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 178
Posts: 12288
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


"SDA" and "SCL" only have a well defined consistent meaning on the outside of the processor.  Inside the processor is a different story.  A vendor is free to implement I2C however they wish.  They are also free to have different implementations for different processor families.

The ATmega family has a dedicated subsystem that performs I2C communications completely in hardware.  The ATtiny family does not.  Instead, it has a "Universal Serial Interface" that provides help with SPI or I2C communications.  It's like comparing a turbine jet engine to a reciprocating internal combustion engine.  They are both capable of moving a vehicle from point A to point B but they do it in radically different ways.

Quote
So, why does these libs do not work with the ATtiny4313 ?

The Wire Library is written specifically to work with the ATmega I2C subsystem; something that simply does not exist on ATtiny processors.

Quote
The docs show that the ATtiny85 and the ATtiny4313 do have a SDA and a SLC and TWI (I2C) is supported.

I2C is supported but the way that support is realized is different than the ATmega family.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 50
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you very much for your time explaining me the differences.
So I go with the ATMega32, it should do the work.
Logged

Pages: [1]   Go Up
Jump to: