I am having trouble with the receive side of SPI 1 instance on the AM437x GP EVM. I have modified the MCSPI example to use instance 1 with the following settings. I can see data transmit out properly on oscope. I can see the slave respond properly. I receive an RXfull interrupt, but all zeros are always put into the RXFIFO even though I can clearly see different results on the D0 input pin. I attempted to swap D0 and D1 to check for a damaged input, but the results were the same....transmits fine but stores all 0's in RXFIFO. See code snippets below.
Thanks,
John
static const mcspiAppCfgObj_t MCSPIAPPFLASH_DEFAULT = { 1U, /* instNum.*/ 0x481A0000U, /* instAddr.*/ 48000000U, /* inClk.*/ 12000000U, /* outClk.*/ 0U, /* channelNum.*/ 2U, /* dataLength.*/ gFlashAppTxBuffer, /* pTx.*/ gFlashAppRxBuffer, /* rTx.*/ { MCSPI_CH_SINGLE, /* channel.*/ MCSPI_TRANSFER_MODE_TX_RX, /* txRxMode.*/ MCSPI_DATA_LINE_COMM_MODE_1, /* pinMode. */ MCSPI_CLK_MODE_1, /* clkMode.*/ 8U, /* wordLength.*/ MCSPI_CS_POL_LOW, /* csPolarity.*/ TRUE, /* txFifoCfg.*/ TRUE, /* rxFifoCfg.*/ MCSPI_INTR_TX_EMPTY(0U) | \ MCSPI_INTR_RX_FULL(0U) /* interrupt.*/ }, { INTC_TRIG_HIGH_LEVEL, /* trigType.*/ 157U, /* intrLine */ 10U, /* intrPriority.*/ FALSE, /* isIntrSecure.*/ gFlashAppTxBuffer, /* pTxBuf.*/ gFlashAppRxBuffer, /* pRxBuf.*/ NULL /* pFnIntrHandler.*/ }, { TRUE, /* csFlag.*/ MCSPI_MODE_MASTER, /* modeFlag.*/ MCSPI_INTERRUPT_MODE /* comFlag.*/ } };
Here is the main loop
int main() { gFlashAppCfg = MCSPIAPPFLASH_DEFAULT; /* Initialize the UART console */ CONSOLEUtilsInit(); /* Select the console type based on compile time check */ CONSOLEUtilsSetType(CONSOLE_UTILS_TYPE_UART); BOARDInit(NULL); /* Initialize the MCSPI controller. */ MCSPIAppInit(&gFlashAppCfg); McspiAppIsWriteSuccess(&gFlashAppCfg); }
static uint32_t McspiAppIsWriteSuccess(mcspiAppCfgObj_t *pCfgMcspi) { uint8_t temprx = 0xFFu; gFlashAppTxBuffer[0U] = 54U; gFlashAppTxBuffer[1U] = 0xFFU; pCfgMcspi->dataLength = 2U; MCSPIAppTransfer(pCfgMcspi); temprx = gFlashAppRxBuffer[0U]; temprx = gFlashAppRxBuffer[1U]; return(1U); }
static uint32_t McspiAppIsWriteSuccess(mcspiAppCfgObj_t *pCfgMcspi) { uint8_t temprx = 0xFFu; gFlashAppTxBuffer[0U] = 54U; // read command to slave gFlashAppTxBuffer[1U] = 0xFFU; // dummy write for read pCfgMcspi->dataLength = 2U; MCSPIAppTransfer(pCfgMcspi); temprx = gFlashAppRxBuffer[0U]; temprx = gFlashAppRxBuffer[1U]; return(1U); }
int32_t MCSPIAppInit(mcspiAppCfgObj_t *pCfgMcspi) { /* Clock Configuration. */ PRCMModuleEnable(CHIPDB_MOD_ID_MCSPI, pCfgMcspi->instNum, 0U); /* Perform the MCSPI pinmux. */ PINMUXModuleConfig(CHIPDB_MOD_ID_MCSPI, pCfgMcspi->instNum, NULL); if(MCSPI_INTERRUPT_MODE == pCfgMcspi->pAppFlag.comFlag) { /* Register the MCSPI interrupts. */ McspiAppIntrConfig(pCfgMcspi); /* Reset the MCSPI instance.*/ MCSPIReset(pCfgMcspi->instAddr); if (TRUE == pCfgMcspi->pAppFlag.csFlag) { /* Enable CS. */ MCSPICsEnable(pCfgMcspi->instAddr, TRUE); /* Set the CS polarity. */ MCSPISetCsPol(pCfgMcspi->instAddr, pCfgMcspi->channelNum, pCfgMcspi->pAppCfg.csPolarity); } else if (FALSE == pCfgMcspi->pAppFlag.csFlag) { /** * Disable CS. In this scenario the CS will be handled * externally. E.g. would be using an external GPIO pin * or the CS pin of slave device is pulled to the required * polarity as default. */ MCSPICsEnable(pCfgMcspi->instAddr, FALSE); } if (MCSPI_MODE_MASTER == pCfgMcspi->pAppFlag.modeFlag) { /* Perform the necessary configuration for master mode.*/ MCSPIModeConfig(pCfgMcspi->instAddr, pCfgMcspi->channelNum, pCfgMcspi->pAppFlag.modeFlag, pCfgMcspi->pAppCfg.channel, pCfgMcspi->pAppCfg.txRxMode, pCfgMcspi->pAppCfg.pinMode); /* Configure the clock speed on the bus. */ MCSPIClkConfig(pCfgMcspi->instAddr, pCfgMcspi->channelNum, pCfgMcspi->inClk, pCfgMcspi->outClk, pCfgMcspi->pAppCfg.clkMode); } else if (MCSPI_MODE_SLAVE == pCfgMcspi->pAppFlag.modeFlag) { /* Perform the necessary configuration for slave mode.*/ MCSPIModeConfig(pCfgMcspi->instAddr, pCfgMcspi->channelNum, pCfgMcspi->pAppFlag.modeFlag, pCfgMcspi->pAppCfg.channel, pCfgMcspi->pAppCfg.txRxMode, pCfgMcspi->pAppCfg.pinMode); } /* Configure the word length. */ MCSPISetWordLength(pCfgMcspi->instAddr, pCfgMcspi->channelNum, pCfgMcspi->pAppCfg.wordLength); /* Enable/disable the Tx FIFO. */ MCSPITxFifoEnable(pCfgMcspi->instAddr, pCfgMcspi->channelNum, pCfgMcspi->pAppCfg.txFifoCfg); /* Enable/disable the Rx FIFO. */ MCSPIRxFifoEnable(pCfgMcspi->instAddr, pCfgMcspi->channelNum, pCfgMcspi->pAppCfg.rxFifoCfg); /* Set Transfer Interrupt Levels*/ // I added this to get RX full interrupt to generate MCSPISetFifoTriggerLvl(pCfgMcspi->instAddr, 1U, 1U, pCfgMcspi->pAppCfg.txRxMode); } else if(MCSPI_DMA_MODE == pCfgMcspi->pAppFlag.comFlag) { CONSOLEUtilsPrintf("\n DMA mode is not supported !\n"); } return(1U); }
Here are my pinmux settings
static pinmuxPerCfg_t gSpi1PinCfg[] = { { /* MySPI1 -> spi1_sclk -> N24 */ PIN_MCASP0_ACLKX, 0, \ ( \ PIN_MODE(3) | \ ((PIN_PULL_UD_DIS | PIN_PULL_UP_EN | PIN_DS_VALUE_OVERRIDE_EN | PIN_DS_OP_DIS | PIN_DS_PULL_UP_EN) & \ (~PIN_RX_ACTIVE & ~PIN_DS_OP_VAL_1 & ~PIN_DS_PULL_UD_EN & ~PIN_WAKE_UP_EN)) ) \ }, { /* MySPI1 -> spi1_d0 -> N22 MISO*/ PIN_MCASP0_FSX, 0, \ ( \ PIN_MODE(3) | \ ((PIN_RX_ACTIVE | PIN_DS_VALUE_OVERRIDE_EN | PIN_DS_OP_DIS | PIN_DS_PULL_UP_EN) & \ (~PIN_PULL_UD_DIS & ~PIN_PULL_UP_EN & ~PIN_DS_OP_VAL_1 & ~PIN_DS_PULL_UD_EN & ~PIN_WAKE_UP_EN)) ) \ }, { /* MySPI1 -> spi1_d1 -> H23 MOSI*/ PIN_MCASP0_AXR0, 0, \ ( \ PIN_MODE(3) | \ ((PIN_PULL_UD_DIS | PIN_PULL_UP_EN | PIN_DS_VALUE_OVERRIDE_EN | PIN_DS_OP_DIS | PIN_DS_PULL_UP_EN) & \ (~PIN_RX_ACTIVE & ~PIN_DS_OP_VAL_1 & ~PIN_DS_PULL_UD_EN & ~PIN_WAKE_UP_EN)) ) \ }, { /* MySPI1 -> spi1_cs0 -> M24 */ PIN_MCASP0_AHCLKR, 0, \ ( \ PIN_MODE(3) | \ ((PIN_PULL_UD_DIS | PIN_PULL_UP_EN | PIN_DS_VALUE_OVERRIDE_EN | PIN_DS_OP_DIS | PIN_DS_PULL_UP_EN) & \ (~PIN_RX_ACTIVE & ~PIN_DS_OP_VAL_1 & ~PIN_DS_PULL_UD_EN & ~PIN_WAKE_UP_EN)) ) \ }, {PINMUX_INVALID_PIN} };