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.

[参考译文] LAUNCHXL-F28379D:F28379D 和 Arduino 之间的 SPI 通信

Guru**** 2538950 points


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

https://e2e.ti.com/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/992753/launchxl-f28379d-spi-communication-between-f28379d-and-arduino

器件型号:LAUNCHXL-F28379D

尊敬的所有人:

你好

我尝试 在 F28379D 和 Arduino 之间进行 SPI 通信。

F28379D (从属)  Arduino (主控/SPI_Cock=1M Hz)  

我发现进入 INTERRUPT_ISR (f28379d)的次数超过 Arduino 发送的数据数。

我使用 interrupt_ISR 中的系统配置时钟和计数器来计算数字。

通过"暂停"按钮、我可以得到计数器的数量以及该时间内的时钟数量。

[ 计数器数量 / ( 时钟数量*9*10^(-9) ) =一秒内计数器数量]

我认为问题是我的螺旋状。


void main(void)
{

//
// Step 1. Initialize System Control:
//
   InitSysCtrl();

//
// Step 2. Initialize GPIO:
//
   SpicInitGpio();

//
// Step 3. Initialize PIE vector table:
// Disable and clear all CPU interrupts
//
   DINT;
   IER = 0x0000;
   IFR = 0x0000;

//
// Initialize PIE control registers to their default state:
//
   InitPieCtrl();

//
// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
//
   InitPieVectTable();

//
// Interrupts that are used in this example are re-mapped to
// ISR functions found within this file.
//
   EALLOW;  // This is needed to write to EALLOW protected registers
   PieVectTable.SPIC_RX_INT = &spicRxFIFOISR;
   EDIS;    // This is needed to disable write to EALLOW protected registers

//
// Step 4. Initialize the Device Peripherals:
//
   spi_fifo_init();   // Initialize the SPI only

//
// Step 5. User specific code, enable interrupts:
//

//
// Enable interrupts required for this example
//
   PieCtrlRegs.PIECTRL.bit.ENPIE = 1;     // Enable the PIE block
   PieCtrlRegs.PIEIER6.bit.INTx9 = 1;     // Enable PIE Group 6, INT 9
   IER=0x20;                              // Enable CPU INT6
   EINT;                                  // Enable Global Interrupts

//
// Step 6. IDLE loop. Just sit and loop forever (optional):
//
    for(;;);
}


//
// spi_fifo_init - Initialize SPI FIFO
//
void spi_fifo_init()
{
    //
    // Initialize SPI FIFO registers
    //
    SpicRegs.SPIFFTX.all = 0xE082;    // Enable FIFOs, set TX FIFO level to 2
    SpicRegs.SPIFFRX.all = 0x24A2;    // Set RX FIFO level to 2
    SpicRegs.SPIFFCT.all = 0x0000;


    //
    // Initialize core SPI registers
    //
    SpiInit();
}


//
// spiRxFifoIsr - ISR for SPI receive FIFO
//
interrupt void spicRxFIFOISR(void)
{
    counter++;
    rdata=(SpicRegs.SPIDAT);     // Read data
    rdata=rdata%256;
    rdata=(rdata<<4);

    SpicRegs.SPIFFRX.bit.RXFFOVFCLR=1;  // Clear Overflow flag
    SpicRegs.SPIFFRX.bit.RXFFINTCLR=1;  // Clear Interrupt flag
       PieCtrlRegs.PIEACK.all = PIEACK_GROUP6;
}


