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.

AWR1843BOOST: 从设备spi数据输出

Part Number: AWR1843BOOST
Other Parts Discussed in Thread: AWR1843

我在尝试使用awr1843作为从设备与树莓派进行数据传输,两设备均测试了spi短接通信(自发自收)正常,两设备也可进行通信,当前我遇到的问题是,树莓派发送的数据与1843收到的数据不一致,1843发出的数据也与树莓派的接收的不一致,这是什么导致的?
1843 mss中主函数涉及spi通信的任务函数为:

static void InitDriverTask_SPI_Slave(UArg arg0, UArg arg1)
{
    int32_t         errCode;
    DMA_Params      dmaParams;
    SPI_Params      spiParams;
    SPI_Transaction spiTransaction;
    bool            transferOK;

    uint8_t txBuffer[8] = {0xaa, 0xbb, 0xcc ,0xdd, 0x11, 0x22, 0x33, 0x44};
    uint8_t rxBuffer[8];

    System_printf("Debug: InitDriverTask_SPI_Slave started\n");

    Pinmux_Set_OverrideCtrl(SOC_XWR18XX_PINE13_PADAF, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL);
    Pinmux_Set_FuncSel(SOC_XWR18XX_PINE13_PADAF, SOC_XWR18XX_PINE13_PADAF_SPIA_CLK);

    Pinmux_Set_OverrideCtrl(SOC_XWR18XX_PIND13_PADAD, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL);
    Pinmux_Set_FuncSel(SOC_XWR18XX_PIND13_PADAD, SOC_XWR18XX_PIND13_PADAD_SPIA_MOSI);

    Pinmux_Set_OverrideCtrl(SOC_XWR18XX_PINE14_PADAE, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL);
    Pinmux_Set_FuncSel(SOC_XWR18XX_PINE14_PADAE, SOC_XWR18XX_PINE14_PADAE_SPIA_MISO);

    Pinmux_Set_OverrideCtrl(SOC_XWR18XX_PINE15_PADAG, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL);
    Pinmux_Set_FuncSel(SOC_XWR18XX_PINE15_PADAG, SOC_XWR18XX_PINE15_PADAG_SPIA_CSN);

    Pinmux_Set_OverrideCtrl(SOC_XWR18XX_PINP13_PADAA, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL);
    Pinmux_Set_FuncSel(SOC_XWR18XX_PINP13_PADAA, SOC_XWR18XX_PINP13_PADAA_SPI_HOST_INTR);

    /* Init SYSDMA params */
    DMA_Params_init(&dmaParams);
    /* Open DMA driver instance 0 for SPI test */
    DMA_Handle dmaHandle = DMA_open(0, &dmaParams, &errCode);

    if (dmaHandle == NULL)
    {
        System_printf("Open DMA driver failed with error=%d\n", errCode);
        return;
    }

    SPI_init();

    if (SOC_SPIOutputCtrl(gAdcdataMSSMCB.socHandle, 0, 1, &errCode) < 0)
    {
      /* Debug Message: */
      System_printf("Debug: SOC_SPIOutputCtrl failed with Error [%d]\n", errCode);
      return;
    }

    SPI_Params_init(&spiParams);

   spiParams.mode        = SPI_SLAVE;       
   spiParams.dataSize    = 8;               
   spiParams.frameFormat = SPI_POL0_PHA0;   
   spiParams.shiftFormat = SPI_MSB_FIRST;
   spiParams.u.slaveParams.dmaCfg.txDmaChanNum = 1U;
   spiParams.u.slaveParams.dmaCfg.rxDmaChanNum = 0U;

   spiParams.dmaEnable = 1;
   spiParams.dmaHandle = dmaHandle;
   spiParams.pinMode   = SPI_PINMODE_3PIN;
   spiParams.eccEnable = 0;

    gAdcdataMSSMCB.spiHandle = SPI_open(0, &spiParams);
    if (gAdcdataMSSMCB.spiHandle == NULL)
    {
        System_printf("Error: Unable to open SPI in slave mode\n");
        return;
    }
    System_printf("Debug: SPI opened in slave mode, waiting for master\n");

   while (1)
   {
       memset(rxBuffer, 0, sizeof(rxBuffer));
       spiTransaction.count = sizeof(txBuffer);
       spiTransaction.txBuf = (void *)txBuffer;
       spiTransaction.rxBuf = (void *)rxBuffer;
       spiTransaction.slaveIndex = 0;

       transferOK = SPI_transfer(gAdcdataMSSMCB.spiHandle, &spiTransaction);

       if (transferOK)
       {
           uint32_t i;

           System_printf("Debug: SPI transfer done\n");

           System_printf("RX data: ");
           for (i = 0; i < sizeof(rxBuffer); i++)
           {
               System_printf("0x%02x ", rxBuffer[i]);
           }
           System_printf("\n");

           System_printf("TX data: ");
           for (i = 0; i < sizeof(txBuffer); i++)
           {
               System_printf("0x%02x ", txBuffer[i]);
           }
           System_printf("\n");
       }
       else
       {
           System_printf("Debug: SPI transfer failed\n");
       }
   }
}


树莓派采用python进行spi数据传输,代码为:

import spidev

spi = spidev.SpiDev()
spi.open(0, 0)

spi.max_speed_hz = 50000
spi.bits_per_word = 8
spi.mode=0

send_data = [0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88]
print("Send:", [hex(x) for x in send_data])
print("Recv:", [hex(x) for x in rx_data])

spi.close()

如上,1843在收到树莓派发送的[0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88]后,会发送{0xaa, 0xbb, 0xcc ,0xdd, 0x11, 0x22, 0x33, 0x44},两设备调试时均会打印发送与接收数据,但是都不能对上,例如,树莓派打印的接发数据为:
Send: ['0x11', '0x22', '0x33', '0x44', '0x55', '0x66', '0x77', '0x88']
Recv: ['0x11', '0x20', '0x3', '0x44', '0x40', '0x0', '0x44', '0x0']
而1843 ccs工程中打印的接发数据为:
RX data: 0x88 0x54 0x23 0x1a 0x22 0xa9 0x98 0xef
TX data: 0xaa 0xbb 0xcc 0xdd 0x11 0x22 0x33 0x44
且两边的接收数据几乎每次都不同
对于spi参数,不同帧模式(spi.mode)、dma是否开启、pinMode是SPI_PINMODE_3PIN还是SPI_PINMODE_4PIN_CS乃至csHold=1等参数设置我都有尝试过,两设备接发数据不一致的问题并没有解决。