TOSHIBA TC9459 test on UNO

Two years ago, I have tried to use TOSHIBA TC9459 volume control IC, but failed.
Yesterday, after successfully codeing Muses72323, I tried rewriteing the code for TC9459, it successfully made the IC working.
This is the testing schematic
15.JPG


the datasheet of TC9459
https://github.com/jerrylong-km/TOS...71ea65316247f8d16d08897f/东芝TC9459F-音量控制芯片.pdf
 
the testing code of UNO
/*
电子音量IC(TC9459F)功能测试代码,2024年2月
*/
#include <SPI.h>

//TC9459F与Arduino UNO连接
#define STB_Pin 10 //Arduino板的Digital #10接TC9459F的STB(#14)接口
#define DATA_Pin 11 //Arduino板的Digital #11接TC9459F的DATA(#13)接口
#define CK_Pin 13 //Arduino板的Digital #13接TC9459F的CK(#12)接口


//定义TC9459F的地址,和是否启用响度
const uint8_t Addr_Loudness = 0b10000000; //不启用响度,CS1和CS2都接地

uint8_t Volume = 0;//用于控制音量大小,根据TC9459F数据手册,最大音量为0dB,对应的寄存器写入值为0b0000000,最小音量为-89dB,对应的寄存器写入值为0b1001101
const uint8_t defaultVolume = 30;//默认音量,-30dB
void setup() {


//设置CS脚位
pinMode(STB_Pin, OUTPUT);
digitalWrite(STB_Pin, HIGH);

//初始化SPI
SPI.begin();
SPI.beginTransaction(SPISettings(250000, LSBFIRST, SPI_MODE0));//根据数据手册,芯片工作频率为0~1MHz,寄存器数据写入顺序为LSB


Serial.begin(115200); // output
}

void loop()
{

for (Volume = 0; Volume < 50; Volume++) //控制音量衰减由小到大(音量从大到小变化),衰减控制数值从0(0dB)增加到89(-89dB)
{
TC9459Write(Volume, Volume);
Serial.print("Volume=");
Serial.println(Volume);
delay(10);
}

for (Volume = 50; Volume > 0; Volume--) //控制音量衰减由大到小(音量从小到大变化),衰减控制数值从89(-89dB)减小到0(0dB)
{
TC9459Write(Volume, Volume);
Serial.print("Volume=");
Serial.println(Volume);
delay(10);
}

//TC9459Write(defaultVolume, defaultVolume);
//Serial.print("Volume=");
//Serial.println(defaultVolume);

}


//TC9459F写入函数
void TC9459Write(uint8_t leftAttenuation, uint8_t rightAttenuation)
{

//拉低CS脚电位,准备写入
digitalWrite(STB_Pin, LOW);
delayMicroseconds(1);

//写入数据
SPI.transfer(leftAttenuation);
SPI.transfer(rightAttenuation);
SPI.transfer(Addr_Loudness);

//拉高CS脚电位,完成写入
delayMicroseconds(1);
digitalWrite(STB_Pin, HIGH);
SPI.endTransaction();

}
 
Then I made a Lib of this IC
https://github.com/jerrylong-km/TOSHIBA_TC9459F.git

This is the code by using the lib
/*
使用Arduino UNO控制TOSHIBA TC9459F电子音量芯片
使用Jerry Long的TC9459库
By Jerry Long, 10 Feb 2024

TC9459芯片SPI接线:
STB(14#)——>SDL——>D10(SS)
Clock(12#)——>SCL——>D13(SCK)
Data(13#) ——>SDA——>D11(MOSI)

TC9459芯片模拟供电:
外接±15V电源,地A_GND
*/
#include <TC9459.h>

//定义TC9459芯片的地址(根据CS1-#9和CS2-#16脚位的高低电平)
static const byte TC9459_ADDRESS = 0b10000000;

//根据上述芯片地址创建TC9459对象
static TC9459 TC9459L(TC9459_ADDRESS);

//定义默认音量,当前音量,最大和最小音量
static TC9459::volume_t defaultVolume = 30; //重启后的默认音量--44dB
static TC9459::volume_t currentVolume = 20; //当前音量,-20dB开始
int MaxVolume = 0; //最大音量0dB
int MinVolume = 89; //最小音量-89dB

void setup() {
//设置串口波特率
Serial.begin(115200);

//初始化TC9459
TC9459L.begin();

//设置TC9459状态
TC9459L.turnOnLoudness(false); //不使用响度

//启动时设置为默认音量
TC9459L.setVolume(defaultVolume, defaultVolume);

}

void loop() {
// put your main code here, to run repeatedly:

for(int i = MaxVolume; i<MinVolume; i++)
{
currentVolume = i;
Serial.print("currentVolume = ");
Serial.println(currentVolume);
TC9459L.setVolume(currentVolume, currentVolume);
delay(30);
}

for (int i = MinVolume; i>MaxVolume; i--)
{
currentVolume = i;
Serial.print("currentVolume = ");
Serial.println(currentVolume);
TC9459L.setVolume(currentVolume, currentVolume);
delay(30);
}

// You can continue with the rest of your loop code here.
delay(100);
}