This quick post is about the verification script which I did to test the PT8211 DAC functionality. This script is designed to work with Arduino boards and, I tested with Arduino Due and Arduino Mega 2560 boards.
The script is self-explanatory, and it emulates the I2S interface and communicates with the PT8211 DAC.
With this script, PT8211 generate sine wave in both channels. The frequency of the waveform is dependent on the clock frequency of the Arduino board. In Due board, PT8211 generates 0.052kHz sine wave on both channels.
The test setup is quite straightforward. I2S and power pins of PT8211 need to connect to the Arduino board in the following order:
Test script for Arduino is available in here:
The script is self-explanatory, and it emulates the I2S interface and communicates with the PT8211 DAC.
![]() |
The output waveform of PT8211 on Arduino Due board. |
With this script, PT8211 generate sine wave in both channels. The frequency of the waveform is dependent on the clock frequency of the Arduino board. In Due board, PT8211 generates 0.052kHz sine wave on both channels.
![]() |
Connections between PT8211 and Arduino. |
The test setup is quite straightforward. I2S and power pins of PT8211 need to connect to the Arduino board in the following order:
- Serial clock (BCK) - Pin 22
- Channel selector (WS) - Pin 23
- Data (DIN) - Pin 24
- VCC - 5V (Mega 2560 board) 3.3V (Due board)
- GND - GND
Test script for Arduino is available in here:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <limits.h> | |
#ifndef PIN_BCK | |
#define PIN_BCK 22 | |
#endif | |
#ifndef PIN_WS | |
#define PIN_WS 23 | |
#endif | |
#ifndef PIN_DIN | |
#define PIN_DIN 24 | |
#endif | |
#define NOP __asm__ __volatile__ ("nop\n\t") | |
void writeDACChannel(short waveData) | |
{ | |
unsigned char pos = 16; | |
// Send data into PT8211 in least significant bit justified (LSBJ) format. | |
while(pos > 0) | |
{ | |
pos--; | |
digitalWrite(PIN_BCK, LOW); | |
// Write next bit in stream into DIN. | |
digitalWrite(PIN_DIN, (waveData & (1 << pos)) ? HIGH : LOW); | |
NOP; | |
// Toggle BCK. | |
digitalWrite(PIN_BCK, HIGH); | |
NOP; | |
} | |
} | |
void writeDAC(short waveData) | |
{ | |
digitalWrite(PIN_WS, LOW); | |
digitalWrite(PIN_BCK, LOW); | |
// Write data into right channel of DAC. | |
writeDACChannel(waveData); | |
digitalWrite(PIN_WS, HIGH); | |
// Write data into left channel of DAC. | |
writeDACChannel(waveData); | |
} | |
void setup() | |
{ | |
pinMode(PIN_BCK, OUTPUT); | |
pinMode(PIN_WS, OUTPUT); | |
pinMode(PIN_DIN, OUTPUT); | |
} | |
void loop() | |
{ | |
short pos = 0; | |
while(pos < 360) | |
{ | |
pos += 5; | |
if(pos > 360) | |
{ | |
pos = 0; | |
continue; | |
} | |
writeDAC(sin(radians(pos)) * SHRT_MAX); | |
} | |
} |
Comments