18
MCU aP89xxxxK CSB SCK DI BUSY LOAD S1(CSB) S2(SCK) S3(DI) OUT1( BUSY) OUT3( LOAD) VDDA,VDDP VSS,VPP VOUT1 VOUT2 COUT VDD C 104 CSB : Chip Select (active low, output from master). (Master) ( Slave) SCK : Serial Clock (output from master). DI : Master Output, Slave Input (output from master). BUSY : Master Input, Slave Output (output from slave). OUT1 as output from the Slave chip to the Master CPU for feedback response. LOAD : Master Input, Slave Output (output from slave). OUT3 as output from the Slave chip to the Master CPU for feedback response. SPI Mode

SPI&I2C-control timing&C code - aplusinc.com.t Voice Ic/SPI_I2C-control_timing_C_code.pdf · Title: Microsoft PowerPoint - SPI&I2C-control_timing&C_code.pptx Author: RD Created Date:

  • Upload
    lenhi

  • View
    224

  • Download
    0

Embed Size (px)

Citation preview

Page 1: SPI&I2C-control timing&C code - aplusinc.com.t Voice Ic/SPI_I2C-control_timing_C_code.pdf · Title: Microsoft PowerPoint - SPI&I2C-control_timing&C_code.pptx Author: RD Created Date:

MCU aP89xxxxK

CSBSCKDI

BUSYLOAD

S1(CSB)S2(SCK)S3(DI)

OUT1( BUSY)OUT3( LOAD)

VDDA,VDDP

VSS,VPP

VOUT1VOUT2

COUT

VDD

C 104

CSB : Chip Select (active low, output from master).

(Master) ( Slave)

SCK : Serial Clock (output from master).DI : Master Output, Slave Input (output from master).BUSY : Master Input, Slave Output (output from slave).

OUT1 as output from the Slave chip to the Master CPU for feedback response.LOAD : Master Input, Slave Output (output from slave).

OUT3 as output from the Slave chip to the Master CPU for feedback response.

SPI Mode

Page 2: SPI&I2C-control timing&C code - aplusinc.com.t Voice Ic/SPI_I2C-control_timing_C_code.pdf · Title: Microsoft PowerPoint - SPI&I2C-control_timing&C_code.pptx Author: RD Created Date:

Reset

Configure

Power On / External ResetThe Ext power on reset time depend on Crst .The Internal power on reset time . : Typ = 5usDevice configure time : 2ms

Step A Step A : Whether you want to play voices.NY

Step B Step B : CMD PU1 / PU2.

Active CMD : PU1/PU2,Load,PlayDe-Active CMD : PD1/PD2

Step C Step C : CMD Load.

Step D Step D : To detect whether the end of the LOAD signal.N

Step E Step E : Do you want to continue to play voices.YY

Process start

Step FN

Step F : CMD PD1 / PD2.

Step G Step G : After power down would like to continue to play voices.

Process endN

Y

Page 3: SPI&I2C-control timing&C code - aplusinc.com.t Voice Ic/SPI_I2C-control_timing_C_code.pdf · Title: Microsoft PowerPoint - SPI&I2C-control_timing&C_code.pptx Author: RD Created Date:

Reset

Configure

Power On / External ResetThe Ext power on reset time depend on Crst .The Internal power on reset time . : Typ = 5usDevice configure time : 2ms

Step 1 Step 1 : Whether you want to play voices.NY

Active CMD : PU1/PU2,Load,PlayDe-Active CMD : PD1/PD2

Step 2 Step 2 : CMD Play.

Step 3 Step 3 : To detect whether the end of the BUSY signal.N

Step 4 Step 4 : Do you want to continue to play voices.YY

Process start

Step 5N

Step 5 : CMD PD1 / PD2.

Step 6 Step 6 : After power down would like to continue to play voices.

Process endN

Y

Page 4: SPI&I2C-control timing&C code - aplusinc.com.t Voice Ic/SPI_I2C-control_timing_C_code.pdf · Title: Microsoft PowerPoint - SPI&I2C-control_timing&C_code.pptx Author: RD Created Date:

Step B : CMD PU1 (A400h) / PU2 (A800h)

