Yeah.... got it working, but I am not sure why it didn't in the first place.
The code is not changed much.. While testing I set the "outputValueMain" to 0b111111111111 ( 12 bits), and got a full reading on the output of the MCP4725. So I added to the declared variable 0x00.
unsigned int outputValueMain = 0x00;
I set REFS1 and REFS0 back to 0 because the attiny85 does not have an AREF pin.
Please find the code below that reads 10 bits analog input and returns 12 bits to the DAC ( MCP4725).
/* TEST MCP4725 ATTINY85
*
* sensor read ( hall sensor) pin 2
* - OR - potentiometer pin to VCC pin to GND and the runner to pin 2
* led on pin 6 with resistor to ground
* SDA pin 5
* SCL pin 7
*
*/
#include <TinyWireM.h> // Adafruit / Bro Hogan
#define dacMainController 0x60 // address for main motor controller
#define outputPin 1
byte adcLoByte;
unsigned int adcRaw;
unsigned int analogData; // declare analogData variable
unsigned int mainBuffer[ 3];
unsigned int outputValueMain = 0x00;
void setup() {
// pinMode( outputPin, OUTPUT);
ADMUX = ( 0 << REFS1) | // sets ref. voltage to AREF, bit 1
( 0 << REFS0) | // sets ref. voltage to AREF, bit 0
( 0 << ADLAR) | // left shift result
( 0 << MUX3) | // use ADC3 for input ( PB3), MUX bit 3
( 0 << MUX2) | // use ADC3 for input ( PB3), MUX bit 2
( 1 << MUX1) | // use ADC3 for input ( PB3), MUX bit 1
( 1 << MUX0); // use ADC3 for input ( PB3), MUX bit 0
ADCSRA = (1 << ADEN) | // enable ADC
(0 << ADPS2) | // set prescaler to 8, bit 2
(1 << ADPS1) | // set prescaler to 8, bit 1
(1 << ADPS0); // set prescaler to 8, bit 0
TinyWireM.begin();
}
void loop() {
ADCSRA |= ( 1 << ADSC); // start adc measurement
while( ADCSRA & ( 1 << ADSC)); // wait till conversion complete
adcLoByte = ADCL;
adcRaw = ADCH << 8 | adcLoByte;
analogData = adcRaw; // store data in analogData variable
outputValueMain = analogData * 4; // x 4 to get to 12 bits
mainBuffer[ 0] = 0b01000000; // control byte, bits 7 - 5 -> 010 write DAC
mainBuffer[ 1] = outputValueMain >> 4; // MSB 11-4 shift right 4 places
mainBuffer[ 2] = outputValueMain << 4; // LSB 3-0 shift left 4 places, bits 3 - 0 unused
TinyWireM.beginTransmission( dacMainController);
TinyWireM.write( mainBuffer[ 0]); // pointer
TinyWireM.write( mainBuffer[ 1]); // the 8 most significant bits...
TinyWireM.write( mainBuffer[ 2]); // the 4 least significant bits...
TinyWireM.endTransmission();
}