sta013.h By Zhi-Hern Loh

Home
Design
Results
A 2nd try
Schematics
Code
Files
Links
Contact

//STA013 register definitions
#define DLA           0x46
#define DLB           0x47
#define DRA           0x48
#define DRB           0x49
#define MFSFDF_411    0x50
#define PLLFRAC_411_L 0x51
#define PLLFRAC_411_R 0x52
#define PCMDIVIDER    0x54
#define PCMCONF       0x55
#define MSFDF_X       0x61
#define DAC_CLK_MODE  0x63
#define PLLFRAC_L     0x64
#define PLLFRAC_H     0x65
#define PLLCTRL       0x05
#define HEADH         0x43
#define HEADM         0x44
#define HEADL         0x45
#define ERROR_CODE    0x0f
#define PLAY	      0x13
#define MUTE	      0x14
#define DATA_REQ_ENABLE 0x18   
#define RUN	      0x72      

//base address of the config data stored in eeprom
#define STA_CONFIG_ADDR 0x0000

//some convenient constants             
//following are names for the bits in 
//TWCR register
#define TWINT 	7 //TWI Interrupt flag
#define TWEA 	6 //TWI Enable ACK bit
#define TWSTA 	5 //TWI START condition bit
#define TWSTO 	4 //TWI STOP condition bit
#define TWWC	3 //TWI Write Collision flag
#define TWEN	2 //TWI Enable bit
#define TWIE	0 //TWI interrupt enable

//I2C STA013 address + r/w bit
#define STA_READ 	0x86 		//to write to STA013
#define STA_WRITE 	0x87//STA_READ + 1 	//to listen from STA013

//Mega128 TWI STATUS codes
#define TWI_START   0x08
#define TWI_R_START 0x10
//Master Reciever mode, for reading from STA013
//refer to page 209 of ATMEL documentation
#define MR_ARBF_NOT_ACK 	0x38 //arbitration fail
#define MR_ADD_ACK 		0x40
#define MR_NO_ACK		0x48
#define MR_DATA_ACK		0x50
#define MR_DATA_NO_ACK		0x58

//Master Transmitter mode
#define MT_ADD_ACK		0x18
#define MT_DATA_ACK		0x28

//define MACRO for sending START condition
#define I2C_START 	TWCR = (1<<TWINT)|(1<<TWSTA)|(1<<TWEN)
#define I2C_WAIT 	while(!(TWCR&(1<<TWINT)))
//#define I2C_READ	TWCR = (1<<TWINT) //clear TWINT flag check table 88 atmel doc
#define I2C_TRANSMIT 	TWCR = (1<<TWINT)|(1<<TWEN)//start transmission
#define I2C_STOP 	TWCR = (1<<TWINT)|(1<<TWEN)|(1<<TWSTO) //stop condition

//MP3 data interface
#define DATA_REQ 	PIND.5  //DATA_REQ high when STA013 requests a MP3 byte
#define SDI		PORTD.7 //Serial Data
#define SCKR		PORTD.6 //Serial Clk

void STA013_Init(void);
void Read_Eeprom(void);
void STA013_Audio_Send(unsigned char data);    
void STA013_Play_MP3(void);
void STA013_Play_Buffer(void);
void STA013_Audio_Stop(void);
void STA013_Test_Serial_Interface(void);
void STA013_Show_Info(void);//displays config info
void STA013_Write(unsigned char address, unsigned char data);

Home | Design | Results | A 2nd try | Schematics | Code | Files | Links | Contact

For problems or questions regarding this web contact Zhi-Hern Loh.
Last updated: 05/02/02.