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.

CC3200-LAUNCHXL - Getting values with SPITransfer

Other Parts Discussed in Thread: CC3200-LAUNCHXL, CC3200

Hi,

I am currently having trouble whith getting values of registers with SPITransfer.

I am using a CC3200-LAUNCHXL, and the sensor i am trying to use is an LSM9DS0.

I began from a code that was working, which used an other sensor (ADXL362). This code was adapted from the SPI demo, and was working well when trying to read/write the registers.

The only things i changed are adresses of the registers (obviously), and the protocol in the functions readSPI and WriteSPI, because they needed two bytes to give instructions (read/write+adress) for the ADXL instead of 1 for the LSM9DS0.

Unfortunately, i wasn't able to get the values of the registers anymore. When I looked at the signals with an oscilloscope, I saw that everything worked as it was supposed too, the instructions were given to the sensor and it answers the good values.

For example, I tried to read the WHO_AM_I register, and i saw the good value with the oscilloscope (0b01001001), but the value i get from SPITransfer in the code is 0b00000111.

The same problem occurs for every register.

Here are some parts of my code :

//
    // Reset SPI
    //
    MAP_SPIReset(GSPI_BASE);

    //
    // Configure SPI interface
    //
    MAP_SPIConfigSetExpClk(GSPI_BASE,MAP_PRCMPeripheralClockGet(PRCM_GSPI),
                     SPI_IF_BIT_RATE,SPI_MODE_MASTER,SPI_SUB_MODE_0,
                     (SPI_SW_CTRL_CS |
                     SPI_4PIN_MODE |
                     SPI_TURBO_OFF |
                     SPI_CS_ACTIVELOW |
                     SPI_WL_8));

    //
    // Enable SPI for communication
    //
    MAP_SPIEnable(GSPI_BASE);

    unsigned char buffer;

    buffer=readSPI(LSM9DS0_REGISTER_WHO_AM_I_XM,XMTYPE);

And here is my function readSPI :

unsigned char readSPI(unsigned char OFFSET, unsigned int choix_capteur)
{
	int iRetVal=1;
	unsigned char RESULT;

	unsigned char addr=(OFFSET|0x80)&0xBF;

	MAP_SPICSEnable(GSPI_BASE);
	int i=0;
	for (i=0;i<2000;i++){}
	iRetVal = iRetVal + MAP_SPITransfer(GSPI_BASE, &addr, 0, 1,  0);//write command
	for (i=0;i<2000;i++){}
	iRetVal = iRetVal + MAP_SPITransfer(GSPI_BASE, 0, &RESULT, 1,  0);//read command
	if (iRetVal<0){
		Message("Erreur readSPI");
	}
	else{
		Report ("offset 0x%x (in readSPI) => 0x%x\n\r",OFFSET,RESULT);
	}
	MAP_SPICSDisable(GSPI_BASE);
	return RESULT;
}

The parameter choix_capteur is not implemented yet, so it has no effect on the code. It will be useful later because the sensor has two SDO pins and two CS pins, each for a set of sensors.

I checked the hardware many times, so I guess the problem does not come from that ; and if yes, the oscilloscope would give me false values.

So,

- The sensor seems to work well, the signals are what they are supposed to be with the oscilloscope

- The values got with the function readSPI are wrong

Any piece of advice is appreciated :)

I guess i did not give all useful informations I could, so ask if you need some more.

