audio - PIC32MX : SPI1CON. SPIBUSY 位永远不会被清除

标签 audio spi mplab pic32 i2s

我正在尝试使用 PIC32MX250F128B 通过 I2S 与 DAC+放大器从模块 (MAX98257) 通信来生成简单的正弦波声音。最终目标是为学校项目制作带键盘的合成器。
我用 MPLABX (v.5.40) 创建了一个基本项目我现在没有使用 Harmony 或任何其他框架,我只是想拥有一个基本的声音生成、工作代码。
这是代码:
微 Controller 配置位:

// DEVCFG3
#pragma config USERID = 0xFFFF          // Enter Hexadecimal value (Enter Hexadecimal value)
#pragma config PMDL1WAY = ON            // Peripheral Module Disable Configuration (Allow only one reconfiguration)
#pragma config IOL1WAY = ON             // Peripheral Pin Select Configuration (Allow only one reconfiguration)
#pragma config FUSBIDIO = ON            // USB USID Selection (Controlled by the USB Module)
#pragma config FVBUSONIO = ON           // USB VBUS ON Selection (Controlled by USB Module)

// DEVCFG2
#pragma config FPLLIDIV = DIV_2         // PLL Input Divider (2x Divider)
#pragma config FPLLMUL = MUL_18         // PLL Multiplier (18x Multiplier)
#pragma config UPLLIDIV = DIV_12        // USB PLL Input Divider (12x Divider)
#pragma config UPLLEN = OFF             // USB PLL Enable (Disabled and Bypassed)
#pragma config FPLLODIV = DIV_1         // System PLL Output Clock Divider (PLL Divide by 1)

// DEVCFG1
#pragma config FNOSC = PRIPLL           // Oscillator Selection Bits (Primary Osc w/PLL (XT+,HS+,EC+PLL))
#pragma config FSOSCEN = ON             // Secondary Oscillator Enable (Enabled)
#pragma config IESO = ON                // Internal/External Switch Over (Enabled)
#pragma config POSCMOD = XT             // Primary Oscillator Configuration (XT osc mode)
#pragma config OSCIOFNC = OFF           // CLKO Output Signal Active on the OSCO Pin (Disabled)
#pragma config FPBDIV = DIV_2           // Peripheral Clock Divisor (Pb_Clk is Sys_Clk/2)
#pragma config FCKSM = CSDCMD           // Clock Switching and Monitor Selection (Clock Switch Disable, FSCM Disabled)
#pragma config WDTPS = PS1048576        // Watchdog Timer Postscaler (1:1048576)
#pragma config WINDIS = OFF             // Watchdog Timer Window Enable (Watchdog Timer is in Non-Window Mode)
#pragma config FWDTEN = OFF             // Watchdog Timer Enable (WDT Disabled (SWDTEN Bit Controls))
#pragma config FWDTWINSZ = WINSZ_25     // Watchdog Timer Window Size (Window Size is 25%)

// DEVCFG0
#pragma config JTAGEN = OFF             // JTAG Enable (JTAG Disabled)
#pragma config ICESEL = ICS_PGx1        // ICE/ICD Comm Channel Select (Communicate on PGEC1/PGED1)
#pragma config PWP = OFF                // Program Flash Write Protect (Disable)
#pragma config BWP = OFF                // Boot Flash Write Protect bit (Protection Disabled)
#pragma config CP = OFF                 // Code Protect (Protection Disabled)
SPI/I2S 配置 + 代码:
int sineTable[4096]= { ... };

int i = 0;

void main(void) {
    RPB5R = 0b0011; //pin 14 : SDO1 (data out)
    RPA0R = 0b0011; //pin 2 : SS1 (word select)
    
    SPI1CON2bits.AUDEN = 1; //audio protocol enabled
    SPI1CON2bits.AUDMONO = 1; //MONO mode
    SPI1CON2bits.AUDMOD = 0b00; //I2S mode
    SPI1CON2bits.IGNROV = 1; // Ignore Receive Overflow bit (for Audio Data Transmissions)
    SPI1CON2bits.IGNTUR = 1; //  Ignore Transmit Underrun bit (for Audio Data Transmissions) 1 = A TUR is not a critical error and zeros are transmitted until thSPIxTXB is not empty 0 = A TUR is a critical error which stop SPI operation

    SPI1BRG = 140;
    SPI1CONbits.MSTEN = 1;
    SPI1CONbits.MCLKSEL = 0; //Clock = Fpb
    SPI1CONbits.CKP = 1; //Idle state high, active state low
    SPI1CONbits.MODE32 = 1;
    SPI1CONbits.MODE16 = 0; //32 bit
    //SPI1CONbits.STXISEL = 0b11; //quand générer l'interruption?
    SPI1CONbits.DISSDI = 1; // disable serial data in
    SPI1CONbits.ENHBUF = 1; // enable enhanced buffer
    
    SPI1CONbits.ON = 0; //ON
    SPI1CONbits.ON = 1; //ON
    
    while(1)
    {
        SPI1BUF = sineTable[i];
        while( SPI1STATbits.SPIBUSY); // wait for transfer complete
        if(i >= 4095){
            i = 0;
        }
        i++;
    } // main loop 
} 
模拟行为:
在模拟中,代码似乎工作正常,但是状态寄存器(SPI1STAT)中的所有位都是 0 并且始终保持在 0(包括 SPIBUSY),这很奇怪。
目标行为:
我正在用面包板上的 Pickit3 对 PIC32 进行编程(ICSP,没有开发板)。我遵循数据表中指定的 PIC32MX 的基本连接,并连接了 DAC
我注意到:
  • 在我用 sinetable 中的第一个值填充 SPI1BUF 后设置 SPIBUSY。
  • 我没有在 watch 窗口中看到缓冲区(SPI1BUF)的值发生变化,而在模拟中我看到了(但这可能是正常的 idk)
  • 程序卡在 while 循环中,因为 SPIBUSY 从未被清除

  • 所以在模拟中,它似乎工作正常,可能是因为 SPI1BUSY 位永远不会改变(就像其他状态位一样)。
    对于目标,状态位似乎工作除了 SPI1BUSY 永远不会被清除。
    知道为什么会这样吗?
    谢谢

    最佳答案

    仔细检查 Pic32 SPI 的 FRM。在音频模式下使用时有特殊情况。

    关于audio - PIC32MX : SPI1CON. SPIBUSY 位永远不会被清除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64626018/

    相关文章:

    c - 为什么在此 MPLAB C 示例中使用 `extern`?

    vb.net - 如何在安装项目时将文件保存/安装到用户计算机的 C 驱动器中?

    macos - 如何用python3控制音量?

    beagleboneblack - 无法在 BeagleBone Green Wireless 上配置 SPI0

    c - 发送 2 个 SPI 字节问题

    c - 使用 C30 和 MPLAB X 的 switch 语句的奇怪行为

    c - Proteus 中伺服电机无法正常转动

    python - 如何使用Python从一次性音频样本中获取以赫兹为单位的音符?

    c# - 获取最大值的字节数组

    c - 通过 SPI 写入和读取闪存