<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[forum.rcl-radio.ru &mdash; DAC CS8416 + CS4398 (Arduino)(2)]]></title>
	<link rel="self" href="http://forum.rcl-radio.ru/extern.php?action=feed&amp;tid=225&amp;type=atom" />
	<updated>2021-12-29T17:25:10Z</updated>
	<generator>PunBB</generator>
	<id>http://forum.rcl-radio.ru/viewtopic.php?id=225</id>
		<entry>
			<title type="html"><![CDATA[Re: DAC CS8416 + CS4398 (Arduino)(2)]]></title>
			<link rel="alternate" href="http://forum.rcl-radio.ru/viewtopic.php?pid=4962#p4962" />
			<content type="html"><![CDATA[<p>Наконец-то до меня дошло ! Благодарю за терпение и подробный ответ!!!</p>]]></content>
			<author>
				<name><![CDATA[VyacheslavChernov1973]]></name>
				<uri>http://forum.rcl-radio.ru/profile.php?id=1604</uri>
			</author>
			<updated>2021-12-29T17:25:10Z</updated>
			<id>http://forum.rcl-radio.ru/viewtopic.php?pid=4962#p4962</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: DAC CS8416 + CS4398 (Arduino)(2)]]></title>
			<link rel="alternate" href="http://forum.rcl-radio.ru/viewtopic.php?pid=4961#p4961" />
			<content type="html"><![CDATA[<p>Например если взять модуль PCF8574 I2C для дисплеев LCD1602 то во всех скетчах указан адрес от 0x20 до 0x27, но в даташите указано:<br /><span class="postimg"><img src="http://forum.rcl-radio.ru/uploads/images/2021/12/0ad88b714f0b98c96104acce88ac6132.png" alt="http://forum.rcl-radio.ru/uploads/images/2021/12/0ad88b714f0b98c96104acce88ac6132.png" /></span> </p><p>что соответствует адресам от 0x40 до 0x4E</p><p>Но если к I2C обращаться через регистры:<br /> void i2c_write_1byte(byte i2c_addr, byte i2c_reg){<br />&nbsp; &nbsp;TWCR = (1&lt;&lt;TWINT)|(1&lt;&lt;TWSTA)|(1&lt;&lt;TWEN);&nbsp; // START<br />&nbsp; while (!(TWCR &amp; (1&lt;&lt;TWINT)));<br />&nbsp; &nbsp;<strong>TWDR = i2c_addr;</strong><br />&nbsp; &nbsp;TWCR = (1&lt;&lt;TWINT) | (1&lt;&lt;TWEN);<br />&nbsp; while (!(TWCR &amp; (1&lt;&lt;TWINT)));<br />&nbsp; &nbsp;TWDR = i2c_reg;<br />&nbsp; &nbsp;TWCR = (1&lt;&lt;TWINT) | (1&lt;&lt;TWEN);<br />&nbsp; while (!(TWCR &amp; (1&lt;&lt;TWINT)));<br />&nbsp; &nbsp;TWCR = (1&lt;&lt;TWINT)|(1&lt;&lt;TWEN)|(1&lt;&lt;TWSTO); // СТОП<br />&nbsp; } </p><p>То нужно указывать адрес как в даташите, для записи в младшем разряде указывать 0, а для чтения 1.</p>]]></content>
			<author>
				<name><![CDATA[liman324]]></name>
				<uri>http://forum.rcl-radio.ru/profile.php?id=2</uri>
			</author>
			<updated>2021-12-29T15:59:11Z</updated>
			<id>http://forum.rcl-radio.ru/viewtopic.php?pid=4961#p4961</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: DAC CS8416 + CS4398 (Arduino)(2)]]></title>
			<link rel="alternate" href="http://forum.rcl-radio.ru/viewtopic.php?pid=4960#p4960" />
			<content type="html"><![CDATA[<p>В последних версиях библиотеки Wire.h в функции:<br />Wire.beginTransmission();<br />нужно игнорировать младший разряд.</p>]]></content>
			<author>
				<name><![CDATA[liman324]]></name>
				<uri>http://forum.rcl-radio.ru/profile.php?id=2</uri>
			</author>
			<updated>2021-12-29T15:52:05Z</updated>
			<id>http://forum.rcl-radio.ru/viewtopic.php?pid=4960#p4960</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: DAC CS8416 + CS4398 (Arduino)(2)]]></title>
			<link rel="alternate" href="http://forum.rcl-radio.ru/viewtopic.php?pid=4959#p4959" />
			<content type="html"><![CDATA[<p>Вот из Гитхаба <a href="https://github.com/StephiB/CS8416/blob/master/CS8416.h">https://github.com/StephiB/CS8416/blob/master/CS8416.h</a></p><p>//&nbsp; Start-of-communication byte<br />#define CS8416_RD&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(0x01)&nbsp; &nbsp; &nbsp;// Read from a control register<br />#define CS8416_WR&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(0x00)&nbsp; &nbsp; &nbsp;// Write to a control register<br />#define CS8416_ADDR&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <strong>(0x20) </strong>&nbsp; &nbsp; // Identifying address<br />#define CS8416_WRITE_REG&nbsp; &nbsp; &nbsp; &nbsp; (CS8416_ADDR | CS8416_WR)&nbsp; &nbsp; &nbsp;// Start of write sequence<br />#define CS8416_READ_REG&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(CS8416_ADDR | CS8416_RD)&nbsp; &nbsp; &nbsp;// Start of read sequence</p><p>Так что, пока ясности нет...</p>]]></content>
			<author>
				<name><![CDATA[VyacheslavChernov1973]]></name>
				<uri>http://forum.rcl-radio.ru/profile.php?id=1604</uri>
			</author>
			<updated>2021-12-29T15:11:52Z</updated>
			<id>http://forum.rcl-radio.ru/viewtopic.php?pid=4959#p4959</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: DAC CS8416 + CS4398 (Arduino)(2)]]></title>
			<link rel="alternate" href="http://forum.rcl-radio.ru/viewtopic.php?pid=4958#p4958" />
			<content type="html"><![CDATA[<p>Я понял картинку из даташита так - <br /><span class="postimg"><img src="http://forum.rcl-radio.ru/uploads/images/2021/12/c45cfb8c1228775e5e9a6969fb091e93.jpg" alt="http://forum.rcl-radio.ru/uploads/images/2021/12/c45cfb8c1228775e5e9a6969fb091e93.jpg" /></span> <br />Очевидно, где-то недобрал. Благодарю за ответ, пошел курить матчасть.</p>]]></content>
			<author>
				<name><![CDATA[VyacheslavChernov1973]]></name>
				<uri>http://forum.rcl-radio.ru/profile.php?id=1604</uri>
			</author>
			<updated>2021-12-29T14:32:57Z</updated>
			<id>http://forum.rcl-radio.ru/viewtopic.php?pid=4958#p4958</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: DAC CS8416 + CS4398 (Arduino)(2)]]></title>
			<link rel="alternate" href="http://forum.rcl-radio.ru/viewtopic.php?pid=4956#p4956" />
			<content type="html"><![CDATA[<p>I2C адрес 7 бит, младший 8-й бит это бит запись\чтение</p>]]></content>
			<author>
				<name><![CDATA[liman324]]></name>
				<uri>http://forum.rcl-radio.ru/profile.php?id=2</uri>
			</author>
			<updated>2021-12-29T14:13:10Z</updated>
			<id>http://forum.rcl-radio.ru/viewtopic.php?pid=4956#p4956</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: DAC CS8416 + CS4398 (Arduino)(2)]]></title>
			<link rel="alternate" href="http://forum.rcl-radio.ru/viewtopic.php?pid=4955#p4955" />
			<content type="html"><![CDATA[<p>Прошу простить моё невежество, но - в даташите на CS8416 (страница 35) адрес I2C указан как 0010 AD2 AD1 AD0 0 - бинарный. При выводах 14, 15, 17, посаженных на 0, адрес должен быть 0b00100000 или 0x20.<br />В авторском скетче при обращении к 8416&nbsp; &quot;Wire.beginTransmission(0x10);&quot; - и все работает.<br />Прошу подсказать, в чем моя ошибка ?</p>]]></content>
			<author>
				<name><![CDATA[VyacheslavChernov1973]]></name>
				<uri>http://forum.rcl-radio.ru/profile.php?id=1604</uri>
			</author>
			<updated>2021-12-29T14:06:57Z</updated>
			<id>http://forum.rcl-radio.ru/viewtopic.php?pid=4955#p4955</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: DAC CS8416 + CS4398 (Arduino)(2)]]></title>
			<link rel="alternate" href="http://forum.rcl-radio.ru/viewtopic.php?pid=2622#p2622" />
			<content type="html"><![CDATA[<p>отличная работа, спасибо</p>]]></content>
			<author>
				<name><![CDATA[vasya_tarasov]]></name>
				<uri>http://forum.rcl-radio.ru/profile.php?id=848</uri>
			</author>
			<updated>2020-12-02T07:52:45Z</updated>
			<id>http://forum.rcl-radio.ru/viewtopic.php?pid=2622#p2622</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[DAC CS8416 + CS4398 (Arduino)(2)]]></title>
			<link rel="alternate" href="http://forum.rcl-radio.ru/viewtopic.php?pid=2485#p2485" />
			<content type="html"><![CDATA[<p>Доработка ЦАП<br /></p><ul><li><p>Доработан индикатор ERROR - нет звука отображается как &quot;NO SOUND&quot;, не подключен кабель COAX отображается как ERROR</p></li></ul><div class="codebox"><pre><code>#include &lt;Wire.h&gt; 
#include &lt;EEPROM.h&gt;
#include &lt;Encoder.h&gt;  // http://rcl-radio.ru/wp-content/uploads/2019/05/Encoder.zip
#include &lt;MsTimer2.h&gt; // http://rcl-radio.ru/wp-content/uploads/2018/11/MsTimer2.zip
#include &lt;LiquidCrystal_I2C.h&gt; //Библиотека -  http://forum.rcl-radio.ru/misc.php?action=pan_download&amp;item=45&amp;download=1
 LiquidCrystal_I2C lcd(0x27,16,2);  // Устанавливаем дисплей 
 Encoder myEnc(9, 8);//CLK, DT
      byte v1[8] = {0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07};
      byte v2[8] = {0x07,0x07,0x00,0x00,0x00,0x00,0x00,0x00};      
      byte v3[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x1F};
      byte v4[8] = {0x1F,0x1F,0x00,0x00,0x00,0x00,0x1F,0x1F};
      byte v5[8] = {0x1C,0x1C,0x00,0x00,0x00,0x00,0x1C,0x1C};
      byte v6[8] = {0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C};
      byte v7[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x07};
      byte v8[8] = {0x1F,0x1F,0x00,0x00,0x00,0x00,0x00,0x00};
      int a[3],vol,vol_d,menu,in,dem,form;
      byte i,d1,d2,d3,d4,d5,d6,e1,e2,e3;
      unsigned long times,times1,oldPosition  = -999,newPosition;
      bool w,w1,www=1,mute;
      byte dem_dac,dem_res,for_dac,for_res,err,err_old;

void setup(){
   Wire.begin();
   delay(100);
  // Serial.begin(9600);
   MsTimer2::set(3, to_Timer);MsTimer2::start();
   lcd.init();lcd.backlight();
   lcd.createChar(1, v1);lcd.createChar(2, v2);lcd.createChar(3, v3);lcd.createChar(4, v4);lcd.createChar(5, v5);lcd.createChar(6, v6);lcd.createChar(7, v7);lcd.createChar(8, v8);
   lcd.setCursor(0,0);lcd.print(&quot;CS8416  00&quot;);lcd.print(wireRead(0x10,0x7F),BIN);
   lcd.setCursor(0,1);lcd.print(&quot;CS4398  0&quot;);lcd.print(wireRead(0x4C,0x01),BIN);
   delay(2000);
   pinMode(10,INPUT);// SW 
   pinMode(11,INPUT_PULLUP); // кнопка MUTE
  if(EEPROM.read(100)!=0){for(int i=0;i&lt;101;i++){EEPROM.update(i,0);}}// очистка памяти при первом включении 
  vol = EEPROM.read(0);in = EEPROM.read(1);dem_dac = EEPROM.read(2);dem_res = EEPROM.read(3);for_dac = EEPROM.read(4);for_res = EEPROM.read(5);
// Write 8416
  Wire.beginTransmission(0x10);
  Wire.write (0x00);
//-------------------//
  Wire.write (0b00000000);
  Wire.write (0b10000010);// 128Fs
  Wire.write (0b00000000 + (dem_res &lt;&lt; 4));
  Wire.write (0b00000000);
  Wire.write (0b10000000 + (in &lt;&lt; 3));
  Wire.write (0b10000000 + (for_res));
  Wire.write (0xFF);
  Wire.write (0x00);
  Wire.write (0x00);
  Wire.write (0x00);
  Wire.endTransmission();
// End Write ////////////////////////////////////
delay(10);
// Write 4398 
  wireWrite(0x4C, 0x02, 0b00000010 + (dem_dac &lt;&lt; 2) + (for_dac &lt;&lt; 4));
  wireWrite(0x4C, 0x03, 0b00001001);// default
  wireWrite(0x4C, 0x04, 0b11000000);// default
  wireWrite(0x4C, 0x05, vol);
  wireWrite(0x4C, 0x06, vol);
  wireWrite(0x4C, 0x07, 0b10110000);// default
  wireWrite(0x4C, 0x08, 0b01000000);// default
  wireWrite(0x4C, 0x09, 0b00001000);// default
// End Write ////////////////////////////////////
  lcd.clear();
  }

void loop(){ 
  /// MENU //////////////////////////////
  if(digitalRead(10)==LOW){menu++;if(menu&gt;3){menu=0;};delay(200);lcd.clear();www=1;}

 /// MUTE /////////////////////////////
 if(digitalRead(11)==LOW &amp;&amp; mute==0){mute=1;wireWrite(0x4C, 0x04, 0b11011000);delay(300);www=1;} 
 if(digitalRead(11)==LOW &amp;&amp; mute==1){mute=0;wireWrite(0x4C, 0x04, 0b11000000);delay(300);www=1;}

 /// VOLUME ////////////////////////////
  if(menu==0){
  if (newPosition != oldPosition){oldPosition = newPosition;www=0;
     vol=vol+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w1=1;
      if(vol&lt;0){vol=0;}if(vol&gt;99){vol=99;}
      wireWrite(0x4C, 0x05, vol);
      wireWrite(0x4C, 0x06, vol);
  }
  if(www==1||w==1){www=0;w=0;
      if(mute==1){         lcd.setCursor(0,0);lcd.print(&quot;MUTE    &quot;);}
      if(err==0&amp;&amp;mute==0){ lcd.setCursor(0,0);lcd.print(&quot;VOLUME  &quot;);}
      if(err==22&amp;&amp;mute==0){lcd.setCursor(0,0);lcd.print(&quot;ERROR   &quot;);}
      if(err==8&amp;&amp;mute==0){ lcd.setCursor(0,0);lcd.print(&quot;NO SOUND&quot;);}
      
      lcd.setCursor(0,1);lcd.print(&quot;COAX &quot;);lcd.print(in);
     vol_d=99-vol;a[0]=vol_d/10;a[1]=vol_d%10;
      for(i=0;i&lt;2;i++){
      switch(i){
        case 0: e1=9,e2=10,e3=11;break;
        case 1: e1=12,e2=13,e3=14;break;
        }
      switch(a[i]){
        case 0: d1=1,d2=8,d3=6,d4=1,d5=3,d6=6;break;
        case 1: d1=32,d2=2,d3=6,d4=32,d5=32,d6=6;break;
        case 2: d1=2,d2=8,d3=6,d4=1,d5=4,d6=5;break;
        case 3: d1=2,d2=4,d3=6,d4=7,d5=3,d6=6;break;
        case 4: d1=1,d2=3,d3=6,d4=32,d5=32,d6=6;break;
        case 5: d1=1,d2=4,d3=5,d4=7,d5=3,d6=6;break;
        case 6: d1=1,d2=4,d3=5,d4=1,d5=3,d6=6;break;
        case 7: d1=1,d2=8,d3=6,d4=32,d5=32,d6=6;break;
        case 8: d1=1,d2=4,d3=6,d4=1,d5=3,d6=6;break;
        case 9: d1=1,d2=4,d3=6,d4=7,d5=3,d6=6;break;
    }
      lcd.setCursor(e1,0);lcd.write((uint8_t)d1);lcd.setCursor(e2,0);lcd.write((uint8_t)d2);lcd.setCursor(e3,0);lcd.write((uint8_t)d3);
      lcd.setCursor(e1,1);lcd.write((uint8_t)d4);lcd.setCursor(e2,1);lcd.write((uint8_t)d5);lcd.setCursor(e3,1);lcd.write((uint8_t)d6);
 }}
 }
 //////// INPUT ////////////////////////////////////  
  if(menu==1){
    if (newPosition != oldPosition){oldPosition = newPosition;
     in=in-newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w1=1;
      if(in&lt;0){in=0;}if(in&gt;7){in=7;}
  Wire.beginTransmission(0x10);
  Wire.write (0x00);
  Wire.write (0b00000000);
  Wire.write (0b10000010);
  Wire.write (0b00000000 + (dem_res &lt;&lt; 4));
  Wire.write (0b00000000);
  Wire.write (0b10000000 + (in &lt;&lt; 3));
  Wire.write (0b10000000 + (for_res));
  Wire.write (0xFF);
  Wire.write (0x00);
  Wire.write (0x00);
  Wire.write (0x00);
  Wire.endTransmission();}
  delay(10);
  if(www==1||w==1){www=0;w=0;
  lcd.setCursor(0,0);lcd.print(&quot;INPUT SELECTOR&quot;);  
  lcd.setCursor(0,1);lcd.print(&quot;COAXIAL &quot;); lcd.print(in);lcd.print(&quot; &quot;);
  }
  }

  /// DE-EMPHASIS //////////////////////////////////
  if(menu==2){
    if (newPosition != oldPosition){oldPosition = newPosition;
     dem=dem-newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w1=1;
      if(dem&lt;0){dem=0;}if(dem&gt;3){dem=3;}
  
  Wire.beginTransmission(0x10);
  Wire.write (0x00);
  Wire.write (0b00000000);
  Wire.write (0b10000010);
  Wire.write (0b00000000 + (dem_res &lt;&lt; 4));
  Wire.write (0b00000000);
  Wire.write (0b10000000 + (in &lt;&lt; 3));
  Wire.write (0b10000000 + (for_res));
  Wire.write (0xFF);
  Wire.write (0x00);
  Wire.write (0x00);
  Wire.write (0x00);
  Wire.endTransmission();
  delay(10);
  wireWrite(0x4C, 0x02, 0b00000010 + (dem_dac &lt;&lt; 2) + (for_dac &lt;&lt; 4));
  delay(10);
  }
  if(www==1||w==1){www=0;w=0;
  lcd.setCursor(0,0);lcd.print(&quot;DE-EMPHASIS SEL&quot;);  
  lcd.setCursor(0,1);
  switch(dem){
  case 0: lcd.print(&quot;No De-emphasis&quot;);dem_dac=0;dem_res=0;break;
  case 1: lcd.print(&quot;44.1 kHz      &quot;);dem_dac=1;dem_res=2;break;
  case 2: lcd.print(&quot;48.0 kHz      &quot;);dem_dac=2;dem_res=3;break;
  case 3: lcd.print(&quot;32.0 kHz      &quot;);dem_dac=3;dem_res=1;break;
  }
  }
  }

  /// Serial Format Select //////////////////////////////////
  if(menu==3){
    if (newPosition != oldPosition){oldPosition = newPosition;
     form=form-newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w1=1;
      if(form&lt;0){form=0;}if(form&gt;2){form=2;}
  
  Wire.beginTransmission(0x10);
  Wire.write (0x00);
  Wire.write (0b00000000);
  Wire.write (0b10000010);
  Wire.write (0b00000000 + (dem_res &lt;&lt; 4));
  Wire.write (0b00000000);
  Wire.write (0b10000000 + (in &lt;&lt; 3));
  Wire.write (0b10000000 + (for_res));
  Wire.write (0xFF);
  Wire.write (0x00);
  Wire.write (0x00);
  Wire.write (0x00);
  Wire.endTransmission();
  delay(10);
  wireWrite(0x4C, 0x02, 0b00000010 + (dem_dac &lt;&lt; 2) + (for_dac &lt;&lt; 4));
  delay(10);
  }
  if(www==1||w==1){www=0;w=0;
  lcd.setCursor(0,0);lcd.print(&quot;FORMAT SELECT&quot;);  
  lcd.setCursor(0,1);
  switch(form){
  case 0: lcd.print(&quot;L-Just 24 bit&quot;);for_dac=0;for_res=0;break;
  case 1: lcd.print(&quot;I2S    24 bit&quot;);for_dac=1;for_res=5;break;
  case 2: lcd.print(&quot;R-Just 24 bit&quot;);for_dac=3;for_res=8;break;
  }
  }
  }
  ////////////////////////////////////////////////////////
  
  delay(100);

  if(millis()-times1&gt;1000){times1=millis();err = wireRead(0x10,0x0C);delay(10);}
  if(err!=err_old){err_old = err;www=1;}

  if(millis()-times&gt;10000 &amp;&amp; w1==1){w1=0;EEPROM.update(0,vol);EEPROM.update(1,in);
  EEPROM.update(2,dem_dac);EEPROM.update(3,dem_res);EEPROM.update(4,for_dac);EEPROM.update(5,for_res);
  menu=0;www=1;lcd.clear();}
  
  }  

void wireWrite(byte addr, byte reg, byte data){
  Wire.beginTransmission(addr);
  Wire.write (reg);
  Wire.write (data);
  Wire.endTransmission();
  }

byte wireRead(int addr, int reg){
  Wire.beginTransmission(addr);
  Wire.write (reg);
  Wire.endTransmission();
  delay(10);
  Wire.requestFrom(addr,1);
  while(Wire.available()&lt;1);
  byte value = Wire.read();
  return value;
  }  

  
void to_Timer(){newPosition = myEnc.read()/4;}  

   </code></pre></div>]]></content>
			<author>
				<name><![CDATA[liman324]]></name>
				<uri>http://forum.rcl-radio.ru/profile.php?id=2</uri>
			</author>
			<updated>2020-11-17T14:21:23Z</updated>
			<id>http://forum.rcl-radio.ru/viewtopic.php?pid=2485#p2485</id>
		</entry>
</feed>