void SoundChip_Active(unsigned int cmd){ CSB = 1;CSB = 0; //start conditionDelay20us(); //wait sleep to wake up state (20us)SPIdata(cmd); //power up chip with ramp-up or without ramp-upCSB = 1; //stop conditionDelay2ms(); //wait state exist wake up state ( 2ms)while(BUSY); //wait end of ramp (160ms)}

void SPIdata(unsigned int cmd){ unsigned int mask = 0;for(mask = 0x8000;mask > 0;mask >>=1){ DI = (cmd & mask) ? 1:0;SCK = 0;SCK = 1;}SCK = 0;}

Page 5: SPI&I2C-control timing&C code - aplusinc.com.t Voice Ic/SPI_I2C-control_timing_C_code.pdf · Title: Microsoft PowerPoint - SPI&I2C-control_timing&C_code.pptx Author: RD Created Date:

Step C : CMD Load (9400h) + Group Address

void SPIdata(unsigned int cmd){ unsigned int mask = 0;for(mask = 0x8000;mask > 0;mask >>=1){ DI = (cmd & mask) ? 1:0;SCK = 0;SCK = 1;}SCK = 0;}

void SoundChip_Load(unsigned int addr){ unsigned int cmd = 0;cmd = 0x9400 + addr;CS = 1;CS = 0; //start conditionSPIdata(cmd);CS = 1; //stop conditionDelay20us(); //for max output delay of BUSY/FULL signal}

Page 6: SPI&I2C-control timing&C code - aplusinc.com.t Voice Ic/SPI_I2C-control_timing_C_code.pdf · Title: Microsoft PowerPoint - SPI&I2C-control_timing&C_code.pptx Author: RD Created Date:

Step F : CMD PD1 (B400h) / PD2 (B800h)

void SPIdata(unsigned int cmd){ unsigned int mask = 0;for(mask = 0x8000;mask > 0;mask >>=1){ DI = (cmd & mask) ? 1:0;SCK = 0;SCK = 1;}SCK = 0;}

void SoundChip_DeActive(unsigned int cmd){ while(LOAD); //wait the last voice group be loadedwhile(BUSY); //wait the end of last voice groupCSB = 1;CSB = 0; //start conditionSPIdata(cmd) //power down chip with ramp-down or without ramp-downCSB = 1; //stop conditionwhile(BUSY); //wait end of ramp (160ms)}

Page 7: SPI&I2C-control timing&C code - aplusinc.com.t Voice Ic/SPI_I2C-control_timing_C_code.pdf · Title: Microsoft PowerPoint - SPI&I2C-control_timing&C_code.pptx Author: RD Created Date:

Step 2 : CMD Play (9800h) + Group Address

void SoundChip_Play(unsigned int addr){ unsigned int cmd = 0;cmd = 0x9800 + addr;CSB = 1;CSB = 0; //start conditionSPIdata(cmd);CSB = 1; //stop conditionDelay20us(); //for max output delay of BUSY/FULL signal}

void SPIdata(unsigned int cmd){ unsigned int mask = 0;for(mask = 0x8000;mask > 0;mask >>=1){ DI = (cmd & mask) ? 1:0;SCK = 0;SCK = 1;}SCK = 0;}

Page 8: SPI&I2C-control timing&C code - aplusinc.com.t Voice Ic/SPI_I2C-control_timing_C_code.pdf · Title: Microsoft PowerPoint - SPI&I2C-control_timing&C_code.pptx Author: RD Created Date:

void main(){ //The voices are PWM output.//unsigned char CheckBtn = 0; InitPortD();InitPortB();Delay10ms(); //waiting Reset time & Device configure time.while(1){ //Step A : Whether you want to play voices.PushBtn1(&CheckBtn); //Detecting whether a button is pressed. //---------------------------------if(CheckBtn == 1) //When button is pushed. { //----------------------------//Step B : CMD PU1SoundChip_Active(0xa400);//----------------------------//Step C : CMD LoadSoundChip_Load(0);while(FULL); //Step D : To detect whether the end of the LOAD signal.SoundChip_Load(1);while(FULL);SoundChip_Load(2);while(FULL);//----------------------------//When you do not want to play voices //Step F : CMD PD1 SoundChip_DeActive(0xb400);CheckBtn = 0;}}//while(1)}

Page 9: SPI&I2C-control timing&C code - aplusinc.com.t Voice Ic/SPI_I2C-control_timing_C_code.pdf · Title: Microsoft PowerPoint - SPI&I2C-control_timing&C_code.pptx Author: RD Created Date:

void main(){ //The voices are PWM output.//unsigned char CheckBtn = 0; InitPortD();InitPortB();Delay10ms(); //waiting Reset time & Device configure time. while(1){ //Step 1 : Whether you want to play voices.PushBtn1(&CheckBtn); //Detecting whether a button is pressed. //---------------------------------if(CheckBtn == 1) //When button is pushed. { //----------------------------//Step 2 : CMD PlaySoundChip_Play(0);while(BUSY); //Step 3 : To detect whether the end of the BUSY signal.SoundChip_Play(1);while(BUSY);SoundChip_Play(2);while(BUSY);//----------------------------//When you do not want to play voices //Step 5 : CMD PD1 SoundChip_DeActive(0xb400);CheckBtn = 0;}}//while(1)}

Page 10: SPI&I2C-control timing&C code - aplusinc.com.t Voice Ic/SPI_I2C-control_timing_C_code.pdf · Title: Microsoft PowerPoint - SPI&I2C-control_timing&C_code.pptx Author: RD Created Date:

MCU aP89xxxxK

SCKDI

BUSYLOAD

S2(SCK)S3(DI)

OUT1( BUSY)OUT3( LOAD)

VDDA,VDDP

VSS,VPP

VOUT1VOUT2

COUT

VDD

C 104

(Master) ( Slave)

SCK : Serial Clock (output from master).DI : Master Output, Slave Input (output from master).BUSY : Master Input, Slave Output (output from slave).

OUT1 as output from the Slave chip to the Master CPU for feedback response.LOAD : Master Input, Slave Output (output from slave).

OUT3 as output from the Slave chip to the Master CPU for feedback response.

I2C Mode

Page 11: SPI&I2C-control timing&C code - aplusinc.com.t Voice Ic/SPI_I2C-control_timing_C_code.pdf · Title: Microsoft PowerPoint - SPI&I2C-control_timing&C_code.pptx Author: RD Created Date:

Reset

Configure

Power On / External ResetThe Ext power on reset time depend on Crst .The Internal power on reset time . : Typ = 5usDevice configure time : 2ms

Step A Step A : Whether you want to play voices.NY

Step B Step B : CMD PU1 / PU2.

Active CMD : PU1/PU2,Load,PlayDe-Active CMD : PD1/PD2

Step C Step C : CMD Load.

Step D Step D : To detect whether the end of the LOAD signal.N

Step E Step E : Do you want to continue to play voices.YY

Process start

Step FN

Step F : CMD PD1 / PD2.

Step G Step G : After power down would like to continue to play voices.

Process endN

Y

Page 12: SPI&I2C-control timing&C code - aplusinc.com.t Voice Ic/SPI_I2C-control_timing_C_code.pdf · Title: Microsoft PowerPoint - SPI&I2C-control_timing&C_code.pptx Author: RD Created Date:

Reset

Configure

Power On / External ResetThe Ext power on reset time depend on Crst .The Internal power on reset time . : Typ = 5usDevice configure time : 2ms

Step 1 Step 1 : Whether you want to play voices.NY

Active CMD : PU1/PU2,Load,PlayDe-Active CMD : PD1/PD2

Step 2 Step 2 : CMD Play.

Step 3 Step 3 : To detect whether the end of the BUSY signal.N

Step 4 Step 4 : Do you want to continue to play voices.YY

Process start

Step 5N

Step 5 : CMD PD1 / PD2.

Step 6 Step 6 : After power down would like to continue to play voices.

Process endN

Y

Page 13: SPI&I2C-control timing&C code - aplusinc.com.t Voice Ic/SPI_I2C-control_timing_C_code.pdf · Title: Microsoft PowerPoint - SPI&I2C-control_timing&C_code.pptx Author: RD Created Date:

Step B : CMD PU1 (A400h) / PU2 (A800h)

void SoundChip_Active(unsigned int cmd){ SCK = 1; //start conditionDI = 1; //DI = 0; ////--------------//Delay20us(); //wait sleep to wake up state (20us)I2Cdata(cmd); //power up chip with ramp-up or without ramp-up//--------------//stop conditionDI = 0; //SCK = 1; //DI = 1; //Delay2ms(); //wait state exist wake up state (2ms)while(BUSY); //wait end of ramp (160ms)}

void I2Cdata(unsigned int cmd){ unsigned int mask = 0;for(mask = 0x8000;mask > 0;mask >>=1){ SCK = 0;DI = (cmd & mask) ? 1:0;SCK = 1;}SCK = 0;}

Page 14: SPI&I2C-control timing&C code - aplusinc.com.t Voice Ic/SPI_I2C-control_timing_C_code.pdf · Title: Microsoft PowerPoint - SPI&I2C-control_timing&C_code.pptx Author: RD Created Date:

Step C : CMD Load (9400h) + Group Address

void I2Cdata(unsigned int cmd){ unsigned int mask = 0;for(mask = 0x8000;mask > 0;mask >>=1){ SCK = 0;DI = (cmd & mask) ? 1:0;SCK = 1;}SCK = 0;}

void SoundChip_Load(unsigned int cmd){ unsigned int cmd = 0;cmd = 0x9400 + addr;SCK = 1; //start conditionDI = 1; //DI = 0; ////--------------//I2Cdata(cmd); //power up chip with ramp-up or without ramp-up//--------------//stop conditionDI = 0; //SCK = 1; //DI = 1; //Delay20us(); //for max output delay of BUSY/FULL signal}

Page 15: SPI&I2C-control timing&C code - aplusinc.com.t Voice Ic/SPI_I2C-control_timing_C_code.pdf · Title: Microsoft PowerPoint - SPI&I2C-control_timing&C_code.pptx Author: RD Created Date:

Step F : CMD PD1 (B400h) / PD2 (B800h)

void I2Cdata(unsigned int cmd){ unsigned int mask = 0;for(mask = 0x8000;mask > 0;mask >>=1){ SCK = 0;DI = (cmd & mask) ? 1:0;SCK = 1;}SCK = 0;}

void SoundChip_DeActive(unsigned int cmd){ while(FULL); //wait the last voice group be loadedwhile(BUSY); //wait the end of last voice groupSCK = 1; //start conditionDI = 1; //DI = 0; ////--------------//I2Cdata(cmd); //power up chip with ramp-up or without ramp-up//--------------//stop conditionDI = 0; //SCK = 1; //DI = 1; //while(BUSY); //wait end of ramp (160ms)}

Page 16: SPI&I2C-control timing&C code - aplusinc.com.t Voice Ic/SPI_I2C-control_timing_C_code.pdf · Title: Microsoft PowerPoint - SPI&I2C-control_timing&C_code.pptx Author: RD Created Date:

Step 2 : CMD Play (9800h) + Group Address

void I2Cdata(unsigned int cmd){ unsigned int mask = 0;for(mask = 0x8000;mask > 0;mask >>=1){ SCK = 0;DI = (cmd & mask) ? 1:0;SCK = 1;}SCK = 0;}

void SoundChip_Play(unsigned int cmd){ unsigned int cmd = 0;cmd = 0x9800 + addr;SCK = 1; //start conditionDI = 1; //DI = 0; ////--------------//I2Cdata(cmd); //power up chip with ramp-up or without ramp-up//--------------//stop conditionDI = 0; //SCK = 1; //DI = 1; //Delay20us(); //for max output delay of BUSY/FULL signal}

Page 17: SPI&I2C-control timing&C code - aplusinc.com.t Voice Ic/SPI_I2C-control_timing_C_code.pdf · Title: Microsoft PowerPoint - SPI&I2C-control_timing&C_code.pptx Author: RD Created Date:

void main(){ //The voices are DAC output.//unsigned char CheckBtn = 0; InitPortD();InitPortB();Delay10ms(); //waiting Reset time & Device configure time.while(1){ //Step A : Whether you want to play voices.PushBtn1(&CheckBtn); //Detecting whether a button is pressed. //---------------------------------if(CheckBtn == 1) //When button is pushed. { //----------------------------//Step B : CMD PU2SoundChip_Active(0xa800);//----------------------------//Step C : CMD LoadSoundChip_Load(0);while(FULL); //Step D : To detect whether the end of the LOAD signal.SoundChip_Load(1);while(FULL);SoundChip_Load(2);while(FULL);//----------------------------//When you do not want to play voices //Step F : CMD PD2 SoundChip_DeActive(0xb800);CheckBtn = 0;}}//while(1)}

Page 18: SPI&I2C-control timing&C code - aplusinc.com.t Voice Ic/SPI_I2C-control_timing_C_code.pdf · Title: Microsoft PowerPoint - SPI&I2C-control_timing&C_code.pptx Author: RD Created Date:

void main(){ //The voices are DAC output.//unsigned char CheckBtn = 0; InitPortD();InitPortB();Delay10ms(); //waiting Reset time & Device configure time. while(1){ //Step 1 : Whether you want to play voices.PushBtn1(&CheckBtn); //Detecting whether a button is pressed. //---------------------------------if(CheckBtn == 1) //When button is pushed. { //----------------------------//Step 2 : CMD PlaySoundChip_Play(0);while(BUSY); //Step 3 : To detect whether the end of the BUSY signal.SoundChip_Play(1);while(BUSY);SoundChip_Play(2);while(BUSY);//----------------------------//When you do not want to play voices //Step 5 : CMD PD2 SoundChip_DeActive(0xb800);CheckBtn = 0;}}//while(1)}