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.

TMS470MF06607: SPI receive function

Part Number: TMS470MF06607
Other Parts Discussed in Thread: HALCOGEN

Hi,

i am using TMS470mf06607 microcontroller.

i want to develop the SPI communication in my microcontroller.

i developed my code for transmit the data using the example code.

i enabled the Tx interrupt also in Halcogen code generator.

i know for receive the data from the other device i want to use the following function.             (  uint32 spiGetData(spiBASE_t *spi, uint32 group, uint16 * data);    )

but can any one please suggest me where and how i want to use this function. i dont know i want to use in main function only or in notification.c   .

any suggest me how i want to receive the data through the SPI.

Thanks & Regards

Arun Kumar.N 

  • You can put the call in either place. If your main function is not likely to be able to read the data before the receive FIFO is full, then you should read and buffer the data from the interrupt routine (notification.c).
  • Hi Sir,

    I am trying to use this receive function in the main function itself. but the data is not received.
    I am trying to transmit from the another microcontroller.
    I put my main function in the below. if any suggestion means kindly let me know.
    I enabled the TX interrupt from the halcogen also.
    And in the notification file its always true in case0 only.


    program:
    #include "sys_common.h"
    #include "system.h"
    #include "spi.h"

    uint32_t TG3_IS_Complete;

    uint16 TG0_TX_DATA[8] = {11,22,33,44,55,66,77,1};
    uint16 TG0_RX_DATA[8]= {0};

    uint16 TG1_TX_DATA[8] = {0x2000, 0x2111, 0x2222, 0x2333, 0x2444, 0x2555, 0x2666, 0x2777};
    uint16 TG1_RX_DATA[8]= {0};

    uint16 TG2_TX_DATA[8] = {0x3000, 0x3111, 0x3222, 0x3333, 0x3444, 0x3555, 0x3666, 0x3777};
    uint16 TG2_RX_DATA[8]= {0};

    uint16 TG3_TX_DATA[8] = {0x4000, 0x4111, 0x4222, 0x4333, 0x4444, 0x4555, 0x4666, 0x4777};
    uint16 TG3_RX_DATA[8]= {0};

    int delay_count = 0;

    void main(void)
    {
    /* USER CODE BEGIN (3) */

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

    /* Initialize SPI Module Based on GUI configuration
    * SPI1 - Master ( SIMO, SOMI, CLK, CS0 ) * */
    spiInit();



    /* Enable TG 0, 1, 2, 3 complete interrupt to INT 0 */
    spiEnableGroupNotification(spiREG1,0,0);
    spiEnableGroupNotification(spiREG1,1,0);
    spiEnableGroupNotification(spiREG1,2,0);
    spiEnableGroupNotification(spiREG1,3,0);

    /* Fill the transfer Groups */
    spiSetData(spiREG1,0,TG0_TX_DATA);


    /* Enable TG0 to start, once tickCNT triggers */
    while(1)
    {
    spiTransfer(spiREG1,0);

    while(TG3_IS_Complete != 0xA5A5A5A5);
    spiGetData(spiREG1, 1, TG0_RX_DATA);
    }

    }

    void spiGroupNotification(spiBASE_t *spi, uint32 group)
    {
    /* enter user code between the USER CODE BEGIN and USER CODE END. */
    /* USER CODE BEGIN (21) */
    switch (group)
    {
    case 0 :
    /* Enable TG1 to start, SW Trigger */
    spiTransfer(spiREG1,0);
    break;
    case 1 : /* Enable TG1 to start, SW Trigger */
    spiTransfer(spiREG1,2);
    break;
    case 2 : /* Enable TG1 to start, SW Trigger */
    spiTransfer(spiREG1,3);
    break;
    case 3 :
    TG3_IS_Complete = 0xA5A5A5A5;
    break;
    default :
    while(1);
    break;
    }

    /* USER CODE END */
    }



    regards
    Arun
  • A few suggestions. If you set TG3_IS_Complete in the interrupt routine, but poll it in main, it needs to be declared volatile.

    volatile uint32_t TG3_IS_Complete;
    

    Then do your main while loop like this:

    	while(1)
    	{
    	    TG3_IS_Complete = 0;
    	    /* Enable TG0 to start, once tickCNT triggers */
    	    spiTransfer(spiREG1,0);
    
    	    while(TG3_IS_Complete != 0xA5A5A5A5); // Wait here 
    	    spiGetData(spiREG1, 0, TG0_RX_DATA);
    
    	}
    

    I tried this code just shorting the SPI1SIMO pin to the SPI1SOMI pin and saw the TX data copied into the RX buffer.