Go Down

Topic: [I2C] arduino -> attiny(slave) can't have adress higher than 63 (Read 3059 times) previous topic - next topic

eye_a

Apr 12, 2013, 08:35 pm Last Edit: Apr 13, 2013, 01:16 pm by eye_a Reason: 1
Hello,

i'm quite new in arduino. I'm working on a home-made i2c network to drive attinys slaves (attiny85) by an arduino master(arduino uno).

hardware : -1 arduino uno as master
               -1 attiny85(1MHZ) on breadboard as slave
               -wires between slave and master for 5v,gnd,SCL,SDA
               -2 pull-ups resistor 4k7 on SDA and SCL

sketch arduino uno master :
Code: [Select]

#include "Wire.h"

void setup()
{
 Wire.begin();
 Serial.begin(115200);                    
 Serial.println ("IC2 master starting");
}


void i2c_scan_p()
{
 Serial.println ();
 Serial.println ("Scanning");
 int nbr_module = 0;
 Wire.begin();
 for (byte i = 1; i < 127; i++)
 {
   Wire.beginTransmission (i);
   if (Wire.endTransmission () == 0)
   {
     Serial.print ("adress found: "),Serial.print (i, DEC),Serial.print (" (0x"),Serial.print (i, HEX),Serial.println (")");
     nbr_module++;
   }
 }
 delay(1000);
 Serial.println ("Scan done");
 Serial.print ("there is "),Serial.print (nbr_module, DEC),Serial.println (" module(s) on the bus");
}


void loop()
{
i2c_scan_p();
}


sketch of attiny85 slave :
Code: [Select]
#include "TinyWireS.h"                

void setup(){TinyWireS.begin(63);}    

void loop(){}


I have done some i2c test and as far as know, i can detect and communicate (both way) with the attinys85 on the bus. all my test have been done with adress between 1 and 16. I used as much as 6 attinys at the same time and everything worked perfetcly.

In order to see larger application and to get a better understanding, i'm trying to use all adresses available. The Wire library says that adress are coded on 7 bit wich allow 127 adresses. TinyWires library says that it works the same as Wire library, so 7 bit as well for the adress.

the problem is : i CAN'T detect or communicate with any adress higher than 63. wich is basicaly the half of what the libraries say.

I have tried a lot of adress definition (not at the same time ofc) :

Code: [Select]

TinyWireS.begin(64); //also with (73) or (85) or (110)
TinyWireS.begin(0x40);
TinyWireS.begin(B01000000);
TinyWireS.begin(B1000000);
TinyWireS.begin(B10100000);  //(just to avoid the second bit in case of ...)

//and of course :

TinyWireS.begin(i);

//with :

int i = 64 ;
byte i = 64 ;
byte i = 0x40 ;
#define i 0x40  ; // ect ...



I guess it has something to do with :  
Quote
""the eighth bit determines if it's being written to or read from.


tinywires says :
Quote
TinyWireS.begin(I2C_SLAVE_ADDR);              // initialize I2C lib & setup slave's address (7 bit - same as Wire)


When i give the slave the adress 63, the i2cscanner return :
Code: [Select]
Scanning
adress found: 63 (0x3F)
Scan done
there is 1 module(s) on the bus


When i give the slave the adress 64 or more, the i2cscanner return :
Code: [Select]
Scanning
Scan done
there is 0 module(s) on the bus



i'm missing something here, it may be huge, i'm always owned by basic stupid things :/

By the way, if it's just an hardware limit or something, it will work for me, but i'm very curious to understand.

(I searched a lot on google and made a few research on the forum but unsuccessfully. If i missed a topic explaining the subject i'm sorry)

eye_a


Coding Badly


I cannot promise you will get help.  But I can promise you are much more likely to get help if you...

Post a ready-to-run sketch for the ATtiny85 processor that illustrates the problem.  Please use [code] [/code] tags.

Provide a link to both of the I2C scanners you have tried.

At a minimum, include a description of the hardware.  For example, did you include external pull-up resistors?

eye_a

#2
Apr 13, 2013, 11:09 am Last Edit: Apr 14, 2013, 08:03 am by eye_a Reason: 1
Hello,

Following your advice, i have remade my topic for better understanding.

if it's not clear enought, i'll try to be more specific. I got rid of everything exept the minimum in my code in order to test my adress probleme, that's why the sketches are quite empy.

Thanks in advance,

.Eye

borland

.Eye,

If you look at the library file, TinyWireS.cpp, you'll see that the function call is expecting a uint8_t (byte).

Code: [Select]
void USI_TWI_S::begin(uint8_t slaveAddr){ // initialize I2C lib
  usiTwiSlaveInit(slaveAddr);


So, you could change your address declaration to look like this..

uint8_t I2C_SLAVE_ADDRESS = 0x72;

or

byte I2C_SLAVE_ADDRESS = 0x72;

then use the setup() call:

TinyWireS.begin(I2C_SLAVE_ADDRESS);

You could also use decimal 114 instead of hex 0x72.


Go Up