void SpicInitGpio()
{
   EALLOW;

    //
    // Enable internal pull-up for the selected pins
    //
    // Pull-ups can be enabled or disabled by the user.
    // This will enable the pullups for the specified pins.
    // Comment out other unwanted lines.
    //
   GpioCtrlRegs.GPDPUD.bit.GPIO122 = 0; // Enable pull-up on GPIO122 (SPISIMOC)
   GpioCtrlRegs.GPDPUD.bit.GPIO123 = 0; // Enable pull-up on GPIO123 (SPISOMIC)
   GpioCtrlRegs.GPDPUD.bit.GPIO124 = 0; // Enable pull-up on GPIO124 (SPICLKC)
   GpioCtrlRegs.GPDPUD.bit.GPIO125 = 0; // Enable pull-up on GPIO125 (SPISTEC)

   GpioCtrlRegs.GPDQSEL2.bit.GPIO122 = 3; // Asynch input GPIO122 (SPISIMOC)
   GpioCtrlRegs.GPDQSEL2.bit.GPIO123 = 3; // Asynch input GPIO123 (SPISOMIC)
   GpioCtrlRegs.GPDQSEL2.bit.GPIO124 = 3; // Asynch input GPIO124 (SPICLKC)
   GpioCtrlRegs.GPDQSEL2.bit.GPIO125 = 3; // Asynch input GPIO125 (SPISTEC)

   GpioCtrlRegs.GPDMUX2.bit.GPIO122 = 2; // Configure GPIO122 as SPISIMOC
   GpioCtrlRegs.GPDMUX2.bit.GPIO123 = 2; // Configure GPIO123 as SPISOMIC
   GpioCtrlRegs.GPDMUX2.bit.GPIO124 = 2; // Configure GPIO124 as SPICLKC
   GpioCtrlRegs.GPDMUX2.bit.GPIO125 = 2; // Configure GPIO125 as SPISTEC

   GpioCtrlRegs.GPDGMUX2.bit.GPIO122 = 1; // Configure GPIO122 as SPISIMOC
   GpioCtrlRegs.GPDGMUX2.bit.GPIO123 = 1; // Configure GPIO123 as SPISOMIC
   GpioCtrlRegs.GPDGMUX2.bit.GPIO124 = 1; // Configure GPIO124 as SPICLKC
   GpioCtrlRegs.GPDGMUX2.bit.GPIO125 = 1; // Configure GPIO125 as SPISTEC




    EDIS;

}

void SpiInit(void)
{

    // Set the baud rate
        SpicRegs.SPIBRR.bit.SPI_BIT_RATE = 0x0001;
    // Halting on a breakpoint will not halt the SPI
        SpicRegs.SPIPRI.bit.FREE = 1;




        //When changing configuration, you should clear this bit before the changes and set this bit before resuming operation.
        SpicRegs.SPICCR.bit.SPISWRESET = 1;
        //(Shift Clock Polarity) This bit controls the polarity of the SPICLK signal. CLOCK POLARITY and POLARITY CLOCK PHASE (SPICTL.3) control four clocking schemes on the SPICLK pin.
        SpicRegs.SPICCR.bit.CLKPOLARITY = 0;
        //(Character Length Control Bits)the number of bits to be shifted in or SPI CHAR0 out as a single character during one shift sequence.
        SpicRegs.SPICCR.bit.SPICHAR = 7;//( 8-bit f bits to be shifted in or SPI CHAR0)

        //SPI is configured as a slave
        SpicRegs.SPICTL.bit.MASTER_SLAVE = 0;
        //Enables transmission
        SpicRegs.SPICTL.bit.TALK =0;
        //SPI Clock Phase Select
        SpicRegs.SPICTL.bit.CLK_PHASE = 0;

}

//
// End of file
//

我应该更改此代码部分的哪一部分?

或者 我的计算错误?  

如果您能帮我解决问题、我将不胜感激。

此致、

Jessie

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

    Jessie、您好!

    您是否曾尝试使用示波器验证从 Arduino 输出的数据? 在 F28379D 上接收到的数据是否存在问题?

    通常情况下、数据不会从 SPIDAT 中读取、因为这是发送和接收移位寄存器、数据应从 SPIRXBUF 寄存器中读取。

    TX FIFO 中的每个 FIFO 都启用了2级 FIFO、这意味着只有当 RXFFST 大于或等于 RXFFIL (设为2个字)时、RX ISR 才会执行。 这正是您所期望的吗?

    此致、

    Marlyn

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

    如果我不向 主器件(Arduino)传输数据、我仍然设置 TXFFIENA 和 TXFFIL?

    此致、

    Jessie

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

    Jessie、您好!

    如果您没有写入发送缓冲区、则不会产生发送中断、因为 FIFO 的条件将不会满足。 您还将 TXFFIENA 位设置为0、以禁用 TX 中断、因此我认为这不会影响您看到的内容。   

    正如我之前所说的、您是否尝试使用示波器来验证从 Arduino 输出的数据? 在 F28379D 上接收到的数据是否存在问题?

    此致、

    Marlyn