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.

AM3352 McSPI讀取資料問題



您好,

我參考StartWare02_02_01_01撰寫了一個spi的測試程式..

情況1. 在WAIT_EOT=0的情況下,運行讀寫測試...,讀寫數百次後,會有機會讀回一筆0x00(但應該是0x86)

情況2. 在WAIT_EOT=1的情況下,運行讀寫測試...,每次讀回的資料是0x00(但應該是0x86)

PS:沒有啟用中斷服務..

請問,是否有需要注意的地方呢?

Kerry

static void WriteEnable(void)
{
unsigned char tmp;
unsigned char cnt = 0x86;

while(1) {
McSPITransfer(0x4800, cnt);
tmp = McSPITransfer(0x4A00, 0x00);
if(cnt != tmp)
{
DEBUG("loopCnt = %d, wr = %x, rd = %x", loopCnt, cnt, tmp);
}
}

return ;
}

unsigned char McSPITransfer(unsigned short cmd, unsigned short data)
{
unsigned char rcv_data = 0;
unsigned short cmd_data ;
cmd_data = cmd + data;

/* SPIEN line is forced to low state.*/
McSPICSAssert(SOC_SPI_0_REGS, chNum);

/* Enable the McSPI channel for communication.*/
McSPIChannelEnable(SOC_SPI_0_REGS, chNum);

McSPITransmitData(SOC_SPI_0_REGS,(unsigned int)cmd_data, chNum);

#if WAIT_EOT
//Wait until 'end of transmission' flag is set
while (0 == (McSPIChannelStatusGet(SOC_SPI_0_REGS, chNum) & MCSPI_CH0STAT_EOT))
{
//Wait and do nothing
}
#endif

rcv_data = McSPIReceiveData(SOC_SPI_0_REGS, chNum);

/* Force SPIEN line to the inactive state.*/
McSPICSDeAssert(SOC_SPI_0_REGS, chNum);
McSPIChannelDisable(SOC_SPI_0_REGS, chNum);

return rcv_data;

}

  • 请问具体是参考的哪个例程?

    liu kerry 说:

    情況1. 在WAIT_EOT=0的情況下,運行讀寫測試...,讀寫數百次後,會有機會讀回一筆0x00(但應該是0x86)

    情況2. 在WAIT_EOT=1的情況下,運行讀寫測試...,每次讀回的資料是0x00(但應該是0x86)

    不是很清楚这两种判断情况是什么意思?

    从手册来看,EOT是自动清除和置位的。

  • Dear Nancy,

    我是參考...AM335X_StarterWare_02_00_01_01-master/examples/evmAM335x/mcspi/mcspiFlash.c

    簡單來說,,,

    當我McSPITransmitData()這個函數執行後,若等待MCSPI_CH0STAT_EOT這個bit的資料變high才去讀取RX的資料,則RX的值永遠為"0"
    若沒等待"MCSPI_CH0STAT_EOT",直接去讀取RX的資料..則大部分讀回來的值,是正確的,偶爾會讀到"0"

    Kerry
  • 方便的话将配置模式也贴出来。
    我觉得可以试试看轮询MCSPI_CH0STAT的RXS位,然后从MCSPI_RX0读取。
  • Dear Nancy ,

    麻煩您了...謝謝

    相關資料如下!

    Kerry

    chNum = 1;

    /* Enable the clocks for McSPI0 module.*/
    McSPI0ModuleClkConfig();

    /* Perform Pin-Muxing for SPI0 Instance */
    McSPIPinMuxSetup();

    /* Perform Pin-Muxing for CS0/CS1 of SPI0 Instance */
    McSPI0CSPinMuxSetup(chNum);

    /* Reset the McSPI instance.*/
    McSPIReset(SOC_SPI_0_REGS);

    /* Enable chip select pin.*/
    McSPICSEnable(SOC_SPI_0_REGS);

    /* Enable master mode of operation.*/
    McSPIMasterModeEnable(SOC_SPI_0_REGS);

    /* Perform the necessary configuration for master mode.*/
    McSPIMasterModeConfig(SOC_SPI_0_REGS, MCSPI_MULTI_CH,
    MCSPI_TX_RX_MODE, MCSPI_DATA_LINE_COMM_MODE_0,
    chNum);

    /* Configure the McSPI bus clock depending on clock mode. */
    McSPIClkConfig(SOC_SPI_0_REGS, MCSPI_IN_CLK, MCSPI_OUT_FREQ, chNum,
    MCSPI_CLK_MODE_1);

    /* Configure the word length.*/
    McSPIWordLengthSet(SOC_SPI_0_REGS, MCSPI_WORD_LENGTH(16), chNum);

    /* Set polarity of SPIEN to low.*/
    McSPICSPolarityConfig(SOC_SPI_0_REGS, MCSPI_CS_POL_LOW, chNum);

    WriteEnable();

    static void WriteEnable(void)
    {
    unsigned char tmp;
    unsigned char cnt = 0x86;

    while(1) {
    McSPITransfer(0x4800, cnt);
    tmp = McSPITransfer(0x4A00, 0x00);
    if(cnt != tmp)
    {
    DEBUG("loopCnt = %d, wr = %x, rd = %x", loopCnt, cnt, tmp);
    }
    }

    return ;
    }

    unsigned char McSPITransfer(unsigned short cmd, unsigned short data)
    {
    unsigned char rcv_data = 0;
    unsigned short cmd_data ;
    cmd_data = cmd + data;

    /* SPIEN line is forced to low state.*/
    McSPICSAssert(SOC_SPI_0_REGS, chNum);

    /* Enable the McSPI channel for communication.*/
    McSPIChannelEnable(SOC_SPI_0_REGS, chNum);

    McSPITransmitData(SOC_SPI_0_REGS,(unsigned int)cmd_data, chNum);

    #if WAIT_EOT
    //Wait until 'end of transmission' flag is set
    while (0 == (McSPIChannelStatusGet(SOC_SPI_0_REGS, chNum) & MCSPI_CH0STAT_EOT))
    {
    //Wait and do nothing
    }
    #endif

    rcv_data = McSPIReceiveData(SOC_SPI_0_REGS, chNum);

    /* Force SPIEN line to the inactive state.*/
    McSPICSDeAssert(SOC_SPI_0_REGS, chNum);
    McSPIChannelDisable(SOC_SPI_0_REGS, chNum);

    return rcv_data;

    }

  • 请问有没有试过轮询MCSPI_CH0STAT的RXS位,然后从MCSPI_RX读取?结果如何?
  • Dear Nancy,

    有的...,程式如下...

    但使用這個方法的話..除了跟之前的狀況一樣偶爾會讀回"0x00"以外..

    還多了一個問題...就是..偶爾會在這個迴圈一直跑...無法跳出..也就是MCSPI_CH0STAT_RXS一直為"1"

    Kerry

    while (1 == (McSPIChannelStatusGet(SOC_SPI_0_REGS, chNum) & MCSPI_CH0STAT_RXS))
    {
    //Wait and do nothing
    }

  • Dear Nancy,

    請問有任何建議嗎???

    Kerry

  • 抱歉,还是建议对比看一下PDK中提供的代码<PDK_INSTALL_PATH>/ti/drv/spi/example中的代码。
    software-dl.ti.com/.../index_device_drv.html
  • 我是使用linux, rtos的PDK適用嗎?

    附檔是我的測試程式..給您參考..看是否有那裡少設定了!

    感謝!

    PS:  CS 是使用 SPIO_CS1(C15)

    MISO 是使用 SPIO_D0)(B17)

    MOSI 是使用 SPIO_D1)(B16)

    CLK 是使用 SPIO_SCLK)(A17)

    Kerry8206.mcspi_test.zip

  • 您好,

    附檔是我的測試程式,pic的資料夾裡面是有關dts,原理圖,及強制MISO的訊號pull high及pull low的照片

    目前不論MISO pull high or low,讀回來的值都是

    ff99
    c801
    201
    c1a

    可以請您幫忙看看,哪裡出錯了嗎?

    可以請您協助我..讓他讀回來的資料是0xffff or 0x0 嗎?

    若要編譯代碼,修改build.sh裡面toolchain的路徑就可以編譯了

    Kerry1067.mcspi.zip