This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] TMS320F280025C:SPIA 工作正常、但 SPIB 会在数据中产生大量错误。

Guru**** 2457760 points
Other Parts Discussed in Thread: TMS320F280025C

请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/1026603/tms320f280025c-spia-working-perfectly-fine-but-spib-giving-lot-of-errors-in-data

器件型号:TMS320F280025C

我需要通过 SPI 接口将 TMS320F280025C 与另一个控制器连接。 280025C 配置为 SPI 从器件。 我使用了 SPI 示例4、该示例4使用具有 SPI TX 和 RX 缓冲器的 DMA 控制器。 DMA 的突发大小为8、传输大小为4。 因此、32个字进行一个完整的事务。 我已禁用内部回路、以便 SPI 从外部接收数据。  最初、我通过使用 SPIA 接口发送数据流(32个16位字)进行了测试。 控制器接收并打印数据、不会出现任何错误。 下一步、我修改了与 SPIB 接口相同的代码。 保持代码的其余部分不变仅更新了 SPIB 的 PinMux 设置、并将 DMA 通道分配给 SPIB 而不是 SPIA。 但是、SPIB 接口会在接收数据中产生大量错误。 例如、如果我重复发送2个32次的常量值、那么在 SPIB 缓冲区中接收到的数据如下所示:


DMA:2 2 2 258 2 1 2 2 2 0 2
2 2 2 0 2 258 2 2 2 2 2 2 2 2
2 258 1 7 2 2 2 0 2 2
2.



DMA:2 2 2 2 0 2 2 2 0 2 2
2 1 2 2 2 2 2 0 2 2
58 2 0 2 2 2 3 2 2 2 2 2 2 2 2
2.



DMA:2 2 6 2 2 2 2 0 2 2
6 1 2 2 2 0 2 2 2 2 2 2 2 2
0 2 2 2 6 2 2 2 2 2 0
2.

