I got it! I did a program to generate a sawtooth wave on channel A and a sine wave on channel B! Here goes the codes. I am already creating a repository in Github.
DAC855X.h
/*************************************************************************
** Library for Digital to Analogic Converters by Texas Instruments **
** DAC8550, DAC8551, DAC8552, DAC8554, DAC8555 on Arduino. **
** By Renato Ianhez **
*************************************************************************/
#ifndef DAC855X_H
#define DAC855X_H
#include "Arduino.h"
#include "SPI.h"
class DAC855X
{
public:
DAC855X();
void setPins(int DIN, int SCK, int SYNC);
void setChipChanValue(int CHIPX, int chan, int value);
void initializeDAC855X();
private:
int _DIN;
int _SCK;
int _SYNC;
};
#endif
DAC855X.cpp
/*************************************************************************
** Library for Digital to Analogic Converters by Texas Instruments **
** DAC8550, DAC8551, DAC8552, DAC8554, DAC8555 on Arduino. **
** By Renato Ianhez **
*************************************************************************/
#include "DAC855X.h"
DAC855X::DAC855X() {
}
void DAC855X::setPins(int DIN, int SCK, int SYNC) {
_DIN = DIN;
_SCK = SCK;
_SYNC = SYNC;
pinMode(_DIN,OUTPUT);
pinMode(_SCK,OUTPUT);
pinMode(_SYNC,OUTPUT);
}
void DAC855X::initializeDAC855X() {
Serial.begin(9600);
// initialize pins:
digitalWrite(_SYNC, HIGH);
delay(1);
SPI.begin();// initialize SPI
delay(1);
SPI.beginTransaction(SPISettings(16000000, MSBFIRST, SPI_MODE1));
delay(100);
}
void DAC855X::setChipChanValue(int CHIPX, int chan, int value) {
int header;
//Choose of chips and channels - define the header byte
switch(CHIPX) {
case 0: //DAC8550 and 8551
header = 0x00;
break;
case 1: //DAC8552
switch(chan) {
case 0: //Channel A
header = 0x10;
break;
case 1: //Channel B
header = 0x24;
break;
default:
Serial.println("Wrong channel for DAC8552. Choose 0, 1. Using default = 0");
header = 0x10;
}
break;
case 2: //DAC8554 and 8555
switch(chan) {
case 0: //Channel A
header = 0x00;
break;
case 1: //Channel B
header = 0x04;
break;
case 2: //Channel C
header = 0x08;
break;
case 3: //Channel D
header = 0x0C;
break;
default:
Serial.println("Wrong channel for DAC8554. Choose 0, 1, 2 or 3. Using default = 0");
header = 0x00;
}
break;
default:
Serial.println("Wrong DAC. Choose 0, 1 or 2");
}
digitalWrite(_SYNC, LOW); //Turn on the transfer
byte hiByte = highByte(value); //Divides the integer into two bytes
byte loByte = lowByte(value);
SPI.transfer(header); //Transfer configuration byte
SPI.transfer(hiByte); //Transfer data bytes 15 to 8
SPI.transfer(loByte); //Transfer data bytes 7 to 0
digitalWrite(_SYNC, HIGH); //Turn off the transfer
}
Example
//This program exemplifies the use
//of the library on a Texas Instruments
//DAC8552 2-channel chip. Channel A
//will make a saw tooth wave, and
//channel B will make a sine wave, sumultaneously.
#include <DAC855X.h>
DAC855X dac;
const float radian = 0.000488281F;
uint32_t sen;
float numpi = 0.0;
void setup() {
dac.setPins(11, 13, 10);
dac.initializeDAC855X();
}
void loop() {
for (int i=1; i<4096; i=i+4){
int dacA = i*16; // Channel A shows the sawtooth wave
dac.setChipChanValue(1, 0, dacA); // DAC8552 chip, channel A
int ChA = analogRead(0);
delay(10);
Serial.print("Channel A = ");
Serial.print(ChA);
numpi = PI*radian*i; //Channel B shows the sinewave
int dacB = (1+(sin(numpi)))*32768;
dac.setChipChanValue(1, 1, dacB); // DAC8552 chip, channel B
delay(10);
int ChB = analogRead(1);
Serial.print("\t Channel B = ");
Serial.println(ChB);
delay(100);
}
}