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.

SPI salve interrupts TMS570LS0432

Other Parts Discussed in Thread: HALCOGEN, TMS570LS0432

 Hello everyone,

I'm using TMS570LS0432, with 5.4.00091 CCS and Halcogen 03.05.02.
What I'm tyring to achieve is make SPI2 work in slave mode with interrupts (send and receive data of fixed length uint16 type array). Thing should work in polling mode every 1s. Receive data, put it to certain array (maybe do required calculations) and send this data only when next data send occurs (after 1 second).

I'm using SPI3 as master  which sends data with "spiTransmitAndReceiveData" function, using RTI interrupts (blinking leds indicate operation of program). I initialize program and enter while(1) loop, the rest should be done in interrupts.

The code is as follows:

#include "sys_common.h"

#include "system.h"

 

/* USER CODE BEGIN (1) */

#include "spi.h"

#include "gio.h"

#include "rti.h"

 

#define length 8

 

uint16 TXbuf[length]={0};

uint16 RXbuf2[length]={0};

 

spiDAT1_t structure;

spiDAT1_t *pointer;

 

/* USER CODE END */

 

/* USER CODE BEGIN (2) */

/* USER CODE END */

 

void main(void)

{

/* USER CODE BEGIN (3) */

 

            uint32 i;

 

            pointer=&structure;

 

            for(i=0;i<length;i++)  //for filling up with initial data

            {

                         TXbuf[i]=12-i;

            }

 

            _enable_IRQ();  //initializations and enables

            gioInit();

            rtiInit();

            spiInit();

 

            rtiEnableNotification(rtiNOTIFICATION_COMPARE0);

            rtiResetCounter(rtiCOUNTER_BLOCK0);

            rtiStartCounter(rtiCOUNTER_BLOCK0);

 

            spiEnableNotification(spiREG2, spiREG2->INT0);

 

            while(1){   } // endless loop since program runs with real time timer interrupts

/* USER CODE END */

}

 

/* USER CODE BEGIN (4) */

 

void rtiNotification(uint32 notification)

{

            pointer=&structure;

            uint16 i;

 

            gioToggleBit(gioPORTA, 3); //toggling leds to see that program is running

            gioToggleBit(gioPORTA, 4);

            gioToggleBit(gioPORTA, 6);

 

            spiTransmitAndReceiveData(spiREG3, pointer, length, TXbuf, RXbuf2);

 

            for(i=0;i<length;i++)

            {

                         TXbuf[i]=length+TXbuf[i];

            }

}

 

But the program isn't jumping to interrupts.

The if I enter this line (spiREG2->DAT1=spiREG2->BUF;), before entering while(1) loop (and enter same line in "spi2HighLevelInterrupt" after initializations, before case statement), after sending data, program jumps to interrupt but only once per sending (so in case of 10 member array, I receive last member). This must be related with specific flags, but I'm not sure which ones and how.

1)I'd like to know how to make the program to receive whole array and to send whole array as a responce.

2) What is the difference between "spiTransmitAndReceiveData" and "spiSendAndGetData".

3)I'm interested just in slave mode, and master is just configured for testing purposes.

 

Regards,

Vytautas

  • Vytautas,

    Your question has been forwarded to the HALCoGen team.

    Thanks and regards,

    Zhaohong

  • Hi Vytautas,

    Attached is a simple SPI 1 ( Master) to SPI2 ( Slave) example.. Replace the sys_main.c with this file..
    I have given some comments on the HALCogen GUI configuration on top of the file, just helping you to generate file.

    6763.example_spi_Master_Slave.c

    SendAndGetData is Interrupt mode, and TransmitAndReceive is polling Mode. We want to have one common but to support legacy we support it this way.

    Regards
    Prathap

  • Hi Prathap,

    This code is very useful, now I realised, how it should be used.

    Just one more thing, could you please explain, how to change data in the middle of program (for example- I'd like to receive data with slave and store it to memory, but when next cycle of transmission occurs, to multiply past data by 2 and send back the result (or take data from another array) ). I tried doing so in while(1) loop, and the transfer buffer's  values seems to change, but master receive seems to stay the same.

     

    while(1){

    if (i==1){

     

    for (counter=0;counter<16;counter++)

    {

    TX_Data[counter]=TX_Data_Slave1[counter]; 

    }

    i=0;

    }

    else{


    for (counter=0;counter<16;counter++)

    {

    TX_Data[counter]=TX_Data_Slave[counter];

    }

    i=1;

    }

     

    P.S. Just wanted to add, will this work with taking MCU to sleep.

     

    Regards

  • Hi,

    Any news here??

     

    Regards