红色值为错误值。 SPIA 接口可正确读取数据、因此我不怀疑变速器控制器存在任何问题。 我已经使用 FIFO 中断测试了不带 DMA 的 SPIB 接口、但结果相同。 我花了2多天时间来解决这个问题,但都是徒劳的。 我怀疑 SPIB 中可能存在任何芯片问题? 请检查并告知我是否需要更正。


  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    阿萨德

    SPIB 的验证时间与 SPIA 一样长。 这可能是器件问题、这种可能性非常小。 从您的描述中、我看到的只是 您偶尔错误地获取 SPIB RX 数据。 我很难猜测可能是什么问题。 您是否能够共享主设备和从设备的代码? 您的 SPI 主设备是什么?

    此致、

    曼诺伊

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 Manoj:

       非常感谢大家分享初始想法。 要添加更多信息、我将 TMS320F280025C LaunchPad 用作 SPI 从设备。 对于主设备端、我使用 Arduino Due。 Arduino 代码非常简单、可与 SPIA 配合使用。 其给出如下:

    #include  
    #include  

    uint16_t  RX_Data =  0
    void  setup()
      // 将  您的设置 代码 放在这里, 运行  一次:
      Serial.begin(9600);
      SPI.begin();
      SPI.setDataMode(SPI_MODE0);
      SPI.setBitOrder(MSBFIRST);
      SPI.setClockDivider(168);//setting 时钟 为 84MHz/210= 500KHz  
      引脚模式(14、 输出);//连接  到 TMS320F280025C STE 引脚。
        

    void  loop()
      // 将  主 代码 放在此处,   重复运行:
      延迟(1000);
      while (1)
      {
        digitalWrite (14low);//将 STE 置 为低电平
        RX_Data =  SPI.transfer16 (2);//传输 16 位 值
        digitalWrite (14HIGH);//将 STE 置为 高电平
        serial.print ("SPI RX: ");
        serial.println (RX_Data);
        delayMicroseconds (5000);
      }
     SPIB 的 TMS320F280025C Launchpad 代码如下:
    //#############################################################################
    //
    // FILE:   spi_ex4_loopback_dma.c
    //
    // TITLE:  SPI Digital Loopback with DMA
    //
    //! \addtogroup driver_example_list
    //! <h1>SPI Digital Loopback with DMA</h1>
    //!
    //! This program uses the internal loopback test mode of the SPI module. Both
    //! DMA interrupts and the SPI FIFOs are used. When the SPI transmit FIFO has
    //! enough space (as indicated by its FIFO level interrupt signal), the DMA
    //! will transfer data from global variable sData into the FIFO. This will be
    //! transmitted to the receive FIFO via the internal loopback.
    //!
    //! When enough data has been placed in the receive FIFO (as indicated by its
    //! FIFO level interrupt signal), the DMA will transfer the data from the FIFO
    //! into global variable rData.
    //!
    //! When all data has been placed into rData, a check of the validity of the
    //! data will be performed in one of the DMA channels' ISRs.
    //!
    //! \b External \b Connections \n
    //!  - None
    //!
    //! \b Watch \b Variables \n
    //!  - \b sData - Data to send
    //!  - \b rData - Received data
    //!
    //
    //#############################################################################
    // $TI Release: F28002x Support Library v3.04.00.00 $
    // $Release Date: Fri Feb 12 18:58:34 IST 2021 $
    // $Copyright:
    // Copyright (C) 2021 Texas Instruments Incorporated - http://www.ti.com/
    //
    // Redistribution and use in source and binary forms, with or without 
    // modification, are permitted provided that the following conditions 
    // are met:
    // 
    //   Redistributions of source code must retain the above copyright 
    //   notice, this list of conditions and the following disclaimer.
    // 
    //   Redistributions in binary form must reproduce the above copyright
    //   notice, this list of conditions and the following disclaimer in the 
    //   documentation and/or other materials provided with the   
    //   distribution.
    // 
    //   Neither the name of Texas Instruments Incorporated nor the names of
    //   its contributors may be used to endorse or promote products derived
    //   from this software without specific prior written permission.
    // 
    // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
    // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
    // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
    // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
    // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
    // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
    // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
    // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    // $
    //###########################################################################
    
    //
    // Included Files
    //
    #include "driverlib.h"
    #include "device.h"
    
    //
    // Defines
    //
    #define FIFO_LVL    8               // FIFO interrupt level
    #define BURST       FIFO_LVL        // Each burst will empty the FIFO
    #define TRANSFER    4              // It will take 4 bursts of 8 to transfer
                                        // all data in rData
    
    //
    // Globals
    //
    uint16_t sData[32];                // Send data buffer
    uint16_t rData[32];                // Receive data buffer
    uint16_t ascii[10]={0};
    const uint16_t DMA_char[6]={'\r','\n','D','M','A',':'};
    
    // Place buffers in GSRAM
    #pragma DATA_SECTION(sData, "ramgs0");
    #pragma DATA_SECTION(rData, "ramgs0");
    
    volatile uint16_t done = 0;         // Flag to set when all data transfered
    volatile uint16_t count=0;
    
    //
    // Function Prototypes
    void configGPIOs(void);
    void initDMA(void);
    void initSPIFIFO(void);
    void initSCI(void);
    int int_to_char(int);
    __interrupt void dmaCh5ISR(void);
    __interrupt void dmaCh6ISR(void);
    
    //
    // Main
    //
    void main(void)
    {
        uint16_t i;
    
        //
        // Initialize device clock and peripherals
        //
        Device_init();
    
        //
        // Disable pin locks and enable internal pullups.
        //
        Device_initGPIO();
    
        //
        // Initialize PIE and clear PIE registers. Disables CPU interrupts.
        //
        Interrupt_initModule();
    
        //
        // Initialize the PIE vector table with pointers to the shell Interrupt
        // Service Routines (ISR).
        //
        Interrupt_initVectorTable();
    
        //
        // Interrupts that are used in this example are re-mapped to ISR functions
        // found within this file.
        //
        Interrupt_register(INT_DMA_CH5, &dmaCh5ISR);
        Interrupt_register(INT_DMA_CH6, &dmaCh6ISR);
    
        //Configuring pins
        configGPIOs();
        //
        // Set up DMA for SPI use, initialize the SPI for FIFO mode
        //
        initDMA();
        initSPIFIFO();
        // Setup SCI for debugging purpose
        initSCI();
        //
        // Initialize the data buffers
        //
        for(i = 0; i < 32; i++)
        {
            sData[i] = 256+i;
            rData[i]= 0;
        }
    
        //
        // Enable interrupts required for this example
        //
        Interrupt_enable(INT_DMA_CH5);
        Interrupt_enable(INT_DMA_CH6);
    
        //
        // Enable Global Interrupt (INTM) and realtime interrupt (DBGM)
        //
        EINT;
        ERTM;
        GPIO_writePin(DEVICE_GPIO_PIN_LED1,0);
        GPIO_writePin(DEVICE_GPIO_PIN_LED2,0);
        //
        // Start the DMA channels
        //
        DMA_startChannel(DMA_CH6_BASE);
        DMA_startChannel(DMA_CH5_BASE);
    
        //
        // Wait until the DMA transfer is complete
        //
        while(1)
        {
            GPIO_togglePin(DEVICE_GPIO_PIN_LED1);
            DEVICE_DELAY_US(1000000);
            SCI_writeCharArray(SCIA_BASE,DMA_char,6);
            for(i=0;i<32;i++)
            {
            count=int_to_char(rData[i]);
            SCI_writeCharArray(SCIA_BASE,ascii,count);
            SCI_writeCharBlockingFIFO(SCIA_BASE, '\t');
            }
            SCI_writeCharBlockingFIFO(SCIA_BASE, '\r');
            SCI_writeCharBlockingFIFO(SCIA_BASE, '\n');
        }
    
    
    }
    
    //
    // Function to configure SPI A in FIFO mode.
    //
    void initSPIFIFO()
    {
        //
        // Must put SPI into reset before configuring it
        //
        SPI_disableModule(SPIB_BASE);
    
        //
        // FIFO configuration
        //
        SPI_enableFIFO(SPIB_BASE);
        SPI_clearInterruptStatus(SPIB_BASE, SPI_INT_RXFF | SPI_INT_TXFF);
        SPI_setFIFOInterruptLevel(SPIB_BASE, (SPI_TxFIFOLevel)FIFO_LVL,
                                 (SPI_RxFIFOLevel)FIFO_LVL);
    
    
        //
        // SPI configuration. Use a 500kHz SPICLK and 16-bit word size.
        //
        SPI_setConfig(SPIB_BASE, DEVICE_LSPCLK_FREQ, SPI_PROT_POL0PHA0,
                      SPI_MODE_SLAVE, 1000000, 16);
        SPI_disableLoopback(SPIB_BASE);
        SPI_enableModule(SPIB_BASE);
    }
    
    //
    // DMA setup for both TX and RX channels.
    //
    void initDMA()
    {
        //
        // Initialize DMA
        //
        DMA_initController();
    
        //
        // Configure DMA Ch5 for TX. When there is enough space in the FIFO, data
        // will be transferred from the sData buffer to the SPI module's transmit
        // buffer register.
        //
        DMA_configAddresses(DMA_CH5_BASE, (uint16_t *)(SPIB_BASE + SPI_O_TXBUF),
                            sData);
        DMA_configBurst(DMA_CH5_BASE, BURST, 1, 0);
        DMA_configTransfer(DMA_CH5_BASE, TRANSFER, 1, 0);
        DMA_configMode(DMA_CH5_BASE, DMA_TRIGGER_SPIBTX, DMA_CFG_ONESHOT_DISABLE |
                       DMA_CFG_CONTINUOUS_ENABLE | DMA_CFG_SIZE_16BIT);
    
        //
        // Configure DMA Ch5 interrupts
        //
        DMA_setInterruptMode(DMA_CH5_BASE, DMA_INT_AT_BEGINNING);
        DMA_enableInterrupt(DMA_CH5_BASE);
        DMA_enableTrigger(DMA_CH5_BASE);
    
        //
        // Configure DMA Ch6 for RX. When the FIFO contains at least 8 words to
        // read, data will be transferred from the SPI module's receive buffer
        // register to the rData buffer.
        //
        DMA_configAddresses(DMA_CH6_BASE, rData,
                            (uint16_t *)(SPIB_BASE + SPI_O_RXBUF));
        DMA_configBurst(DMA_CH6_BASE, BURST, 0, 1);
        DMA_configTransfer(DMA_CH6_BASE, TRANSFER, 0, 1);
        DMA_configMode(DMA_CH6_BASE, DMA_TRIGGER_SPIBRX, DMA_CFG_ONESHOT_DISABLE |
                       DMA_CFG_CONTINUOUS_ENABLE | DMA_CFG_SIZE_16BIT);
    
        //
        // Configure DMA Ch6 interrupts
        //
        DMA_setInterruptMode(DMA_CH6_BASE, DMA_INT_AT_END);
        DMA_enableInterrupt(DMA_CH6_BASE);
        DMA_enableTrigger(DMA_CH6_BASE);
    }
    
    
    void initSCI(){
    
        //mySCI0 initialization
        SCI_clearInterruptStatus(SCIA_BASE, SCI_INT_RXFF | SCI_INT_TXFF | SCI_INT_FE | SCI_INT_OE | SCI_INT_PE | SCI_INT_RXERR | SCI_INT_RXRDY_BRKDT | SCI_INT_TXRDY);
        SCI_clearOverflowStatus(SCIA_BASE);
    
        SCI_resetTxFIFO(SCIA_BASE);
        SCI_resetRxFIFO(SCIA_BASE);
        SCI_resetChannels(SCIA_BASE);
    
        SCI_setConfig(SCIA_BASE, DEVICE_LSPCLK_FREQ, 115200, (SCI_CONFIG_WLEN_8|SCI_CONFIG_STOP_ONE|SCI_CONFIG_PAR_NONE));
        SCI_disableLoopback(SCIA_BASE);
        SCI_performSoftwareReset(SCIA_BASE);
        SCI_setFIFOInterruptLevel(SCIA_BASE, SCI_FIFO_TX0, SCI_FIFO_RX0);
        SCI_enableFIFO(SCIA_BASE);
        SCI_enableModule(SCIA_BASE);
    }
    
    //
    // DMA Channel 5 ISR
    //
    __interrupt void dmaCh5ISR(void)
    {
        DMA_stopChannel(DMA_CH5_BASE);
        Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP7);
        return;
    }
    
    //
    // DMA Channel 6 ISR
    //
     __interrupt void dmaCh6ISR(void)
    {
        uint16_t i;
    
        DMA_stopChannel(DMA_CH6_BASE);
        Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP7);
    
        //
        // Check for data integrity
        //
       //GPIO_writePin(DEVICE_GPIO_PIN_LED1,1);
        for(i = 0; i < 32; i++)
        {
            if (rData[i] != i)
            {
                // Something went wrong. rData doesn't contain expected data.
                GPIO_writePin(DEVICE_GPIO_PIN_LED2,1);//turn off green LED
            }
        }
        //Again triggering DMA transfer
        DMA_startChannel(DMA_CH6_BASE);
        DMA_startChannel(DMA_CH5_BASE);
        done = 1;
        return;
    }
    
     //
     // Configure GPIOs for external loopback.
     //
     void configGPIOs(void)
     {
         //
         // This test is designed for an external loopback between SPIA
         // and SPIB.
         // External Connections:
         // -GPIO40 and GPIO8  - SPISIMO
         // -GPIO41 and GPIO10 - SPISOMI
         // -GPIO22 and GPIO9  - SPICLK
         // -GPIO23 and GPIO11 - SPISTE
         // -GPIO31 is LED4
         // -GPIO34 is LED5
    
         GPIO_setDirectionMode(DEVICE_GPIO_PIN_LED1,GPIO_DIR_MODE_OUT);//setting LED1 pin as output
         GPIO_setDirectionMode(DEVICE_GPIO_PIN_LED2,GPIO_DIR_MODE_OUT);//setting LED2 pin as output
         //
         // GPIO10 is the SPISOMIA.
         //
         /*GPIO_setPinConfig(GPIO_10_SPIB_SOMI);
         GPIO_setPadConfig(10, GPIO_PIN_TYPE_PULLUP);
         GPIO_setQualificationMode(10, GPIO_QUAL_ASYNC);
    
         //
         // GPIO11 is the SPISIMO.
         //
         GPIO_setPinConfig(GPIO_11_SPIA_SIMO);
         GPIO_setPadConfig(11, GPIO_PIN_TYPE_PULLUP);
         GPIO_setQualificationMode(11, GPIO_QUAL_ASYNC);
    
         //
         // GPIO09 is the SPICLKA.
         //
         GPIO_setPinConfig(GPIO_9_SPIA_CLK);
         GPIO_setPadConfig(9, GPIO_PIN_TYPE_PULLUP);
         GPIO_setQualificationMode(9, GPIO_QUAL_ASYNC);
    
         //
         // GPIO5 is the SPISTEA.
         //
         GPIO_setPinConfig(GPIO_5_SPIA_STE);
         GPIO_setPadConfig(5, GPIO_PIN_TYPE_PULLUP);
         GPIO_setQualificationMode(5, GPIO_QUAL_ASYNC);*/
         //
             // GPIO40 is the SPISIMOB clock pin.
             //
             GPIO_setPinConfig(GPIO_40_SPIB_SIMO);
             GPIO_setPadConfig(40, GPIO_PIN_TYPE_PULLUP);
             GPIO_setQualificationMode(40, GPIO_QUAL_ASYNC);
    
             //
             // GPIO41 is the SPISOMIB.
             //
             GPIO_setPinConfig(GPIO_41_SPIB_SOMI);
             GPIO_setPadConfig(41, GPIO_PIN_TYPE_PULLUP);
             GPIO_setQualificationMode(41, GPIO_QUAL_ASYNC);
    
             //
             // GPIO22 is the SPICLKB.
             //
             GPIO_setPinConfig(GPIO_22_SPIB_CLK);
             GPIO_setPadConfig(22, GPIO_PIN_TYPE_PULLUP);
             GPIO_setQualificationMode(22, GPIO_QUAL_ASYNC);
    
             //
             // GPIO5 is the SPISTEA.
             //
             GPIO_setPinConfig(GPIO_23_SPIB_STE);
             GPIO_setPadConfig(5, GPIO_PIN_TYPE_PULLUP);
             GPIO_setQualificationMode(5, GPIO_QUAL_ASYNC);
    
    
    
    
         //SCIA -> mySCI0 Pinmux
         GPIO_setPinConfig(GPIO_28_SCIA_RX);
         GPIO_setPinConfig(GPIO_29_SCIA_TX);
    
     }
     int16_t int_to_char(int integer)
     {
         int temp,count=0,i,cnd=0;
         if (integer==0)//special case for 0
             {
                 ascii[0]='0';
                 return 1;
             }
         if(integer>>15)
          {
          /*CONVERTING 2's complement value to normal value*/
          integer=~integer+1;
          for(temp=integer;temp!=0;temp/=10,count++);
          ascii[0]=0x2D;
          count++;
          cnd=1;
          }
          else
          for(temp=integer;temp!=0;temp/=10,count++);
          for(i=count-1,temp=integer;i>=cnd;i--)
          {
    
             ascii[i]=(temp%10)+0x30;
             temp/=10;
          }
          return count;
     }
    
    
    
    我还在为 SPIA 附加代码、该代码在没有任何通信错误的情况下工作。
    //#############################################################################
    //
    // FILE:   spi_ex4_loopback_dma.c
    //
    // TITLE:  SPI Digital Loopback with DMA
    //
    //! \addtogroup driver_example_list
    //! <h1>SPI Digital Loopback with DMA</h1>
    //!
    //! This program uses the internal loopback test mode of the SPI module. Both
    //! DMA interrupts and the SPI FIFOs are used. When the SPI transmit FIFO has
    //! enough space (as indicated by its FIFO level interrupt signal), the DMA
    //! will transfer data from global variable sData into the FIFO. This will be
    //! transmitted to the receive FIFO via the internal loopback.
    //!
    //! When enough data has been placed in the receive FIFO (as indicated by its
    //! FIFO level interrupt signal), the DMA will transfer the data from the FIFO
    //! into global variable rData.
    //!
    //! When all data has been placed into rData, a check of the validity of the
    //! data will be performed in one of the DMA channels' ISRs.
    //!
    //! \b External \b Connections \n
    //!  - None
    //!
    //! \b Watch \b Variables \n
    //!  - \b sData - Data to send
    //!  - \b rData - Received data
    //!
    //
    //#############################################################################
    // $TI Release: F28002x Support Library v3.04.00.00 $
    // $Release Date: Fri Feb 12 18:58:34 IST 2021 $
    // $Copyright:
    // Copyright (C) 2021 Texas Instruments Incorporated - http://www.ti.com/
    //
    // Redistribution and use in source and binary forms, with or without 
    // modification, are permitted provided that the following conditions 
    // are met:
    // 
    //   Redistributions of source code must retain the above copyright 
    //   notice, this list of conditions and the following disclaimer.
    // 
    //   Redistributions in binary form must reproduce the above copyright
    //   notice, this list of conditions and the following disclaimer in the 
    //   documentation and/or other materials provided with the   
    //   distribution.
    // 
    //   Neither the name of Texas Instruments Incorporated nor the names of
    //   its contributors may be used to endorse or promote products derived
    //   from this software without specific prior written permission.
    // 
    // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
    // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
    // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
    // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
    // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
    // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
    // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
    // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    // $
    //###########################################################################
    
    //
    // Included Files
    //
    #include "driverlib.h"
    #include "device.h"
    
    //
    // Defines
    //
    #define FIFO_LVL    8               // FIFO interrupt level
    #define BURST       FIFO_LVL        // Each burst will empty the FIFO
    #define TRANSFER    4              // It will take 4 bursts of 8 to transfer
                                        // all data in rData
    
    //
    // Globals
    //
    uint16_t sData[32];                // Send data buffer
    uint16_t rData[32];                // Receive data buffer
    uint16_t ascii[10]={0};
    const uint16_t DMA_char[6]={'\r','\n','D','M','A',':'};
    
    // Place buffers in GSRAM
    #pragma DATA_SECTION(sData, "ramgs0");
    #pragma DATA_SECTION(rData, "ramgs0");
    
    volatile uint16_t done = 0;         // Flag to set when all data transfered
    volatile uint16_t count=0;
    
    //
    // Function Prototypes
    void configGPIOs(void);
    void initDMA(void);
    void initSPIFIFO(void);
    void initSCI(void);
    int int_to_char(int);
    __interrupt void dmaCh5ISR(void);
    __interrupt void dmaCh6ISR(void);
    
    //
    // Main
    //
    void main(void)
    {
        uint16_t i;
    
        //
        // Initialize device clock and peripherals
        //
        Device_init();
    
        //
        // Disable pin locks and enable internal pullups.
        //
        Device_initGPIO();
    
        //
        // Initialize PIE and clear PIE registers. Disables CPU interrupts.
        //
        Interrupt_initModule();
    
        //
        // Initialize the PIE vector table with pointers to the shell Interrupt
        // Service Routines (ISR).
        //
        Interrupt_initVectorTable();
    
        //
        // Interrupts that are used in this example are re-mapped to ISR functions
        // found within this file.
        //
        Interrupt_register(INT_DMA_CH5, &dmaCh5ISR);
        Interrupt_register(INT_DMA_CH6, &dmaCh6ISR);
    
        //Configuring pins
        configGPIOs();
        //
        // Set up DMA for SPI use, initialize the SPI for FIFO mode
        //
        initDMA();
        initSPIFIFO();
        // Setup SCI for debugging purpose
        initSCI();
        //
        // Initialize the data buffers
        //
        for(i = 0; i < 32; i++)
        {
            sData[i] = 256+i;
            rData[i]= 0;
        }
    
        //
        // Enable interrupts required for this example
        //
        Interrupt_enable(INT_DMA_CH5);
        Interrupt_enable(INT_DMA_CH6);
    
        //
        // Enable Global Interrupt (INTM) and realtime interrupt (DBGM)
        //
        EINT;
        ERTM;
        GPIO_writePin(DEVICE_GPIO_PIN_LED1,0);
        GPIO_writePin(DEVICE_GPIO_PIN_LED2,0);
        //
        // Start the DMA channels
        //
        DMA_startChannel(DMA_CH6_BASE);
        DMA_startChannel(DMA_CH5_BASE);
    
        //
        // Wait until the DMA transfer is complete
        //
        while(1)
        {
            GPIO_togglePin(DEVICE_GPIO_PIN_LED1);
            DEVICE_DELAY_US(1000000);
            SCI_writeCharArray(SCIA_BASE,DMA_char,6);
            for(i=0;i<32;i++)
            {
            count=int_to_char(rData[i]);
            SCI_writeCharArray(SCIA_BASE,ascii,count);
            SCI_writeCharBlockingFIFO(SCIA_BASE, '\t');
            }
            SCI_writeCharBlockingFIFO(SCIA_BASE, '\r');
            SCI_writeCharBlockingFIFO(SCIA_BASE, '\n');
        }
    
    
    }
    
    //
    // Function to configure SPI A in FIFO mode.
    //
    void initSPIFIFO()
    {
        //
        // Must put SPI into reset before configuring it
        //
        SPI_disableModule(SPIA_BASE);
    
        //
        // FIFO configuration
        //
        SPI_enableFIFO(SPIA_BASE);
        SPI_clearInterruptStatus(SPIA_BASE, SPI_INT_RXFF | SPI_INT_TXFF);
        SPI_setFIFOInterruptLevel(SPIA_BASE, (SPI_TxFIFOLevel)FIFO_LVL,
                                 (SPI_RxFIFOLevel)FIFO_LVL);
    
    
        //
        // SPI configuration. Use a 500kHz SPICLK and 16-bit word size.
        //
        SPI_setConfig(SPIA_BASE, DEVICE_LSPCLK_FREQ, SPI_PROT_POL0PHA0,
                      SPI_MODE_SLAVE, 1000000, 16);
        SPI_disableLoopback(SPIA_BASE);
        SPI_enableModule(SPIA_BASE);
    }
    
    //
    // DMA setup for both TX and RX channels.
    //
    void initDMA()
    {
        //
        // Initialize DMA
        //
        DMA_initController();
    
        //
        // Configure DMA Ch5 for TX. When there is enough space in the FIFO, data
        // will be transferred from the sData buffer to the SPI module's transmit
        // buffer register.
        //
        DMA_configAddresses(DMA_CH5_BASE, (uint16_t *)(SPIA_BASE + SPI_O_TXBUF),
                            sData);
        DMA_configBurst(DMA_CH5_BASE, BURST, 1, 0);
        DMA_configTransfer(DMA_CH5_BASE, TRANSFER, 1, 0);
        DMA_configMode(DMA_CH5_BASE, DMA_TRIGGER_SPIATX, DMA_CFG_ONESHOT_DISABLE |
                       DMA_CFG_CONTINUOUS_ENABLE | DMA_CFG_SIZE_16BIT);
    
        //
        // Configure DMA Ch5 interrupts
        //
        DMA_setInterruptMode(DMA_CH5_BASE, DMA_INT_AT_BEGINNING);
        DMA_enableInterrupt(DMA_CH5_BASE);
        DMA_enableTrigger(DMA_CH5_BASE);
    
        //
        // Configure DMA Ch6 for RX. When the FIFO contains at least 8 words to
        // read, data will be transferred from the SPI module's receive buffer
        // register to the rData buffer.
        //
        DMA_configAddresses(DMA_CH6_BASE, rData,
                            (uint16_t *)(SPIA_BASE + SPI_O_RXBUF));
        DMA_configBurst(DMA_CH6_BASE, BURST, 0, 1);
        DMA_configTransfer(DMA_CH6_BASE, TRANSFER, 0, 1);
        DMA_configMode(DMA_CH6_BASE, DMA_TRIGGER_SPIARX, DMA_CFG_ONESHOT_DISABLE |
                       DMA_CFG_CONTINUOUS_ENABLE | DMA_CFG_SIZE_16BIT);
    
        //
        // Configure DMA Ch6 interrupts
        //
        DMA_setInterruptMode(DMA_CH6_BASE, DMA_INT_AT_END);
        DMA_enableInterrupt(DMA_CH6_BASE);
        DMA_enableTrigger(DMA_CH6_BASE);
    }
    
    
    void initSCI(){
    
        //mySCI0 initialization
        SCI_clearInterruptStatus(SCIA_BASE, SCI_INT_RXFF | SCI_INT_TXFF | SCI_INT_FE | SCI_INT_OE | SCI_INT_PE | SCI_INT_RXERR | SCI_INT_RXRDY_BRKDT | SCI_INT_TXRDY);
        SCI_clearOverflowStatus(SCIA_BASE);
    
        SCI_resetTxFIFO(SCIA_BASE);
        SCI_resetRxFIFO(SCIA_BASE);
        SCI_resetChannels(SCIA_BASE);
    
        SCI_setConfig(SCIA_BASE, DEVICE_LSPCLK_FREQ, 115200, (SCI_CONFIG_WLEN_8|SCI_CONFIG_STOP_ONE|SCI_CONFIG_PAR_NONE));
        SCI_disableLoopback(SCIA_BASE);
        SCI_performSoftwareReset(SCIA_BASE);
        SCI_setFIFOInterruptLevel(SCIA_BASE, SCI_FIFO_TX0, SCI_FIFO_RX0);
        SCI_enableFIFO(SCIA_BASE);
        SCI_enableModule(SCIA_BASE);
    }
    
    //
    // DMA Channel 5 ISR
    //
    __interrupt void dmaCh5ISR(void)
    {
        DMA_stopChannel(DMA_CH5_BASE);
        Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP7);
        return;
    }
    
    //
    // DMA Channel 6 ISR
    //
     __interrupt void dmaCh6ISR(void)
    {
        uint16_t i;
    
        DMA_stopChannel(DMA_CH6_BASE);
        Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP7);
    
        //
        // Check for data integrity
        //
       //GPIO_writePin(DEVICE_GPIO_PIN_LED1,1);
        for(i = 0; i < 32; i++)
        {
            if (rData[i] != i)
            {
                // Something went wrong. rData doesn't contain expected data.
                GPIO_writePin(DEVICE_GPIO_PIN_LED2,1);//turn off green LED
            }
        }
        //Again triggering DMA transfer
        DMA_startChannel(DMA_CH6_BASE);
        DMA_startChannel(DMA_CH5_BASE);
        done = 1;
        return;
    }
    
     //
     // Configure GPIOs for external loopback.
     //
     void configGPIOs(void)
     {
         //
         // This test is designed for an external loopback between SPIA
         // and SPIB.
         // External Connections:
         // -GPIO40 and GPIO8  - SPISIMO
         // -GPIO41 and GPIO10 - SPISOMI
         // -GPIO22 and GPIO9  - SPICLK
         // -GPIO23 and GPIO11 - SPISTE
         // -GPIO31 is LED4
         // -GPIO34 is LED5
    
         GPIO_setDirectionMode(DEVICE_GPIO_PIN_LED1,GPIO_DIR_MODE_OUT);//setting LED1 pin as output
         GPIO_setDirectionMode(DEVICE_GPIO_PIN_LED2,GPIO_DIR_MODE_OUT);//setting LED2 pin as output
         //
         // GPIO10 is the SPISOMIA.
         //
         GPIO_setPinConfig(GPIO_10_SPIA_SOMI);
         GPIO_setPadConfig(10, GPIO_PIN_TYPE_PULLUP);
         GPIO_setQualificationMode(10, GPIO_QUAL_ASYNC);
    
         //
         // GPIO11 is the SPISIMO.
         //
         GPIO_setPinConfig(GPIO_11_SPIA_SIMO);
         GPIO_setPadConfig(11, GPIO_PIN_TYPE_PULLUP);
         GPIO_setQualificationMode(11, GPIO_QUAL_ASYNC);
    
         //
         // GPIO09 is the SPICLKA.
         //
         GPIO_setPinConfig(GPIO_9_SPIA_CLK);
         GPIO_setPadConfig(9, GPIO_PIN_TYPE_PULLUP);
         GPIO_setQualificationMode(9, GPIO_QUAL_ASYNC);
    
         //
         // GPIO5 is the SPISTEA.
         //
         GPIO_setPinConfig(GPIO_5_SPIA_STE);
         GPIO_setPadConfig(5, GPIO_PIN_TYPE_PULLUP);
         GPIO_setQualificationMode(5, GPIO_QUAL_ASYNC);
         //SCIA -> mySCI0 Pinmux
         GPIO_setPinConfig(GPIO_28_SCIA_RX);
         GPIO_setPinConfig(GPIO_29_SCIA_TX);
    
     }
     int16_t int_to_char(int integer)
     {
         int temp,count=0,i,cnd=0;
         if (integer==0)//special case for 0
             {
                 ascii[0]='0';
                 return 1;
             }
         if(integer>>15)
          {
          /*CONVERTING 2's complement value to normal value*/
          integer=~integer+1;
          for(temp=integer;temp!=0;temp/=10,count++);
          ascii[0]=0x2D;
          count++;
          cnd=1;
          }
          else
          for(temp=integer;temp!=0;temp/=10,count++);
          for(i=count-1,temp=integer;i>=cnd;i--)
          {
    
             ascii[i]=(temp%10)+0x30;
             temp/=10;
          }
          return count;
     }
    
    
    

    期待收到您的来信。
  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    只需添加 Arduino 代码的小修正即可。 SPI 时钟分频器被设定为84、这样它的时钟运行在与针对 TMS320F280025C 配置的频率一样的1MHz 上。 我稍后使用较慢的时钟速率进行测试、以检查是否有任何改进。 我没有发现时钟速率降低的任何改进。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您是否已经尝试使用逻辑分析仪探测 SPI 总线以检查总线活动? 您能否共享 SPI 逻辑分析仪快照。是否尝试仅进行一次传输、并查看您是否看到相同的问题。

    我处于一个重要项目的中间。 我只能在下周对这一问题进行更深入的研究

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 Manoj:

       我尝试通过逻辑分析仪进行探测、并验证了数据完整性。 我将再次进行设置、以便为您进行采集。 在传输端、我几乎不怀疑、因为同一控制器上的 SPIA 能够正确接收所有数据。 但是、我将按照您的建议尝试单次传输。 一旦您从正在进行的项目中解放出来、我会要求您尽早查看所提供的代码。 我们已经将 PCB 送去生产、我担心我们是否需要通过将 SPIB 替换为 SPIA 来保持和进行修订。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    阿萨德

    我简要地研究了您的代码、无法找出引起担忧的任何问题。 我需要尝试运行您的代码并检查我是否看到相同的行为。

    此致、

    曼诺伊

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 Manoj:

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 Manoj

       我在周末使用逻辑分析仪进行了详细的测试。 我使用了另一个 TMS320F280025C launchpad 作为 Arduino 的主站。 我有一个发现我想分享。 我一直将主设备作为从设备连接到笔记本电脑的 USB 端口。 我注意到、当我的笔记本电脑连接电源充电器时、SPI 从设备以及逻辑分析仪会收到大量错误传输。 但是、当我断开电源充电器时、逻辑分析仪会正确地检测所有数据。 接下来、我在从侧控制器上测试了 SPIA 和 SPIB。 此测试是在外部电源充电器断开的情况下完成的。 SPIA 正确接收所有数据。 SPIB 具有一些杂散读数。 请在下面找到 SPIB 的一些读数:

    SPIB:0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

    SPIB:0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

    SPIB:0 1 2 3 4 5 4102 15 8 9 10 11 12 13 14 79 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

    SPIB:0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

    SPIB:0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

    SPIB:0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

    SPIB:0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

    SPIB:0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

    SPIB:0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

    SPIB:0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

    SPIB:0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

    SPIB:0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 16399 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

    SPIB:0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

    SPIB:0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

    SPIB:0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

    外部电源充电器断开后、错误值的频率会大幅降低。 我是从噪声的角度来看待它的。 请在您的末尾在 TMS320F280025C Launchpad 上进行测试、以查看您是否发现 SPIA 和 SPIB 接收之间存在任何差异。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    阿萨德

    根据您的说明、SPI 信号似乎会受到您设置中的 EMI 噪声的影响(电源充电器)。 使用电源充电器时、您是否观察到 SPIA/SPIB 上的数据不正确? 此外、当主板和从板都连接时? 是否确保连接主从设置的 GND 引脚?

    由于我们要处理 EMI 噪声、因此最好使用示波器而不是逻辑分析仪。 请分享您的分析仪快照、示波器快照和设置照片。 我将开始研究您的代码。

    此致、

    曼诺伊

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 Manoj:  

    我们正在下班,将于星期五恢复工作。 然后、我将尝试捕获示波器结果并与您一起测试设置。 我们观察到、SPIA 不太容易受到噪声的影响。 它在所有情况下都能正确获得超过95%的数据。 然而、SPIB 看起来更加敏感、并且在噪声情况下会出现高百分比误差。 在我们的设计中、我们已将 SPIB 替换为 SPIA、以减少生产中出现不良通信的可能性。 非常感谢您的持续支持。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    阿萨德

    我们想了解这个问题、看看我们是否有真正的问题。 这可能是电路板问题、设置问题(或)远程设备问题。 请务必分享您的示波器快照和测试设置照片、以帮助我们找到此问题的最底部。

    到目前为止、SPIA/SPIB 没有已知问题。

    此致、

    曼诺伊

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    有更新吗? 您是否有机会获得示波器快照。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 Manoj:

       很抱歉耽误你的回答。 我感染了 CoVid、有3周不在办公室。 我们还没有任何定论。 这可能是由于我们的跳线或外部噪声造成的。 我需要一些时间才能返回到 SPI 任务。 我们可以关闭此 TT。 如果有任何新发现、我将与您分享。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    很遗憾听到这个消息。 希望您能够恢复速度。

    我现在将关闭此机票。