Hello,
Im new to arduino , microcontrollers and coding. Im building a project with attiny85 as I2C master. It has to read registers from the slave. The main slave address is 0x75, and the register address is 0xa2 and 0xa4. on ideal conditions the values of the register a2 and a4 will be 0x17 in hex ( 23 in decimal read). So when both registers are equal/same, i want the on board lead to go high. Im trying to use TinyWIreM request commands but It doesnt seem to read. On Arduino mega I read the registers successfully with Wire library. I have attached the code , any pointers will be helpful.
//THIS IS THE CODE ON THE ATTINY85
TinyWireM.beginTransmission(0x75);
TinyWireM.send(0xa2);
TinyWireM.endTransmission();
TinyWireM.requestFrom(0x75,7);
delay(2);
a = TinyWireM.receive();
TinyWireM.beginTransmission(0x75);
TinyWireM.send(0xa4);
TinyWireM.endTransmission();
TinyWireM.requestFrom(0x75,7);
delay(2);
b = TinyWireM.receive();
if (a = b)
digitalWrite(1, HIGH);
else
digitalWrite(1, LOW);
//THIS IS THE WORKING CODE ON ARDUINO MEGA
Wire.beginTransmission(SLAVE_I2C_ADDRESS);
Wire.write(SLAVE_I2C_REGISTER_ADDRESS1);
Wire.endTransmission();
Wire.requestFrom(SLAVE_I2C_ADDRESS,7);
delay(2);
uint8_t buf1 = (uint8_t)Wire.read();
Wire.beginTransmission(SLAVE_I2C_ADDRESS);
Wire.write(SLAVE_I2C_REGISTER_ADDRESS2);
Wire.endTransmission();
Wire.requestFrom(SLAVE_I2C_ADDRESS,7);
delay(2);
uint8_t buf2 = (uint8_t)Wire.read();
Serial.print( "a2=");
Serial.println( buf1,HEX );
Serial.print( "a4=");
Serial.println( buf2,HEX );
if (buf1 = buf2)
digitalWrite(13, HIGH);
else
digitalWrite(13, LOW);
Please do not duplicate your questions as doing so wastes the time and effort of the volunteers trying to help you as they are then answering the same thing in different places.
Please create one topic only for your question and choose the forum category carefully. If you have multiple questions about the same project then please ask your questions in the one topic as the answers to one question provide useful context for the others, and also you won’t have to keep explaining your project repeatedly.
Repeated duplicate posting could result in a temporary or permanent ban from the forum.
Could you take a few moments to Learn How To Use The Forum
It will help you get the best out of the forum in the future.
The absolute best advise I can give you is to use the ATTinyCore implementation for the ATTiny85... you will save yourself many, many hours of pain. Most of the standard Arduino libraries will work as they do on the Arduino Uno. You don't have to mess around with "ATTiny specific" versions of code.