Other Parts Discussed in Thread: C2000WARE
Tool/software:
Greetings! I am using C2000Ware_MotorControl_SDK_5_03_00_00 with F280041C. I am trying to setup SPIB interface. Here are my settings:
// SPI SIMO
GPIO_setMasterCore(56, GPIO_CORE_CPU1);
GPIO_setPinConfig(GPIO_56_SPIB_SIMO);
GPIO_setDirectionMode(56, GPIO_DIR_MODE_IN);
GPIO_setPadConfig(56, GPIO_PIN_TYPE_STD);
// SPI SOMI
GPIO_setMasterCore(57, GPIO_CORE_CPU1);
GPIO_setPinConfig(GPIO_57_SPISOMIB);
GPIO_setDirectionMode(57, GPIO_DIR_MODE_IN);
GPIO_setPadConfig(57, GPIO_PIN_TYPE_STD);
// SPI CLK
GPIO_setMasterCore(58, GPIO_CORE_CPU1);
GPIO_setPinConfig(GPIO_58_SPIB_CLK);
GPIO_setDirectionMode(58, GPIO_DIR_MODE_IN);
GPIO_setPadConfig(58, GPIO_PIN_TYPE_STD);
void HAL_setupSPIB(HAL_Handle handle)
{
HAL_Obj *obj = (HAL_Obj *)handle;
// Must put SPI into reset before configuring it
SPI_disableModule(obj->spiHandle[1]);
// SPI configuration. Use a 1MHz SPICLK and 16-bit word size.
SPI_setConfig(obj->spiHandle[1], DEVICE_LSPCLK_FREQ, SPI_PROT_POL0PHA1,
SPI_MODE_MASTER, 500000, 8);
SPI_disableLoopback(obj->spiHandle[1]);
SPI_setEmulationMode(obj->spiHandle[1], SPI_EMULATION_FREE_RUN);
//SPI_enableFIFO(obj->spiHandle[1]);
//SPI_setTxDelay(obj->spiHandle[1], 0x0018);
//HWREGH((obj->spiHandle[1])+SPI_O_FFCT) = 0x0018;
SPI_enableTriWire(obj->spiHandle[1]);
//SPI_enableLoopback(obj->spiHandle[1]);
SPI_clearInterruptStatus(obj->spiHandle[1], SPI_INT_TXFF);
// SPI_setFIFOInterruptLevel(obj->spiHandle[1], SPI_FIFO_TX2, SPI_FIFO_RX2);
// SPI_enableInterrupt(obj->spiHandle[1], SPI_INT_TXFF);
// Configuration complete. Enable the module.
SPI_enableModule(obj->spiHandle[1]);
while(SPI_getRxFIFOStatus(obj->spiHandle[1]))
{
char data=SPI_readDataBlockingFIFO(obj->spiHandle[1]);
}
return;
} // end of HAL_setupSPIB() function
unsigned int spi_xfer(unsigned char data)
{
//unsigned int value=data<<8;
SPI_transmitByte(halHandle->spiHandle[1], data);
while(SPI_getTxFIFOStatus(halHandle->spiHandle[1])!=SPI_FIFO_TXEMPTY);
while(SPI_getRxFIFOStatus(halHandle->spiHandle[1])!=SPI_FIFO_RXEMPTY);
unsigned char result=0;
result = SPI_readRxEmulationBuffer(halHandle->spiHandle[1]);
SPI_resetRxFIFO(halHandle->spiHandle[1]);
Delay_us(20);
return result;
}
The loopback bit is not set! when I call spi_xfer() on the physical line everything is OK!The controller is transmitting correct data, the connected device responds correctly to the command and so on. The problem is that in the SPIRX and SPIRXEMU buffers I have the transmitted data(the value is the same as SPITXBUF). It acts as the loopback mode is enabled, but I double checked the bit and it is NOT set! On the line everything is correct, but the microcontroller still copies the transmit buffer to the receive buffer and don`t read the input pin!
Any suggestiongs what is going on here?
Thanks!