《QN8035程序.doc》由会员分享,可在线阅读,更多相关《QN8035程序.doc(44页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、Readme:For ARMBefore using this code:- Make sure I2C address is matching datasheet- If i2c driver existed, then just ignore qnio.c/h- Modify QND_Deley(ms) to get accurate platform related miliseconds delay, otherwise all chips functionality may not working properly- Detail please read related doc or
2、 get FAEs helpqnio.h#define _QNIO_H_/* modify this according to I2C device address when you use standard I2C function like I2C_XXXX except AI2C_XXXX*/#define I2C_DEV0_ADDRESS 0x20#define I2C_TIMEOUT_TIME 10#define I2C_TIMEOUT_COUNT 8#define MS_DELAY_CONST 40/*end*/* The following routines is for LPC
3、214X ARM I/O definition. It is just as reference for program using 2-wire and 3-wire bus.* Pls make a further revision for your routines according to the following type.*/#define SDA 3 /P0.3#define SCL 2 /P0.2#define SEB 5 /P0.5#define MOD 8 /P0.8#define MCK 9 /P0.9#define CEN 10 /P0.10#define WS 7
4、/P0.7#define DIN 4 /P0.4#define SCL_1 (IO0SET=IO0SET|(1SCL)#define SCL_0 (IO0CLR=IO0CLR|(1SCL)#define SDA_1 (IO0SET=IO0SET|(1SDA)#define SDA_0 (IO0CLR=IO0CLR|(1SDA)#define SEB_1 (IO0SET=IO0SET|(1SEB)#define SEB_0 (IO0CLR=IO0CLR|(1SEB)#define MOD_1 (IO0SET=IO0SET|(1MOD)#define MOD_0 (IO0CLR=IO0CLR|(1
5、MOD)#define MCK_1 (IO0SET=IO0SET|(1MCK)#define MCK_0 (IO0CLR=IO0CLR|(1MCK)#define CEN_1 (IO0SET=IO0SET|(1CEN)#define CEN_0 (IO0CLR=IO0CLR|(1CEN)#define WS_1 (IO0SET=IO0SET|(1WS)#define WS_0 (IO0CLR=IO0CLR|(1WS)#define DIN_1 (IO0SET=IO0SET|(1DIN) /TX MODE#define DIN_0 (IO0CLR=IO0CLR|(1SDA & 1) #defin
6、e Set_Datain (IO0DIR =IO0DIR & (1SDA)#define Set_Dataout (IO0DIR =IO0DIR|(10; dly-) for(i=0; iMS_DELAY_CONST; i+);/* Name: I2C_subfunction* Function: Software i2c code */void Set_SCL(UINT8 i) if(i) SCL_1; else SCL_0; void Set_SDA(UINT8 i) if(i) Set_Datain; else Set_Dataout; SDA_0; void Start(void) M
7、sdelay(1); Set_SCL(1); Msdelay(1); Set_SDA(1); Msdelay(1); Set_SDA(0); Msdelay(2); Set_SCL(0);void Stop(void) Msdelay(1); Set_SDA(0); Msdelay(1); Set_SCL(1); Msdelay(2); Set_SDA(1);void Send_ACK(UINT8 i) /i=0 for ACK and i=1 for Nack Set_SDA(i); Msdelay(1); Set_SCL(1); Msdelay(1); Set_SCL(0); Msdela
8、y(1); Set_SDA(1); void Check_ACK(void) Set_Datain; Msdelay(1); Set_SCL(1);qnd_i2c_timeout = (UINT8) Read_SDA; Msdelay(1); Set_SCL(0); Set_Dataout;void Write_Bit(UINT8 i) Msdelay(1); Set_SDA(i); Msdelay(1); Set_SCL(1); Msdelay(2); Set_SCL(0);void Write_Byte(UINT8 Data) UINT8 i; for( i = 0;i 7); Data=
9、1; UINT8 Read_Byte(void) UINT8 Data1=0x00; UINT8 j;Set_Datain; for( j = 0;j 8;j+) Msdelay(1); Set_SCL(1); Data1 = (Data11) | (UINT8) Read_SDA & 0x01); Msdelay(1); Set_SCL(0); Set_Dataout; return Data1; /* Name: I2C_Write_1byte * Funcation:write a data to a desired * register through i2c bus * Descri
10、ption: Slave-device address* Regis_Addr-register address*/UINT8 I2C_Write_1byte(UINT8 Slave,UINT8 Regis_Addr,UINT8 Data) UINT8 temp; temp=Slave; Start(); Write_Byte(temp); Check_ACK(); if (!qnd_i2c_timeout) Write_Byte(Regis_Addr); Check_ACK(); if (!qnd_i2c_timeout) Write_Byte(Data); Check_ACK(); Sto
11、p(); return !qnd_i2c_timeout; /* Name: I2C_Read_1byte * Function: Read a data from a desired register * through i2c bus * Description: Slave-device address* Regis_Addr-register address*/UINT8 I2C_Read_1byte(UINT8 Slave,UINT8 Regis_Addr) UINT8 Data=0x00; UINT8 temp; temp =Slave | 0x01; Start(); Write
12、_Byte(Slave); Check_ACK(); if (!qnd_i2c_timeout) Write_Byte(Regis_Addr); Check_ACK(); if(!qnd_i2c_timeout) /stop(); Start(); Write_Byte(temp); Check_ACK(); if (!qnd_i2c_timeout) Data = Read_Byte(); Send_ACK(1); Stop(); return Data; /* * Name: I2C_Read_nbyte * Function: Read n data from a desired reg
13、ister * through i2c bus * Description: Slave-device address * Regis_Addr-register address */ UINT8 I2C_Read_nbyte(UINT8 Slave,UINT8 Regis_Addr, UINT8 *buf, UINT8 n) UINT8 Data=0x00; UINT8 temp; UINT8 i; temp =Slave | 0x01; Start(); Write_Byte(Slave); Check_ACK(); if(!qnd_i2c_timeout) Write_Byte(Regi
14、s_Addr); Check_ACK(); if (!qnd_i2c_timeout)/stop(); Start(); Write_Byte(temp); Check_ACK(); if (!qnd_i2c_timeout) Set_Datain; for(i=0; in-1; i+) bufi = Read_Byte();Send_ACK(0); bufi = Read_Byte();Send_ACK(1); Stop(); return !qnd_i2c_timeout; /* Name: I2C_Write_nbyte* Function: Write n bytes data to
15、register * through i2c bus * Description: Slave-device address*Regis_Addr-register address*/UINT8 I2C_Write_nbyte(UINT8 Slave,UINT8 Regis_Addr, UINT8 *buf, UINT8 n) UINT8 temp;UINT8 i; temp=Slave; Start(); Write_Byte(temp); Check_ACK(); if(!qnd_i2c_timeout) Write_Byte(Regis_Addr); Check_ACK(); for(i
16、=0; (in) & !qnd_i2c_timeout; i+)Write_Byte(bufi); Check_ACK(); Stop(); return !qnd_i2c_timeout;extern UINT8 qnd_DevIndex;UINT8 QND_WriteReg(UINT8 Regis_Addr,UINT8 Data)return QND_I2C_WRITE(Regis_Addr,Data); return 1;UINT8 QND_ReadReg(UINT8 Regis_Addr) UINT8 Data;Data = QND_I2C_READ(Regis_Addr); retu
17、rn Data;UINT8 QND_I2C_WRITE(UINT8 Regis_Addr,UINT8 Data) UINT8 ret; UINT8 tryCount = I2C_TIMEOUT_COUNT;qnd_i2c = 1; while(-tryCount) ret = I2C_Write_1byte(I2C_DEV0_ADDRESS, Regis_Addr, Data); if(ret) break; if(!tryCount) SPRINTF(QND_I2C_WRITE error!n);return 0; qnd_i2c = 0;return 1;UINT8 QND_I2C_REA
18、D(UINT8 Regis_Addr) UINT8 ret; UINT8 tryCount = I2C_TIMEOUT_COUNT;qnd_i2c = 1; while(-tryCount) ret = I2C_Read_1byte(I2C_DEV0_ADDRESS, Regis_Addr); if(!qnd_i2c_timeout) break; if(!tryCount) SPRINTF(QND_I2C_READ error!n); qnd_i2c = 0;return ret;UINT8 QND_I2C_NREAD(UINT8 Regis_Addr, UINT8 *buf, UINT8
19、n) UINT8 ret; UINT8 tryCount = I2C_TIMEOUT_COUNT; qnd_i2c = 1; while(-tryCount) ret = I2C_Read_nbyte(I2C_DEV0_ADDRESS, Regis_Addr, buf, n); if(!qnd_i2c_timeout) break; if(!tryCount) SPRINTF(QND_I2C_READ error!n); qnd_i2c = 0; return ret;UINT8 QND_I2C_NWRITE(UINT8 Regis_Addr, UINT8 *buf, UINT8 n) UIN
20、T8 ret; UINT8 tryCount = I2C_TIMEOUT_COUNT; qnd_i2c = 1; while(-tryCount) ret = I2C_Write_nbyte(I2C_DEV0_ADDRESS, Regis_Addr, buf, n); if(!qnd_i2c_timeout) break; if(!tryCount) SPRINTF(QND_I2C_READ error!n); qnd_i2c = 0; return ret;/* end file */qndriver.h/*Copyright(c)* Quintic(Nanjing) Microelectr
21、onics Co,Ltd.* * *-* : qndriver.h* subversion number: 160 *-*/#ifndef _QNDRIVER_H#define _QNDRIVER_H#define QN_8035#define _QNFUNC_H_#define CCS_RX 0#define CCS_TX 1#define FREQ2CHREG(freq) (freq-6000)/5)#define CHREG2FREQ(ch) (ch*5+6000)#define _QNCOMMON_H_#define QND_REG_NUM_MAX 85 / for qn8035/ c
22、rystal setting definition is not ready yet, please read datasheet to do setting accordingly#define QND_CRYSTAL_REG 0x03#define QND_CRYSTAL_BIT_MASK 0x3f#define QND_CRYSTAL_24MHZ 0x40#define QND_CRYSTAL_DEFAULT QND_CRYSTAL_24MHZ#define QND_MODE_SLEEP 0 #define QND_MODE_WAKEUP 1#define QND_MODE_DEFAUL
23、T 2/ RX / TX value is using upper 8 bit#define QND_MODE_RX 0x8000#define QND_MODE_TX 0x4000/ AM / FM value is using lower 8 bit / need to check datasheet to get right bit #define QND_MODE_FM 0x0000#define BAND_FM 0/ tune#define QND_FSTEP_50KHZ 0#define QND_FSTEP_100KHZ 1#define QND_FSTEP_200KHZ 2/ o
24、utput format#define QND_OUTPUT_ANALOG 0#define QND_OUTPUT_IIS 1/ stereo mode#define QND_TX_AUDIO_MONO 0x10#define QND_TX_AUDIO_STEREO 0x00#define QND_RX_AUDIO_MONO 0x20#define QND_RX_AUDIO_STEREO 0x00#define QND_CONFIG_MONO 0x01#define QND_CONFIG_MUTE 0x02 #define QND_CONFIG_SOFTCLIP 0x03#define QND
25、_CONFIG_AUTOAGC 0x04#define QND_CONFIG_AGCGAIN 0x05 #define QND_CONFIG_EQUALIZER 0x06 #define QND_CONFIG_VOLUME 0x07 #define QND_CONFIG_BASS_QUALITY 0x08#define QND_CONFIG_BASS_FREQ 0x09#define QND_CONFIG_BASS_GAIN 0x0a#define QND_CONFIG_MID_QUALITY 0x0b#define QND_CONFIG_MID_FREQ 0x0c#define QND_CO
26、NFIG_MID_GAIN 0x0d#define QND_CONFIG_TREBLE_FREQ 0x0e#define QND_CONFIG_TREBLE_GAIN 0x0f#define QND_ENABLE_EQUALIZER 0x10#define QND_DISABLE_EQUALIZER 0x00#define QND_CONFIG_AUDIOPEAK_DEV 0x11#define QND_CONFIG_PILOT_DEV 0x12#define QND_CONFIG_RDS_DEV 0x13/ input format#define QND_INPUT_ANALOG 0#def
27、ine QND_INPUT_IIS 1/ i2s mode#define QND_I2S_RX_ANALOG 0x00#define QND_I2S_RX_DIGITAL 0x40#define QND_I2S_TX_ANALOG 0x00#define QND_I2S_TX_DIGITAL 0x20/i2s clock data rate#define QND_I2S_DATA_RATE_32K 0x00#define QND_I2S_DATA_RATE_40K 0x10#define QND_I2S_DATA_RATE_44K 0x20#define QND_I2S_DATA_RATE_4
28、8K 0x30/i2s clock Bit Wise#define QND_I2S_BIT_8 0x00#define QND_I2S_BIT_16 0x40#define QND_I2S_BIT_24 0x80#define QND_I2S_BIT_32 0xc0/i2s Control mode#define QND_I2S_MASTER 1#define QND_I2S_SLAVE 0/i2s Control mode#define QND_I2S_MSB 0x00#define QND_I2S_I2S 0x01#define QND_I2S_DSP1 0x02#define QND_I2S_DSP2 0x03#define QND_I2S_LSB 0x04#define QND_EQUALIZE_BASS 0x00#define QND_EQUALIZE_MID 0x01#define QND_EQUALIZE_TREBLE 0x02/ RDS, TMC#define QND_EUROPE_FLEXIBILITY_DISABLE 0#define QND_EUROPE_FLEXIBILITY_ENABLE 1#define QND_RDS_OFF 0#define QND_RDS_ON 1#define QND_RDS_BUFFER_NOT_READY 0#define