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:尝试通过 SPI (而不是标准的16位)发送32位数据。

Guru**** 2541470 points
Other Parts Discussed in Thread: SYSCONFIG

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

https://e2e.ti.com/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/1386541/tms320f28379d-trying-to-send-32-bit-data-over-spi-rather-than-the-standard-16-bits

器件型号:TMS320F28379D
主题中讨论的其他器件:SysConfigC2000WARE

工具与软件:

大家好!

我正在使用的 DAC 需要来自 SPI 的24至32位数据才能正常运行。 我一直在尝试通过使用 TI 提供的功能找到一种使用 F28379D 实现这一点的有效方法。

到目前为止、我的方法不起作用、我正在寻找建议。 我的代码如下:

// Microcontroller has high speed SPI mode, look into it
// SPIA MOSI on J2 - 15
// SPIACLK on J1 - 7


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

#define SPIFSI_CLK_SPEED 12500000U

uint16_t voltageToCode(float dac_voltage, float min_output, float max_output) {
// Calculate a LTC2666 DAC code given the desired output voltage and the minimum / maximum
// outputs for a given softspan range.

    uint16_t dac_code;
    float float_code;
    float_code = 65535.0 * (dac_voltage - min_output) / (max_output - min_output);                    // Calculate the DAC code
    float_code = (float_code > (floor(float_code) + 0.5)) ? ceil(float_code) : floor(float_code);     // Round
    if (float_code < 0.0) float_code = 0.0;
    if (float_code > 65535.0) float_code = 65535.0;
    dac_code = (uint16_t) (float_code);                                                               // Convert to unsigned integer
    return (dac_code);
}


//uint16_t output0 = voltageToCode(2.0, 0, 5.0);





void configureGPIOs(void) {

    GPIO_setMasterCore(60, GPIO_CORE_CPU1);
    GPIO_setPinConfig(GPIO_60_SPICLKA);
    GPIO_setQualificationMode(60, GPIO_QUAL_ASYNC);

    GPIO_setMasterCore(58, GPIO_CORE_CPU1);
    GPIO_setPinConfig(GPIO_58_SPISIMOA);
    GPIO_setQualificationMode(58, GPIO_QUAL_ASYNC);

    GPIO_setMasterCore(59, GPIO_CORE_CPU1);
    GPIO_setPinConfig(GPIO_59_SPISOMIA);
    GPIO_setQualificationMode(59, GPIO_QUAL_ASYNC);

    GPIO_setMasterCore(61, GPIO_CORE_CPU1);
    GPIO_setPinConfig(GPIO_61_SPISTEA);
    GPIO_setQualificationMode(61, GPIO_QUAL_ASYNC);

    GPIO_setMasterCore(66, GPIO_CORE_CPU1);
    GPIO_setPinConfig(GPIO_66_GPIO66);
    GPIO_setDirectionMode(66, GPIO_DIR_MODE_OUT);
}







//
// Main
//

void main(void)
{
    uint16_t sData0 = 0b0000000000110000;
    uint16_t sData1 = 0b1111111111111111;

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

    // Set 'CS' High
    GPIO_togglePin(66);


    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









    // Set 'CS' Low
    GPIO_togglePin(66);

    SPI_writeDataBlockingNonFIFO(SPIA_BASE, sData0); // First 16 bits
    SPI_writeDataBlockingNonFIFO(SPIA_BASE, sData1); // Second 16 bits

    // Toggle pin high
    GPIO_togglePin(66);




}

另一条注意事项。 GPIO66是我的临时 CS、因为 DAC 在 CS 引脚变为高电平后停止读取数据、并且 SPI_writeDataBlockingNonFIFO ()函数使用正常的 CS 引脚。 如果我要使用 SPI_writeDataBlockingNonFIFO () CS 引脚、DAC 将在传输过程中停止读取、因为我利用该函数两次发送32位。 对该怎么做有更好的想法吗?

谢谢!

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

    Andrew、您好!  

    为了使用 GPIO 对 CS 引脚进行仿真、应将外设的 SPISTE 引脚保持未配置状态。 我建议使用 SysConfig 执行此操作、以避免过程中出现任何错误。 您可以参考  SPI_ex6_EEPROM 以查看此设置的示例。

    此外、为了避免在翻转 CS 引脚时出现歧义、您可以使用  GPIO_writePin  显式指定写入值。 设置的其余部分看起来正常、 应该能够正常工作。

    谢谢!

    Arnav