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.

C6748 Starterware Driver for SPI issue

Hello,

I am a new user of the C6748 StarterWare libraries, and I have just stated using some libraries to test a custom board.
I have done a lot of reading so as to undertand well the StarterWare structure.


When I want to configure a generic format for the SPI peripheral, I came across with a configuration that I do not understand well, and it makes me think there is an issue in the {StarterwareRoot}/Drivers/spi.c driver.

The function SPIDat1Config says that the parameter  "cs is the value to driven on CS pin(line)."

Similarly, the function SPIDefaultCSSet says "dcsval  is the value written to SPIDEF register to set default value on CS pin(line)".

Thus, my understanding is that if I want to configure a negative active CS pulse when sending a single message, I should configure cs=0, and dcs=1. The reference manual SPRUH79A seems to corroborate that idea (registers SPIDAT1 and SPIDEF)

However, I do not get that behaviour. Then, I realized in the fucntion SPIDat1Config in spi.c, it read:

*(ptr+2) = cs ^ dcs;

I think to have seen corroborated that the XOR function really change the behaviour to what I think is not correct. I sould have expected simply:

*(ptr+2) = cs;

ptr points to the lower bytre of the register SPIDAT1, and "dcs" is the reading of the lower byte of the register SPIDEF.

What I wonder is, is that a "characteristic" of the fucntion that must be interpreted with another logic of working that i do not understand? or is it a bug?.

At least for me, like it is currently makes no sense. By the way, I am using the las versión available  C6748_StarterWare_1_20_04_01

http://software-dl.ti.com/dsps/dsps_public_sw/c6000/starterware/01_20_04_01/index_FDS.html

I hope to made myself undertood.


Gonzalo.

  • Some guesses.

    SPIDefaultCSSet(unsigned int baseAdd, unsigned char dcsval)
    The dcsval parameter is the logic level to put on the CS lines when idle, 0=low, 1=high. Value is saved in SPI_SPIDEF.CSDEF.

    SPIDat1Config(unsigned int baseAdd, unsigned int flag, unsigned char cs)
    cs is the assert pattern to put on the CS lines when active, 0=deassert, 1=assert.
    The code in SPIDat1Config() writes a value to the SPIDAT1.CSNR field. That value is the logic level not the assert pattern passed. The XOR is used to calculate the logic level from the assert pattern and SPI_SPIDEF.CSDEF. Ensures that if SPI_SPIDEF.CSDEF is 1 then SPIDAT1.CSNR wil be 0 and  if SPI_SPIDEF.CSDEF is 0 then SPIDAT1.CSNR wil be 1.

    It is assumed that SPIDefaultCSSet() is called before SPIDat1Config().

    I think the designers of StarterWare wanted to allow the same value to be used for dcsval and cs.

  • Thank you for you answer, Norman.


    I have thought in such a way of behaviour, but it still has some details. To start with, it still would be confusing.

    If the same value is writen in cs and dcs, 0 will not do a change in CS line.

    What could makes sense, I guess would be something like

    cs: enables the assertion

    dcs: gives the logic, 0 for an assertion with 1, 1 for an assertion with 0

    cs | dcs | SPIDAT1.CSNR

    0     0    0

    0     1    1

    1     0    1

    1     1    0

    Transition from default to master data transfer

    Unfortunately, that is not what all comments arounds says.

    I have not checked yet, but the CSHOLD bit must affect on the behaviour logic, since it says to hold the active state between frames.


    Gonzalo.

     

  • The comments are probably a cut'n'paste error. Documentation is not a StarterWare strong point. Your truth table is correct. When you look at an individual CS line, the table looks needlessly complicated. It would have been simpler to use just assign a negated dcsval to SPIDAT1.CSNR. However, it seems to make more sense when you look at the entire group of CS lines. More guesses here. Here's how I used the SPI library. Let's say you you want to set the default level of all CS lines to high and you wanted to use just one CS line 3. Then
    dcsval = 0xFF -> SPIDEF.CSDEF = 0xFF
    cs = 0x08 = 1<<3 -> SPIDAT1.CSNR = 0xF7
    All CS lines other than line 3 will have a fixed CS value of high. As you have stated no change in CS line. That's what is probably what should happen on channels where CS is not used or the channel is not used at all.
  • Thanks you Norman for your answer.

    It is disapointing that commento on the source code are not a good reference.

    At least, what you have suggested as a way of using the driver makes sense.


    (I had no time to progress on my project, so I am sorry for my delayed answer)

    Gonzalo.