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.
Hi,
Is there any example code which uses the motorware driver library for setting up SPI?
Specifically, I'm having the devil of a job trying to get an SPI input feed operational from an encoder source.
Setting the F29069M up as an SPI slave with only MISO and CLK connections, I can clearly see the incoming datastream on GPIO17 (data) and GPIO18 (clk) - see picture below. The RX interrupt is firing on a regular beat, but within the interrupt handler:
- SPIDAT is 0xFFFF
- SPIRXBUF is 0xFFFF
- FifoStatus reads empty
Based on lab code examples, GPIO has been setup as:
GPIO_setMode(obj->gpioHandle, GPIO_Number_17, GPIO_17_Mode_SPISOMIA); GPIO_setDirection(obj->gpioHandle, GPIO_Number_17, GPIO_Direction_Input); GPIO_setQualification(obj->gpioHandle, GPIO_Number_17, GPIO_Qual_ASync); GPIO_setMode(obj->gpioHandle, GPIO_Number_18, GPIO_18_Mode_SPICLKA); GPIO_setDirection(obj->gpioHandle, GPIO_Number_18, GPIO_Direction_Input); GPIO_setQualification(obj->gpioHandle, GPIO_Number_18, GPIO_Qual_ASync);
Clocks added to the clock section :
CLK_enableSpiaClock(obj->clkHandle); CLK_disableSpibClock(obj->clkHandle);
New SPI Setup routine added:
void HAL_setupSPI(HAL_Handle handle) { HAL_Obj *obj = (HAL_Obj *) handle; SPI_reset(obj->spiaHandle); SPI_enableRxFifo(obj->spiaHandle); SPI_setRxFifoIntLevel(obj->spiaHandle, SPI_FifoLevel_2_Words); SPI_disableLoopBack(obj->spiaHandle); SPI_setBaudRate(obj->spiaHandle, SPI_BaudRate_1_MBaud); SPI_setCharLength(obj->spiaHandle, SPI_CharLength_16_Bits); SPI_setClkPhase(obj->spiaHandle, SPI_ClkPhase_Normal); SPI_setClkPolarity(obj->spiaHandle, SPI_ClkPolarity_OutputRisingEdge_InputFallingEdge); SPI_setMode(obj->spiaHandle, SPI_Mode_Slave); SPI_enableRxFifoInt(obj->spiaHandle); SPI_enableInt(obj->spiaHandle); SPI_enable(obj->spiaHandle); SPI_resetRxFifo(obj->spiaHandle); PIE_enableInt(obj->pieHandle, PIE_GroupNumber_6, PIE_InterruptSource_SPIARX); CPU_enableInt(obj->cpuHandle, CPU_IntNumber_6); // enable SCI CPU interrupt }
and finally, the ISRs amended:
static inline void HAL_initIntVectorTable(HAL_Handle handle) { HAL_Obj *obj = (HAL_Obj *) handle; PIE_Obj *pie = (PIE_Obj *) obj->pieHandle; ENABLE_PROTECTED_REGISTER_WRITE_MODE; pie->ADCINT1 = &mainISR; pie->SPIRXINTA = &spiFIFORX_ISR; DISABLE_PROTECTED_REGISTER_WRITE_MODE; return; } // end of HAL_initIntVectorTable() function
My ISR routine then consists:
interrupt void spiFIFORX_ISR(void) { HAL_Obj *obj = (HAL_Obj *) m_HalHandle; fifostatus = SPI_getRxFifoStatus(obj->spiaHandle); //for debug only lastvalue = HAL_readSPIdword(m_HalHandle); //redirects to {return SPI_read(obj->spiaHandle);} HAL_ackSpiRxInt(m_HalHandle); }
I'm at a bit of a loss to understand why I get absolutely nothing, but the ISR is firing, but nothing in the RXBuffer. Any clues anyone?
Mat
GPIO_Number_17
Managed to crack it in the end, just a one-line addition to setup:
SPI_setTriWire(obj->spiaHandle, SPI_TriWire_ThreeWire);
thanks
Mat