I am trying to connect the MMA8452Q with AtTiny85 using the TinyWireM library.
I made the proper hardware setup with pull-ups on SCL and SDA pins - tested it on Arduino
Uno and it works, however when i connect the Tiny I cannot even get the handshake.
The following code produces output 13
instead of 42
(0x2A)
HARDWARE SETUP
MMA8452 Breakout ------------AtTiny85
3.3V -------voltage regulator------ 5V
SDA -----------^^(330)^^----------- PB0 (on attiny programmer marked as 5)
SCL -----------^^(330)^^----------- PB3 (on attiny programmer marked as 2)
GND --------------------------------- GND
(I also tried different pins with no luck)
CODE
//---bluetooth console communication stuff---//
#include <SoftwareSerial.h>
#define rxPin 1 //not important - needed for initialization
#define txPin A2
SoftwareSerial blueTooth(rxPin, txPin);
// --- //
#include "TinyWireM.h" // Used for I2C
// The SparkFun breakout board defaults to 1, set to 0 if SA0 jumper on the bottom of the board is set
#define MMA8452_ADDRESS 0x1D // 0x1D if SA0 is high, 0x1C if low
#define WHO_AM_I 0x0D
void setup() {
blueTooth.begin(9600);
delay(1000);
TinyWireM.begin(); //Join the bus as a master
delay(1000);
}
void loop() {
byte c =0;
c = readRegister(WHO_AM_I);
blueTooth.println(c);
delay(1000);
}
// Read a single byte from addressToRead and return it as a byte
byte readRegister(byte addressToRead) {
TinyWireM.beginTransmission(MMA8452_ADDRESS);
TinyWireM.send(addressToRead);
TinyWireM.endTransmission(); //endTransmission but keep the connection active
TinyWireM.requestFrom(MMA8452_ADDRESS, 1); //Ask for 1 byte, once done, bus is released by default
while(!TinyWireM.available()) ; //Wait for the data to come back
return TinyWireM.receive(); //Return this one byte
}
Would anyone know how to get it right?