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.

[参考译文] TMS320F28379D:用于在 F28379D 上发送和接收的简单 SPI 代码

Guru**** 2526700 points


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

https://e2e.ti.com/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/1381276/tms320f28379d-simple-spi-code-for-sending-and-receiving-on-f28379d

器件型号:TMS320F28379D

工具与软件:

大家好!

我正在尝试使用带有上述微控制器的非 FIFO 来发送一个简单的16位数据流。 我用两个 F28379D、一个用作控制器、另一个用作 外设。

控制器代码如下:

//
// Included Files
//
#include "driverlib.h"
#include "device.h"
#include "board.h"
#include <stdint.h>
#include <stdio.h>

#define SPIFSI_CLK_SPEED 12500000U


void configureGPIOs(void) {

    // GPIO18 is the SPICLKA.
    //
    GPIO_setMasterCore(60, GPIO_CORE_CPU1);
    GPIO_setPinConfig(GPIO_60_SPICLKA);
    GPIO_setQualificationMode(60, GPIO_QUAL_ASYNC);

    //
    // GPIO16 is the SPISIMOA.
    //
    GPIO_setMasterCore(58, GPIO_CORE_CPU1);
    GPIO_setPinConfig(GPIO_58_SPISIMOA);
    GPIO_setQualificationMode(58, GPIO_QUAL_ASYNC);

}







//
// Main
//
void main(void)
{

    uint16_t sData = 0x0F0F;                  // Send data


    //
    // 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();

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




    SPI_disableModule(SPIA_BASE); // Disable SPI before configuring

    // For baud rate calculations, check pg. 2262 of the Technical Reference Manual
    SPI_setConfig(SPIA_BASE, DEVICE_LSPCLK_FREQ, SPI_PROT_POL0PHA0, SPI_MODE_CONTROLLER, SPIFSI_CLK_SPEED, 16);

    SPI_enableModule(SPIA_BASE); // Enable SPI on SPIA





    // Loop forever. Suspend or place breakpoints to observe the buffers.

    while(1) {


        // Transmit Data, blocks until buffer is empty
        SPI_writeDataBlockingNonFIFO(SPIA_BASE, sData);


    }
}

此代码运行良好(我相信)。 我看到它在示波器上发送数据。

但是、我很难使用代码在 F28379D 上接收用作外设的数据。  

外设代码如下所示:

#include "driverlib.h"
#include "device.h"
#include "board.h"
#include <stdint.h>
#include <stdio.h>

#define SPIFSI_CLK_SPEED 12500000U


void configureGPIOs(void) {

    // GPIO18 is SPICLK
    //
    GPIO_setMasterCore(18, GPIO_CORE_CPU1);
    GPIO_setPinConfig(GPIO_18_SPICLKA);
    GPIO_setQualificationMode(18, GPIO_QUAL_ASYNC);

    //
    // GPIO16 is SPISIMO
    //
    GPIO_setMasterCore(16, GPIO_CORE_CPU1);
    GPIO_setPinConfig(GPIO_16_SPISIMOA);
    GPIO_setQualificationMode(16, GPIO_QUAL_ASYNC);



    // GPIO19 is SPISTEA
    //
    GPIO_setMasterCore(19, GPIO_CORE_CPU1);
    GPIO_setPinConfig(GPIO_19_SPISTEA);
    GPIO_setQualificationMode(19, GPIO_QUAL_ASYNC);

}


//
// Main
//
void main(void)
{

    uint16_t rData = 0x0000;                  // Receive data


    //
    // 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();

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




    SPI_disableModule(SPIA_BASE); // Disable SPI before configuring

    // For baud rate calculations, check pg. 2262 of the Technical Reference Manual
    SPI_setConfig(SPIA_BASE, DEVICE_LSPCLK_FREQ, SPI_PROT_POL0PHA0, SPI_MODE_PERIPHERAL, SPIFSI_CLK_SPEED, 16);

    SPI_enableModule(SPIA_BASE); // Enable SPI on SPIA





    // Loop forever. Suspend or place breakpoints to observe the buffers.

    while(1) {


        // Receive Data, blocks until buffer is empty
        rData = SPI_readDataBlockingNonFIFO(SPIA_BASE);


    }
}

我无法看到收到任何数据。 我想知道你们中是否有人可以提供帮助。 非常感谢。 谢谢!

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

    Andrew、您好!

    从代码设置来看、我假设您计划在3线模式下使用 SPI。 在这种情况下、您需要:1)将控制器和外设配置为3线模式2)在外设侧配置 POCI (或 SOMI)引脚、而不是 PICO (SIMO)、因为这是3线外设模式下的有效引脚3)控制器侧代码似乎也缺少 SPISTE 引脚的 GPIO 设置

    如果不是3线模式、您需要配置两侧的所有标准引脚。 请告诉我、这是否可以解决您的问题。

    谢谢!

    Arnav