Hi
In this code input to the DAC is sine wave so output is sine.
For testing quality of the DAC I want to replace input to it by signal applied to analog pin PA7.
This is what I did but it is not working.
#include "i2c_stretch.h"
#define DACDevice I2C1
//#define DACAddress 0x60
#define DACAddress 0x67
uint16_t sineLookup[20] = {2048, 2680, 3251, 3704, 3995, 4095, 3995, 3704, 3251, 2680, 2048, 1415, 844, 391, 100, 0, 100, 391, 844, 1415};
byte sinePos = 0;
bool toggle = 0;
int volt;
void setup()
{
volt= analogRead(PA7);
pinMode(PA7, INPUT_ANALOG);
pinMode(PA1, PWM);
pinMode(33, OUTPUT);
startCommunication();
initTimer();
}
void loop()
{
///////////////////
float volt = analogRead(PA7);
volt = (volt * 3.3) / 4095.0;
/////////////////////
if (i2c_str_IsError(DACDevice) | !i2c_str_PortEnabled(DACDevice))
{
digitalWrite(33, toggle = !toggle);
startCommunication();
}
delay(100);
}
void nextSample()
{
// i2c_str_sendBytes(DACDevice, sineLookup[sinePos] >> 8, sineLookup[sinePos++] & 255);
//sinePos %= 128;
////////////////////////////////////
i2c_str_sendBytes(DACDevice, volt);
sinePos %= 128;
////////////////////////////////////
}
void startCommunication()
{
i2c_str_InitPort(DACDevice, I2C_STRETCH_DIV_1200KHZ);
i2c_str_StartSending(DACDevice, DACAddress);
}
void initTimer()
{
nvic_irq_set_priority(NVIC_TIMER2, 0);
Timer2.setChannel1Mode(TIMER_OUTPUTCOMPARE);
Timer2.setPrescaleFactor(3);
Timer2.setOverflow(133); //should be about 60khz
Timer2.setCompare1(1);
Timer2.attachCompare1Interrupt(nextSample);
}
The error
C:\Users\Documents\Arduino\DAC_in_DAC_out\DAC_in_DAC_out.ino: In function 'void nextSample()':
DAC_in_DAC_out:42:35: error: too few arguments to function 'void i2c_str_sendBytes(i2c_dev*, uint8_t, uint8_t)'
i2c_str_sendBytes(DACDevice, volt);
^
In file included from C:\Users\ Documents\Arduino\DAC_in_DAC_out\DAC_in_DAC_out.ino:1:0:
C:\Users\ted\Documents\Arduino\libraries\MCP4725/i2c_stretch.h:36:6: note: declared here
void i2c_str_sendBytes(i2c_dev *dev, uint8_t data, uint8_t data2);
^~~~~~~~~~~~~~~~~
exit status 1
too few arguments to function 'void i2c_str_sendBytes(i2c_dev*, uint8_t, uint8_t)'
How to fix this line ?
i2c_str_sendBytes(DACDevice, volt);