Do you have examples of Multiple SPI device in MotorWare? i have two SPI device 16 bit (DRV8305) und 24 bit with different SPI Mode.
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.
I use GPIO as CS. Is there a good decision for the correct timing management of CS SPI? To use a delay cycle for SPI CS is not very good.
Hi, everybody,
help to find a mistake. I have me two configurations for SPIa. Each of them works well.
When I switch from a SPIa > MCP2515 > SPIa.
I read the wrong data.
void HAL_setupSpiA(HAL_Handle handle) { HAL_Obj *obj = (HAL_Obj *)handle; SPI_reset(obj->spiAHandle); SPI_setMode(obj->spiAHandle,SPI_Mode_Master); SPI_setClkPhase(obj->spiAHandle, SPI_ClkPhase_Normal); SPI_setClkPolarity(obj->spiAHandle,SPI_ClkPolarity_OutputRisingEdge_InputFallingEdge); SPI_enableTx(obj->spiAHandle); SPI_enableTxFifoEnh(obj->spiAHandle); SPI_enableTxFifo(obj->spiAHandle); SPI_enableRxFifoInt(obj->spiAHandle); SPI_setTxDelay(obj->spiAHandle,0x0010); SPI_setBaudRate(obj->spiAHandle,(SPI_BaudRate_e)(0x0001)); SPI_setCharLength(obj->spiAHandle,SPI_CharLength_16_Bits); SPI_setSuspend(obj->spiAHandle,SPI_TxSuspend_free); SPI_enable(obj->spiAHandle); return; } // end of HAL_setupSpiA() function #endif #ifdef MCP2515 void HAL_setupSpi_MCP2515(HAL_Handle handle) { HAL_Obj *obj = (HAL_Obj *)handle; SPI_reset(obj->spiAHandle); SPI_setMode(obj->spiAHandle,SPI_Mode_Master); SPI_setClkPhase(obj->spiAHandle, SPI_ClkPhase_Delayed); SPI_setClkPolarity(obj->spiAHandle,SPI_ClkPolarity_OutputRisingEdge_InputFallingEdge); SPI_enableTx(obj->spiAHandle); SPI_disableTxFifoEnh(obj->spiAHandle); SPI_disableRxFifoInt(obj ->spiAHandle); SPI_enableInt(obj->spiAHandle); //SPI_setTxDelay(obj->spiAHandle,0x0010); SPI_setBaudRate(obj->spiAHandle,(SPI_BaudRate_e)(0x0001)); SPI_setCharLength(obj->spiAHandle,SPI_CharLength_8_Bits); SPI_setSuspend(obj->spiAHandle,SPI_TxSuspend_free); SPI_enable(obj->spiAHandle); return; } // end of HAL_setupSpi_MCP2515() function #endif
#ifdef DRV8305_SPI // turn on the DRV8305 if present HAL_enableDrv(halHandle); // initialize the DRV8305 interface HAL_setupDrvSpi(halHandle,&gDrvSpi8305Vars); #endif #ifdef MCP2515 HAL_setupSpi_MCP2515(halHandle); SPI_ReadByte = MCP2515_begin(halHandle->mcp2515Handle, CAN_500KBPS); MCP2515_init_Mask(halHandle->mcp2515Handle, 0, 0, 0x000F); MCP2515_init_Filt(halHandle->mcp2515Handle, 0, 0, NODE_ID /*getNodeId(&ObjDict_Data)*/); // RxPDO and SDO MCP2515_init_Filt(halHandle->mcp2515Handle, 1, 0, NODE_ID /*getNodeId(&ObjDict_Data)*/); // same MCP2515_init_Mask(halHandle->mcp2515Handle, 1, 0, 0x07FF); // MCP2515_init_Filt(halHandle->mcp2515Handle, 2, 0, 0x0000); // NMT // MCP2515_init_Filt(halHandle->mcp2515Handle, 3, 0, 0x0080); // sync // MCP2515_init_Filt(halHandle->mcp2515Handle, 4, 0, 0x0100); // time stamp // MCP2515_init_Filt(halHandle->mcp2515Handle, 5, 0, 0x0000); // dummy HAL_setupSpiA(halHandle); //Added #endif
Error in SPI.C library.
void SPI_setClkPhase(SPI_Handle spiHandle,const SPI_ClkPhase_e clkPhase) { SPI_Obj *spi = (SPI_Obj *)spiHandle; // clear the bits spi->SPICTL &= (~SPI_SPICTL_CLK_PHASE_BITS); // Add Andrew // set the value spi->SPICTL |= clkPhase; return; } // end of SPI_setClkPhase() function