Go Down

Topic: [SLOVED] Arduino Mega - SMBus with a LTC1427 help (Read 341 times) previous topic - next topic

stephenlinton

Aug 22, 2012, 04:31 pm Last Edit: Aug 24, 2012, 01:35 pm by stephenlinton Reason: 1
Hello Folks

I'm very new to the whole firmware/software world (I'm hardware electronics engineer) and I'm trying to get a slave device called LTC1427 which is a 10bit current DAC which will be used to vagary the voltage output of a buck boost. This DAC can only receive.

Below is the code that I started to write and got some data coming but I believe the Wire.write commands aren't working correctly. I suspect I'm doing something very silly.

When I say the wire.write commands aren't working correctly what i mean is no matter what hex value I put into the variables the data coming out doesn't change. I'm using an oscilloscope to view that data and clock.

The Wire.beginTransmission does work as I can change these variables and see the difference on the scope.

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include <Wire.h>


void setup()                    // run once, when the sketch starts
{
 Wire.begin();
 Serial.begin(115200);        
 
 Serial.println("All work and no play make Stephen a dull boy!");  // prints hello with ending line break
 LTC1427_TX();
}

void LTC1427_TX()
{
 byte ADD     = 0x2D;
 byte value1  = 0x10;
 byte value2  = 0xAA;
 
 Wire.beginTransmission(ADD);
 Wire.write(0,1); //WR
 Wire.write(0,1); //ACK
 Wire.write(value1);//Command
 Wire.write(0,1); //ACK
 Wire.write(value2);//Data TX
 Wire.write(0,1); //ACK
 Wire.endTransmission();
}

void loop()                       // run over and over again
{
                                 // do nothing!
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

stephenlinton

Solved my problem, Turns out I was been silly with the Oscilloscope. Below is the code for a saw tooth wave.

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#include <Wire.h>

void setup()
{
  Wire.begin();
  Serial.begin(115200);
}

byte val = 0;
byte valHi = 0;

void loop()
{
  Wire.beginTransmission(0x2D); //Address when AD0 & AD1 are low
                             
  Wire.write(valHi);           
  Wire.write(val);             
  Wire.endTransmission();     

  val++;       
  if(val == 255)
  {
    val = 0;
valHi++;   
  }
  if(valHi==4)
  {
    valHi=0;
  }
  Serial.print(valHi);
  Serial.print(" ");
  Serial.print(val);
  Serial.println();
  delay(5);
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Go Up