打印
[应用方案]

NUC505播放SD卡内的MP3文件

[复制链接]
1684|8
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
springvirus|  楼主 | 2018-5-14 09:41 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 springvirus 于 2018-5-14 09:44 编辑

周末试了下NUC505的播放功能,直接用例程I2S_MP3PLAYER_SD播放,只是修改下MP3文件路径和名字

接上耳机,效果不错,可惜没法调音量,计划用TDA2822弄个小功放,再玩玩


沙发
dongnanxibei| | 2018-5-14 22:52 | 只看该作者
用的什么解码啊。

使用特权

评论回复
板凳
springvirus|  楼主 | 2018-5-15 08:11 | 只看该作者
本帖最后由 springvirus 于 2018-5-15 08:16 编辑

libmad + 内部的音频CODEC

使用特权

评论回复
地板
yiyigirl2014| | 2018-5-15 11:11 | 只看该作者
牛叉,貌似我有这个开发板,回去我找找

使用特权

评论回复
5
小灵通2018| | 2018-5-15 19:11 | 只看该作者
官方提供了这个播放MP3的例子吗

使用特权

评论回复
6
springvirus|  楼主 | 2018-5-16 08:23 | 只看该作者
小灵通2018 发表于 2018-5-15 19:11
官方提供了这个播放MP3的例子吗

是的,BSP包里有

使用特权

评论回复
7
玛尼玛尼哄| | 2018-5-16 11:12 | 只看该作者
/**************************************************************************//**
* [url=home.php?mod=space&uid=288409]@file[/url]     main.c
* [url=home.php?mod=space&uid=895143]@version[/url]  V2.1
* $Revision: 8 $
* $Date: 16/01/09 3:40p $
* [url=home.php?mod=space&uid=247401]@brief[/url]    A MP3 file player demo using internal audio codec used to playback MP3 file stored in SD card.
*
* @note
* Copyright (C) 2016 Nuvoton Technology Corp. All rights reserved.
*
******************************************************************************/
#include <stdio.h>
#include <string.h>
#include "NUC505Series.h"
#include "config.h"
#include "diskio.h"
#include "ff.h"

uint32_t volatile u32BuffPos = 0;

FATFS FatFs[_VOLUMES];               /* File system object for logical drive */

#ifdef __ICCARM__
#pragma data_alignment=32
BYTE Buff[16] ;                   /* Working buffer */
#endif

#ifdef __ARMCC_VERSION
__align(32) BYTE Buff[16] ;       /* Working buffer */
#endif

/*---------------------------------------------------------*/
/* User Provided RTC Function for FatFs module             */
/*---------------------------------------------------------*/
/* This is a real time clock service to be called from     */
/* FatFs module. Any valid time must be returned even if   */
/* the system does not support an RTC.                     */
/* This function is not required in read-only cfg.         */

unsigned long get_fattime (void)
{
    unsigned long tmr;

    tmr=0x00000;

    return tmr;
}

//---------------------------------------------------------
//--- Initial SD0 multi-function GPIO pin
//
// NUC505 support 3 groups of GPIO pins and SD sockets for same one SD port.
// Please select ONLY ONE configuration from them.
// 1. SD-A socket on daughter board + default SD0_Init(). (Default)
// 2. SD-B socket on main board + short JP3 and JP4
//    + define compile flag "SDH_GPIO_GB" in SD0_Init().
//    (Note: this configuration conflict with UART1)
// 3. SD-C socket on main board + short JP3 and JP2
//    + define compile flag "SDH_GPIO_GA" in SD0_Init()
//    (Note: this configuration conflict with UART0)
//---------------------------------------------------------
void SD0_Init(void)
{
#ifdef SDH_GPIO_GA
    // The group A are GPA10~11, GPA13~15, GPB0~1
    // Conflict with UART0
    // printf("SD_Open(): Configure GPIO group A as SDH pins.\n");
    SYS->GPA_MFPH &= (~0x77707700);
    SYS->GPA_MFPH |=   0x44404400;
    SYS->GPA_MFPH &= (~0x00000077);
    SYS->GPB_MFPL |=   0x00000044;

#elif defined SDH_GPIO_GB
    // The group B are GPB2~3, GPB5~9
    // Conflict with UART1
    // printf("SD_Open(): Configure GPIO group B as SDH pins.\n");
    SYS->GPB_MFPL &= (~0x77707700);
    SYS->GPB_MFPL |=   0x44404400;
    SYS->GPB_MFPH &= (~0x00000077);
    SYS->GPB_MFPH |=   0x00000044;

#elif defined SDH_GPIO_G_48PIN
    // The group 48PIN are GPB0~3, GPB5~7 for NUC505 48PIN chip
    // Conflict with both UART0 and UART1
    // printf("SD_Open(): Configure special GPIO as SDH pins for 48 pins NUC505 chip.\n");
    SYS->GPB_MFPL &= (~0x77707777);
    SYS->GPB_MFPL |=   0x44404444;

#else   // default for defined SDH_GPIO_GC
    // The group C are GPC0~2, GPC4~7
    // printf("SD_Open(): Configure GPIO group C as SDH pins.\n");
    SYS->GPC_MFPL &= (~0x77770777);
    SYS->GPC_MFPL |=   0x11110111;
#endif
}

