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.

TMS570LS0432: TMS570 SPI1 in interrupt mode

Part Number: TMS570LS0432
Other Parts Discussed in Thread: HALCOGEN

Hello,
I am using TMS57004 Launchpad. Current I am working on SPI communication. For that I have gone through Halcogen example. I want to use SPI1 in normal (not in Mibspi) mode(MASTER mode) using interrupt method.
For SPI1 interrupt method I have set all the parameter as you have mentioned in example for SPI2 slave.
After all setting when I execute the


spiSendAndGetData(spiREG1,&dataconfig1_t,2 TX_Data_Master,Rx_Data_Master)
where uint8 Tx_Data_Master[2]={0x44,0xAA); Rx_Data_Master[2]={0};

I receive only second byte correctly and  first byte as all one. So, could you any one tell is there any wrong in my configuration.
Below is my sample code:
Int main(void)
{
spiDAT1_t dataconfig1_t;

dataconfig1_t.CS_HOLD = TRUE;
dataconfig1_t.WDEL = TRUE;
dataconfig1_t.DFSEL = SPI_FMT_1;
dataconfig1_t.CSNR = 0xFC;

/* Enable CPU Interrupt through CPSR */
_enable_IRQ();

spiInit();
while(1)
{
spiSendAndGetData(spiREG1,&dataconfig1_t,2 TX_Data_Master,Rx_Data_Master);
}
return 0;
}


void spiSendAndGetData(spiBASE_t *spi, spiDAT1_t *dataconfig_t, uint32 blocksize, uint8 * srcbuff, uint8* destbuff)
{

/* USER CODE BEGIN (17) */
/* USER CODE END */

uint32 index = spi == spiREG1 ? 0U :(spi==spiREG2 ? 1U : 2U);

g_spiPacket_t[index].tx_length = blocksize;
g_spiPacket_t[index].rx_length = blocksize;
g_spiPacket_t[index].txdata_ptr = srcbuff;
g_spiPacket_t[index].rxdata_ptr = destbuff;
g_spiPacket_t[index].g_spiDataFormat = *dataconfig_t;
g_spiPacket_t[index].tx_data_status = SPI_PENDING;
g_spiPacket_t[index].rx_data_status = SPI_PENDING;

spi->INT0 |= 0x0300U;

/* USER CODE BEGIN (18) */
/* USER CODE END */
}
static volatile struct g_spiPacket
{
spiDAT1_t g_spiDataFormat;
uint32 tx_length;
uint32 rx_length;
// uint16 * txdata_ptr;
// uint16 * rxdata_ptr;
uint8 * txdata_ptr;
uint8 * rxdata_ptr;
SpiDataStatus_t tx_data_status;
SpiDataStatus_t rx_data_status;
} g_spiPacket_t[3U];

Thanx in Advance..

  • Hello Sameer,

    Have you checked what is clocked into the device on the RX line during the first transmission? Are you certain the external device is ready when the first transmit is initiated? I would surmise that this may be an issue if the first received wrong data but the second does not.  What is the relevance of the highlighted changes in your code above? Also, it appears as though you are using polling mode to send and receive data. How do you utilize the interrupt for SPI in this case?

    If you wish to truly use Interrupt mode, I would recommend using the spiTransmit function and then setting up the receive an interrupt to process the received data and initiate the next transmission if additional data is to be sent.

    If you continue to use the current method, you should insure the receive is completed without error before proceeding with the next transmit.