Thank you for helping !

 

  • Hi Gwendal,

    It looks like you have SPI set to active when CS is low, but you enable CS before you read the SPI. Is there is mistake there?

    If not, can you share which hardware pins you are using for SPI and your pinmux configuration code?

    Best regards,
    Sarah
  • Hi Sarah,

    Ther is no problem with the CS_enable, because it sets the signal to low. Moreover, the sensor seems to give correct answers with the oscilloscope.

    Here is my pinmux configuration code : 

    void
    PinMuxConfig(void)
    {
        //
        // Enable Peripheral Clocks 
        //
        MAP_PRCMPeripheralClkEnable(PRCM_UARTA0, PRCM_RUN_MODE_CLK);
        MAP_PRCMPeripheralClkEnable(PRCM_GSPI, PRCM_RUN_MODE_CLK);
    
        //
        // Configure PIN_55 for UART0 UART0_TX
        //
        MAP_PinTypeUART(PIN_55, PIN_MODE_3);
    
        //
        // Configure PIN_57 for UART0 UART0_RX
        //
        MAP_PinTypeUART(PIN_57, PIN_MODE_3);
    
        //
        // Configure PIN_08 for SPI0 GSPI_CS
        //
        PinTypeSPI(PIN_08, PIN_MODE_7);
    
        //
        // Configure PIN_05 for SPI0 GSPI_CLK
        //
        PinTypeSPI(PIN_05, PIN_MODE_7);
    
        //
        // Configure PIN_06 for SPI0 GSPI_MISO
        //
        PinTypeSPI(PIN_06, PIN_MODE_7);
    
        //
        // Configure PIN_07 for SPI0 GSPI_MOSI
        //
        PinTypeSPI(PIN_07, PIN_MODE_7);
    }

    Thank you,

    Gwendal

  • Hi Gwendal,

    You config your SPI to expect an word length of 8, but you are only reading one byte. SPITransfer expects a multiple of this word length. Please try reading more than one byte. See below from spi.c implementation.

    //! This function transfers \e ulCount bytes of data over SPI channel. Since
    //! the API sends a SPI word at a time \e ulCount should be a multiple of
    //! word length set using SPIConfigSetExpClk().

    If you have two LaunchPads, please test your functions to communicate between these so you debug the send and read functions together.

    Best regards,
    Sarah
  • Hi Gwendal,

    Were you able to resolve your issue?

    Best regards,
    Sarah
  • Hi Sarah,

    Unfortunately I had a lot of hardware problems, and I did not find time to solve this problem.
    Be sure that as soon as i can try your solution, i'll report it here !

    Best regards,
    Gwendal
  • Back to soft problems now, i bought a device in order to be able to see the signals between the sensor and the cc3200.

    I want to read a specific register, which is an ID register, the value is supposed to be 0x49.

    When I launch the read, here is what i can see :

    The sensor seems to answer correctly, although I still get a false value in Code Composer (0x07).

    I tried reading and writing in different registers, I can see that the sensor always acts as it is supposed to, but I can't get them.

    I also tried to write a for loop between the write and read instructions inside the frame (i thought about a timing problem), but it doesn't change anything.

    I checked once again the pinmux configuration, but everything is ok.

    Any new idea ?

    Gwendal

  • Hi Gwendal,

    Were you able to try the last suggestion from April 7th? To update the length of the data you are receiving?

    Best regards,
    Sarah
  • Hi Sarah,

    I replaced

    iRetVal = iRetVal + MAP_SPITransfer(GSPI_BASE, 0, &RESULT, 1,  0);//read command

    by

    iRetVal = iRetVal + MAP_SPITransfer(GSPI_BASE, 0, &RESULT, 8,  0);//read command

    in order to read 8 bytes, and here is what I get :

    We can see that we get the correct value 8 times, but I still get 0x07 in Code Composer.

    Something else that could be interesting is that I get different values for other registers, i.e. 0xFF instead of 0x67, 0x3F instead of 0x03, 0xFF instead of 0x0F, 0x00 instead of 0xF0 ... which are not particular values, so I guess the code reads something that is not random, but what ?

    As I have currently no more idea, I'll try to communicate with I2C, maybe the results could help ...

    Don't hesitate to ask for more screenshots with different parameters !

    Best regards,

    Gwendal Hays

  • I have just tried to modify the pinmux.c like this :

        //
        // Configure PIN_08 for SPI0 GSPI_CS
        //
        PinTypeSPI(PIN_08, PIN_MODE_7);
    
        //
        // Configure PIN_05 for SPI0 GSPI_CLK
        //
        PinTypeSPI(PIN_05, PIN_MODE_7);
    
        //
        // Configure PIN_06 for SPI0 GSPI_MISO
        //
        PinTypeSPI(PIN_06, PIN_MODE_0);
    
        //
        // Configure PIN_07 for SPI0 GSPI_MOSI
        //
        PinTypeSPI(PIN_07, PIN_MODE_7);

    to check if the CC3200 receives something.

    I get 0x00, which is normal because the MISO line is kept low by GPIO. Maybe this information can help ...

  • The sensor has 2 CS pins and 2 MISO pins, one of them for gyro data and the other for accel and mag data.

    Some register adresses are shared by those sets of pins, e.g. the Who_am_I register i'm trying to read.

    Like I said, for the accel/mag part, I get 0x07 instead of 0x49 (expected value, which can be read with the anlyser), but with the same code (just changing hardware connections) I get 0xC0 instead of 0xD4 (expected value).

    We can conclude that the problem does not come from the command, because for the same command I get 2 different values.
  • Hi Gwendal,

    Have you tried flashing the application to the CC3200 and printing out the values you get to a terminal? It may be helpful to check against CCS debug mode.

    Best regards,
    Sarah
  • Hi Sarah,

    I have just tried to do what you said, but unfortunately I get the same false values.

    Best regards,

    Gwendal
  • BTW, as I'm working on similar problems: Which device did you buy? And would you recommend it?

  • The sensor is LSM9DS0, for the tests I bought this board : learn.adafruit.com/.../overview
    With an Arduino, I had no problem to get the different values, and the precision seems to be good, although not perfect.

    I may be able to tell you more when my device will be ready, the program I have developped will be tested.
  • I finally got my device, and everything is working perfectly. I still have no clue why it does not work with the sensor and the CC3200 separately, I didn't change anything in the code. Probably some components around the sensor were causing trouble.