hi all this is my model interface dac via i2c in arduino uno.i get some output but this is some small problem please any one help me.
the problem is only the data is transmit to the dac ic.
i need transmit continuously in the data please any one help me
code is:
#include <Wire.h>
#include <SoftwareSerial.h>
#define disk1 0xc0>>1//Address of 24aa32a eeprom chip
#include <stdlib.h>
#include <stdio.h>
//#define scl A5
//#define sda A6
char incomingByte;
unsigned int data;
unsigned int integerValue=4000;
int stringComplete =0;
void writeEEPROM(int deviceaddress, unsigned int eeaddress,unsigned int data )
{
Wire.beginTransmission(deviceaddress);
Wire.write((int)(eeaddress >> 8)); // MSB
Wire.write((int)(eeaddress & 0xFF)); // LSB
Wire.write((int)(data >> 8)); // MSB
Wire.write((int)(data & 0xFF));
//Wire.write(data);
delay(500);
Wire.endTransmission();
}
void setup(void)
{
Wire.begin();
TWBR = 12;
//pinMode(scl, OUTPUT);
// pinMode(sda, OUTPUT);
Serial.begin(9600);
}
void loop(){
//Wire.begin();
Serial.begin(9600);
unsigned int address;
//int a=0x03;
if (Serial.available()) {
integerValue = 0;
while(1) {
incomingByte = Serial.read();
if (incomingByte == '\ ') break;
if (incomingByte == -1) continue;
integerValue *= 10; // shift left 1 decimal place
// convert ASCII to integer, add, and shift left 1 decimal place
integerValue = ((incomingByte - 48) + integerValue);
//Serial.println( integerValue);
}
}
Serial.println( integerValue);
// Do something with the value
delay(1000);
writeEEPROM(disk1, address, integerValue);
//dac(disk1, address, a);
}
simmulation:
dac.ino (1.41 KB)