| 
 NS4168 是一颗I2S 输入,2.5W 单声道音频功放,就是能将I2S的声音放大提供给喇叭使用。这次测试的是DFRobot 的FireBeetle 配合NS4168 工作。   NS4168 电路图如下:  
  
 PCB 设计如下:  
 左侧J1是留出的接口,右侧SPK1和SPK2是用于连接喇叭的接口,这里可以选择接入2.0间距或者2.54间距接口的喇叭:  
  
 |    NS4168    |  |  |   |  |  |   |  | 根据  DataSheet 这个是用于选择输出  I2S 信号中哪一个声道的。这里直接接入3.3V。CTRL 管脚电压为 0.9V~1.15V 时,选择左声道; CTRL 管脚电压为 1.5 V~VDD 时,选择右声道。小于0.4V 时关闭 NS4168。   特别注意:这里如果接地或者悬空会导致喇叭没有声音。  |   |  | I2S 左右声道帧时钟。用于切换左右声道的数据。LRCLK 为“1”表示正在传输的是右声道的数据,为“0”则表示正在传输的是左声道的数据,LRCLK 的频率等于采样频率。  |   |  | 串行时钟 BCLK 也叫位时钟, 是 主机送出来的I2S时钟信号  |   |  |  |   |  |  |  
  
 测试使用C Arduino-audio-tools0.8.7 版本,具体的引脚定义可以在 \libraries\arduino-audio-tools-0.8.7\src\AudioConfig.h  看到:  
 
			
			
			- #define PWM_FREQENCY 30000
 - #define PIN_PWM_START 12
 - #define PIN_I2S_BCK 14
 - #define PIN_I2S_WS 15
 - #define PIN_I2S_DATA_IN 4
 - 
 - #define PIN_I2S_DATA_OUT 22
 - #define I2S_USE_APLL false
 
  复制代码
 代码位于\libraries\arduino-audio-tools-0.8.7\examples\examples-stream\streams-generator-i2s中,是通过I2S输出一个正弦波:  
 - /**
 -  * @file streams-generator-i2s.ino
 -  * @author Phil Schatzmann
 -  * @brief see https://github.com/pschatzmann/arduino-audio-tools/blob/main/examples/examples-stream/streams-generator-i2s/README.md 
 -  * @copyright GPLv3
 -  */
 -  
 - #include "AudioTools.h"
 - 
 - uint16_t sample_rate=44100;
 - uint8_t channels = 2;                                      // The stream will have 2 channels 
 - SineWaveGenerator<int16_t> sineWave(32000);                // subclass of SoundGenerator with max amplitude of 32000
 - GeneratedSoundStream<int16_t> sound(sineWave);             // Stream generated from sine wave
 - I2SStream out; 
 - StreamCopy copier(out, sound);                             // copies sound into i2s
 - 
 - // Arduino Setup
 - void setup(void) {  
 -   // Open Serial 
 -   Serial.begin(115200);
 -   while(!Serial);
 -   AudioLogger::instance().begin(Serial, AudioLogger::Info);
 - 
 -   // start I2S
 -   Serial.println("starting I2S...");
 -   auto config = out.defaultConfig(TX_MODE);
 -   config.sample_rate = sample_rate; 
 -   config.channels = channels;
 -   config.bits_per_sample = 16;
 -   out.begin(config);
 - 
 -   // Setup sine wave
 -   sineWave.begin(channels, sample_rate, N_B4);
 -   Serial.println("started...");
 - }
 - 
 - // Arduino loop - copy sound to out 
 - void loop() {
 -   copier.copy();
 - }  
 
  复制代码
  
 测试的工作视频在下面可以看到  
  
  
 |