| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| #include "vs1003.h"
|
| #include "SysTick.h"
|
|
|
|
|
| |
| |
| |
| |
| |
| |
|
|
| void VS1003_SPI_Init(void)
|
| {
|
| SPI_InitTypeDef SPI_InitStructure;
|
| GPIO_InitTypeDef GPIO_InitStructure;
|
|
|
|
|
| RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA |RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC , ENABLE);
|
|
|
| RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2 ,ENABLE);
|
|
|
|
|
| GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
|
| GPIO_InitStructure.GPIO_Speed =GPIO_Speed_50MHz;
|
| GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
|
| GPIO_Init(GPIOB, &GPIO_InitStructure);
|
|
|
|
|
| GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
|
| GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
| GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
| GPIO_Init(GPIOB, &GPIO_InitStructure);
|
|
|
|
|
| GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
|
| GPIO_Init(GPIOB, &GPIO_InitStructure);
|
|
|
|
|
|
|
| GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
|
| GPIO_Init(GPIOC, &GPIO_InitStructure);
|
|
|
|
|
| GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
|
| GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
|
| GPIO_Init(GPIOC, &GPIO_InitStructure);
|
|
|
|
|
| SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
|
| SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
|
| SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
|
| SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
|
| SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
|
| SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
|
| SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_32;
|
| SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
|
| SPI_InitStructure.SPI_CRCPolynomial = 7;
|
| SPI_Init(SPI2, &SPI_InitStructure);
|
|
|
|
|
| SPI_Cmd(SPI2, ENABLE);
|
| }
|
|
|
| |
| |
| |
| |
| |
| |
|
|
| u8 VS1003_WriteByte( u8 byte )
|
| {
|
| while(SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET);
|
| SPI_I2S_SendData(SPI2, byte);
|
| while(SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == RESET);
|
| return SPI_I2S_ReceiveData(SPI2);
|
| }
|
|
|
| |
| |
| |
| |
| |
| |
|
|
| u8 VS1003_ReadByte(void)
|
| {
|
| while(SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET);
|
| SPI_I2S_SendData(SPI2, 0);
|
| while(SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == RESET);
|
| return SPI_I2S_ReceiveData(SPI2);
|
| }
|
|
|
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| void Mp3WriteRegister(u8 addressbyte, u8 highbyte, u8 lowbyte)
|
| {
|
| TXDCS_SET(1);
|
| TCS_SET(0);
|
|
|
| VS1003_WriteByte( VS_WRITE_COMMAND );
|
| VS1003_WriteByte( addressbyte );
|
| VS1003_WriteByte( highbyte );
|
| VS1003_WriteByte( lowbyte );
|
|
|
| TCS_SET(1);
|
| }
|
|
|
| |
| |
| |
| |
| |
| |
|
|
| u16 Mp3ReadRegister(u8 addressbyte)
|
| {
|
| u16 resultvalue = 0;
|
| TXDCS_SET(1);
|
| TCS_SET(0);
|
|
|
| VS1003_WriteByte(VS_READ_COMMAND);
|
| VS1003_WriteByte((addressbyte));
|
| resultvalue = (unsigned int )(VS1003_ReadByte() << 8);
|
| resultvalue |= VS1003_ReadByte();
|
|
|
| TCS_SET(1);
|
| return resultvalue;
|
| }
|
|
|
| |
| |
| |
| |
| |
| |
|
|
| void MP3_Start(void)
|
| {
|
| u8 BassEnhanceValue = 0x00;
|
| u8 TrebleEnhanceValue = 0x00;
|
| TRST_SET(0);
|
| Delay_us( 1000 );
|
|
|
| VS1003_WriteByte(0xff);
|
| TXDCS_SET(1);
|
| TCS_SET(1);
|
| TRST_SET(1);
|
| Delay_us( 1000 );
|
|
|
| Mp3WriteRegister( SPI_MODE,0x08,0x00);
|
| Mp3WriteRegister(3, 0x98, 0x00);
|
| Mp3WriteRegister(5, 0xBB, 0x81);
|
| Mp3WriteRegister(SPI_BASS, TrebleEnhanceValue, BassEnhanceValue);
|
| Mp3WriteRegister(0x0b,0x00,0x00);
|
| Delay_us( 1000 );
|
|
|
| while( DREQ == 0 );
|
| }
|
|
|
|
|
|
|
|
|