void SYS_Init(void)
{

/*---------------------------------------------------------------------------------------------------------*/
/* Init System Clock                                                                                       */
/*---------------------------------------------------------------------------------------------------------*/
    /* Unlock protected registers */
    //SYS_UnlockReg();
     
    /* Enable  XTAL */
//    CLK->PWRCTL |= CLK_PWRCTL_HXTEN_Msk;

        CLK_SetCoreClock(100000000);
   
                /* PCLK divider */
                CLK_SetModuleClock(PCLK_MODULE, NULL, 1);
               
    /* Lock protected registers */
    //SYS_LockReg();

                //--- Initial SD0 multi-function pin
    SD0_Init();
}

void UART0_Init(void)
{
                /* Enable UART0 Module clock */
    CLK_EnableModuleClock(UART0_MODULE);
                /* UART0 module clock from EXT */
                CLK_SetModuleClock(UART0_MODULE, CLK_UART0_SRC_EXT, 0);
    /* Reset IP */
    SYS_ResetModule(UART0_RST);   
    /* Configure UART0 and set UART0 Baud-rate */
                UART_Open(UART0, 115200);
                /*---------------------------------------------------------------------------------------------------------*/
    /* Init I/O Multi-function                                                                                 */
    /*---------------------------------------------------------------------------------------------------------*/
    /* Configure multi-function pins for UART0 RXD and TXD */
                SYS->GPB_MFPL  = (SYS->GPB_MFPL & (~SYS_GPB_MFPL_PB0MFP_Msk) ) | SYS_GPB_MFPL_PB0MFP_UART0_TXD;       
                SYS->GPB_MFPL  = (SYS->GPB_MFPL & (~SYS_GPB_MFPL_PB1MFP_Msk) ) | SYS_GPB_MFPL_PB1MFP_UART0_RXD;       
       
}

void I2S_Init(void)
{
                /* Enable I2S Module clock */
    CLK_EnableModuleClock(I2S_MODULE);
                /* I2S module clock from APLL */
        //FIXME APLL CLOCK
                // ideal clock is 49.152MHz, real clock is 49152031Hz
//        CLK_SET_APLL(CLK_APLL_49152031);        // APLL is 49152031Hz for 48000Hz
        CLK_SET_APLL(CLK_APLL_45158425);        // APLL is 45158425Hz for 44100Hz
        CLK_SetModuleClock(I2S_MODULE, CLK_I2S_SRC_APLL, 0);        // 0 means (APLL/1)
    /* Reset IP */
    SYS_ResetModule(I2S_RST);   
    /*---------------------------------------------------------------------------------------------------------*/
    /* Init I/O Multi-function                                                                                 */
    /*---------------------------------------------------------------------------------------------------------*/
    /* Configure multi-function pins for I2S */
                // GPC[8]  = MCLK
                // GPC[9]  = DIN
                // GPC[10] = DOUT
                // GPC[11] = LRCLK
                // GPC[12] = BCLK
                SYS->GPC_MFPH  = (SYS->GPC_MFPH & (~SYS_GPC_MFPH_PC8MFP_Msk) ) | SYS_GPC_MFPH_PC8MFP_I2S_MCLK;       
                SYS->GPC_MFPH  = (SYS->GPC_MFPH & (~SYS_GPC_MFPH_PC9MFP_Msk) ) | SYS_GPC_MFPH_PC9MFP_I2S_DIN;       
                SYS->GPC_MFPH  = (SYS->GPC_MFPH & (~SYS_GPC_MFPH_PC10MFP_Msk) ) | SYS_GPC_MFPH_PC10MFP_I2S_DOUT;       
                SYS->GPC_MFPH  = (SYS->GPC_MFPH & (~SYS_GPC_MFPH_PC11MFP_Msk) ) | SYS_GPC_MFPH_PC11MFP_I2S_LRCLK;       
                SYS->GPC_MFPH  = (SYS->GPC_MFPH & (~SYS_GPC_MFPH_PC12MFP_Msk) ) | SYS_GPC_MFPH_PC12MFP_I2S_BCLK;       
       
}

/*---------------------------------------------------------------------------------------------------------*/
/*  Main Function                                                                                          */
/*---------------------------------------------------------------------------------------------------------*/
int32_t main (void)
{
    /* Init System, IP clock and multi-function I/O */
    SYS_Init();

    /* Init UART0 to 115200-8n1 for print message */
    UART0_Init();

    printf("+------------------------------------------------------------------------+\n");
    printf("|                   MP3 Player Sample with Internal CODEC                |\n");
    printf("+------------------------------------------------------------------------+\n");
    printf(" Please put MP3 files on SD card \n");

    printf("rc=%d\n", (WORD)disk_initialize(0));
    disk_read(0, Buff, 2, 1);
    //f_mount(0, &FatFs[0]);  // for FATFS v0.09
                // Register work area to the default drive
    f_mount(&FatFs[0], "", 0);  // for FATFS v0.11

        /* Init I2S, IP clock and multi-function I/O */
        I2S_Init();

    MP3Player();

    while(1);
}

/*** (C) COPYRIGHT 2015 Nuvoton Technology Corp. ***/

使用特权

评论回复
8
玛尼玛尼哄| | 2018-5-16 11:12 | 只看该作者
太感谢了,终于知道哪个单片机可以播放MP3了。买个去。

使用特权

评论回复
9
springvirus|  楼主 | 2018-5-16 17:24 | 只看该作者

就是这个
只能说,新唐非常的给力!!

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

127

主题

4397

帖子

13

粉丝