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.

[参考译文] TMS320F28P650DK:SPI 外部环回示例:从器件如何发送响应?

Guru**** 2541500 points


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

https://e2e.ti.com/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/1409518/tms320f28p650dk-spi-external-loopback-example-how-does-slave-send-response

器件型号:TMS320F28P650DK

工具与软件:

您好!
我目前正在尝试 spi_ex4_external_loopback_fifo_interrupt.c、想知道如何使用从器件在主器件请求后发送响应。
在附加的图像中、从器件(蓝色)与主器件同时发送。




主器件完成后(即仍在相同的芯片选择状态)从器件如何发送?

我会非常感谢任何帮助:)

(我已将示例代码精简为最重要的内容)

//#############################################################################
//
// FILE:   spi_ex4_external_loopback_fifo_interrupt.c
//
// TITLE:  SPI Digital Loopback with FIFO Interrupts
//
//! \addtogroup driver_example_list
//! <h1>SPI Digital External Loopback with FIFO Interrupts</h1>
//!
//! This program uses the external loopback between two SPI modules. Both
//! the SPI FIFOs and their interrupts are used. SPIA is configured as a peripheral
//! and receives data from SPI B which is configured as a controller.
//!
//! A stream of data is sent and then compared to the received stream.
//! The sent data looks like this: \n
//!  0000 0001 \n
//!  0001 0002 \n
//!  0002 0003 \n
//!  .... \n
//!  FFFE FFFF \n
//!  FFFF 0000 \n
//!  etc.. \n
//! This pattern is repeated forever.
//!
//!  \note This example project has support for migration across our C2000 
//!  device families. If you are wanting to build this project from launchpad
//!  or controlCARD, please specify in the .syscfg file the board you're using.
//!  At any time you can select another device to migrate this example.
//!
//! \b External \b Connections \n
//! Refer to SysConfig for external connections (GPIO pin numbers) specific to each device
//!
//! \b Watch \b Variables \n
//!  - \b sData - Data to send
//!  - \b rData - Received data
//!  - \b rDataPoint - Used to keep track of the last position in the receive
//!    stream for error checking
//!
//
//#############################################################################
// 
// C2000Ware v5.03.00.00
//
// Copyright (C) 2024 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"
#include "board.h"

//
// Globals
//
volatile uint16_t receiveData;

//
// Function Prototypes
//
__interrupt void spibTxFIFOISR(void);
__interrupt void spiaRxFIFOISR(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();

    //
    // Board initialization
    //
    Board_init();

    //
    // Enable Global Interrupt (INTM) and realtime interrupt (DBGM)
    //
    EINT;
    ERTM;

    //
    // Loop forever. Suspend or place breakpoints to observe the buffers.
    //
    while (1)
    {
        ;
    }
}

//
// SPI B Transmit FIFO ISR
//
__interrupt void spibTxFIFOISR(void)
{
    uint16_t i = 0;

    //
    // Send data
    //

    while(i < 10000){
        i++;
    }
    SPI_writeDataNonBlocking(SPIB_BASE, 0b1010101010101010);

    //
    // Clear interrupt flag and issue ACK
    //
    SPI_clearInterruptStatus(SPIB_BASE, SPI_INT_TXFF);
    Interrupt_clearACKGroup(INT_SPIB_controller_TX_INTERRUPT_ACK_GROUP);
}

//
// SPI A Receive FIFO ISR
//
__interrupt void spiaRxFIFOISR(void)
{
    uint16_t i;

    //
    // Read data
    //

    receiveData = SPI_readDataNonBlocking(SPIA_BASE);

    while(i < 10000){
        i++;
    }
    SPI_writeDataNonBlocking(SPIA_BASE, 0b1111000011110000);

    //
    // Clear interrupt flag and issue ACK
    //
    SPI_clearInterruptStatus(SPIA_BASE, SPI_INT_RXFF);
    Interrupt_clearACKGroup(INT_SPIA_peripheral_RX_INTERRUPT_ACK_GROUP);
}

//
// Enabled only for SysConfig functionality
//
__interrupt void INT_SPIA_peripheral_TX_ISR(void)
{
    //
    // Issue ACK
    //
    Interrupt_clearACKGroup(INT_SPIA_peripheral_TX_INTERRUPT_ACK_GROUP);
}

//
// Enabled only for SysConfig functionality
//
__interrupt void INT_SPIB_controller_RX_ISR(void)
{
    //
    // Issue ACK
    //
    Interrupt_clearACKGroup(INT_SPIB_controller_RX_INTERRUPT_ACK_GROUP);

}

//
// End of file
//


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

    您好!

    SPI 是一种同步全双工通信、要求控制器和目标同时进行发送和接收。 为什么要引入延迟? 这实际上会对 SPI 协议产生负面影响、并导致错误的读取和写入。 您可以查看 SPI EEPROM 示例、了解如何在非外部环回中实现协议。  

    此致、

    Aishwarya.

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

    理解问题:主设备需要一段信息、将芯片选择拉至低电平并发送从设备知道的定义序列(例如、前3位作为 ID)。 然后、从器件发送该信息。 主器件何时收到该请求的信息? 选择中选择串行时?

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

    我希望它是这样的:

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

    您好!

    让我和其他人办理登机手续、并在2-3天内给您回复。

    此致、

    Aishwarya.

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

    您好!

    非常感谢

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

    您好!

    SPI 硬件同时发送/接收数据。 如果您想按照提供的屏幕截图所示执行操作、唯一的方法是通过软件。 具体来说、您可以让控制器读取外设虚拟数据、然后保存下一次传输的数据。 我们没有关于这方面的任何示例。

    此致、

    Aishwarya.

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

    您好!

    非常感谢您的努力。

    这意味着我必须使用位拆裂来执行它。  或者:这也许可以通过外部 SPI 硬件来完成吗? 您能建议什么吗?

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

    您好!

    除了上述建议、 我建议您查看可能已经讨论过类似内容的其他 E2E 主题。 希望这对您有所帮助。

    此致、

    Aishwarya.

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

    您好!
    好的, 非常感谢你的帮助:)

    祝你度过美好的一天