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.

mibspi question

Other Parts Discussed in Thread: HALCOGEN, TMS570LS0332

Hi,

I'm new to mibspi and I'm having trouble getting it going.  I've looked at an example project and read through the documentation, but I seem to be missing something.  Hopefully it is just a lack of understanding.

 

I am using CCS5.5 with the TMS570LS0332 and Halcogen 4.0.  I have an IO expander (Microchip MCP23S17) which connects through mibspi1, CS 2.  I have enabled the mibspi driver and I think I have it set up correctly in Halcogen.

Based on the datasheet for the IO expander, I need to send the 8 bit device opcode (0x40 for a read) followed by the  8 bit register address (0x12) and then my 8 bit data (0x00). 

 

The example code is

unsigned short m_data_out[8] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}; /* 8 data of 16 bit length each */
   

/* Write data to ram for transfer */
spiSetData(spiREG1,0,m_data_out); 
   
/* Enable the transfer by setting enable bit of TG0 ctrl reg to 1 */
spiTransfer(spiREG1,0);

But I don't see where the device opcode/register address is supposed to go.  Is it part of the data_out that gets set in SetData,

so my array should look like {0x40, 0x12, 0x00}?
I have tried this and it doesn't work, clearly I am doing something wrong, but I can't tell what it is.

Thanks,

David

  • David,

    Are you using the MIBSPI1 in buffer mode or standard SPI mode?

    Will it be possible to share your CCS project, including the Halcogen setup?

  • Thanks for the quick response.  I think I am running it in standard SPI mode, but I'm not sure how to tell?

     

    I have attached a zipped copy of my project.

     7776.miniCAN.zip

    I noticed that the length in the transfer group for group 2 was set to 0.  I increased this and now I see traffic on the data in line.  What are the units for this number?

     

  • David,

    The MIBSPI transmit and received buffer have to be allocated for each transfer group.

    On your device you have 128 transmit and 128 received buffer in total. Each buffer can handle up to 16 bit of data.
    The allocation is done in Halcogen by using the MIBSPI transfer Group Tab.
    For each transfer group, you have to specify the Chip Select to be use, the data format and the size.
    In the project you have share,
    TG0 is defined to work on CS_0 with 8 buffers using format 0
    All others TG have a size of 0. If you plan to use them, the size has to be defined.

    The Base Address of the transmit buffer is 0xFF0E_0000
    in this example, TG0 will use 0xFF0E_0000 to 0xFF0E_001C

    Each time a transfer is initiated, MIBSPI will send automatically all the data (buffers) allocated for the given TG.

    The mibspisetdata routine takes care of copying the data from your main memory to the corresponding buffer allocated for the TG in use. In mibspisetdata the number of buffer is check and if the size is 0, nothing is done.

    Please let me know if this clarify the situation.

  • Thanks for the info, it helps a lot. 

     

  • David,

    By the way, you are using the MIBSPI in Multi buffer mode.
    This is done in Halcogen when you check the box: Enable MIBSPI driver in the driver enable tab.

  • If I just need to run it in standard spi mode, after selecting SPI1 from the driver tab and pinmux tab, do I use the configuration under SPI1 and use the functions in spi.c and not MIBSPI1 (and mibspi.c)?

    Are there any example projects that use it as a standard spi?

  • Yes,

    In spi mode, you have to use spi.c.
    The concept is similar to mibspi mode.

    Here is a main code using SPI driver:

    /* USER CODE BEGIN (2) */
    uint16 TX_Data_Master[16] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10 };
    uint16 RX_Data_Master[16] = { 0 };
    /* USER CODE END */

    void main(void)
    {
    /* USER CODE BEGIN (3) */
        spiDAT1_t dataconfig1_t;

        dataconfig1_t.CS_HOLD = FALSE;
        dataconfig1_t.WDEL    = TRUE;
        dataconfig1_t.DFSEL   = SPI_FMT_0;
        dataconfig1_t.CSNR    = 0xFE;


        /* Enable CPU Interrupt through CPSR */
        _enable_IRQ();
        spiInit();
        spiEnableLoopback(spiREG1,Analog_Lbk);
        /* Initiate SPI2 Transmit and Receive through Interrupt Mode */
        spiSendAndGetData(spiREG1, &dataconfig1_t, 16, TX_Data_Master,RX_Data_Master);
        while(1)
        {
        }
    /* USER CODE END */

    dataconfig1_t is used to specify some attribute to your configuration.

        dataconfig1_t.CS_HOLD = FALSE;                                // CS is deasserted in between each transmitted data
        dataconfig1_t.WDEL    = TRUE;
        dataconfig1_t.DFSEL   = SPI_FMT_0;                           // Specify the data format
        dataconfig1_t.CSNR    = 0xFE;                                        // Specify which CS to be used. In this case, CS0 will be
                                                                                                       // active low during data transmission, all other CS will be 1

    If interrupt are not used, (in this case) the CPU will execute the spiSendAndGetData routine until completion.
    The number of data to be transmitted and received in this case is 16. The source and destination buffer are also provided as argument.

  • Hi,

    Sorry for all the spi questions.  I thought this would be easy to set up but I am having a difficult time doing so.

     

    I need to clock out 24 bits of data.  I can set this in Halcogen for data format 0 to have a charlen of 24, and I get the right number of clock pulses.  I don't know how to give the data to the spiTransmitData function though.  It is looking for a pointer to 16 bit values.  Do I need to pad my data to get it to a length that is a multiple of 16?

    Also, I'm not sure if it is a bug or not, but setting the charlen produces 16 clock pulses, a charlen of 24 produces 24 clock pulses.  A charlen of 32 however produces 64 clock pulses.

     

    I currently only see 16 bits on the data in line.  My chip select and clock pulses are OK, but I can't figure out how to have it clock out all of the data I need.

     

    Thanks

  • Hi,

    I was able to get it working.  I set the char length to 16 and hold the CS between transfers, putting 2 16 bit entries in my array. 

     

    Thanks