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.

Hercules RM42x LaunchPad Evaluation Kit SPI interfacing with gyroscope

Other Parts Discussed in Thread: HALCOGEN

Hello,
I was trying to return the output of the sensor in a printf statement without success. What was the things that I miss out or did not do correctly? I believe one of the things I need to do is to initialize the sensor similar to http://www.elecfreaks.com/wiki/index.php?title=Triple_Axis_Gyro_-_L3G4200D

I list out the things I have done in 3 parts, first is the physical connection for the hardware, second is the code for my sys_main.c, lastly is my Halcogen settings.

Thanks in advance.

Regards,

Yuanfa

====================================================================================

The Gyroscope I am using is L3G4200D>> https://www.sparkfun.com/products/10612

The physical connection I made from Launchpad to sensor breakout board was,

3.3v to VCC

GND to GND

SPI2SOMI to SDA

SPI2CS0 to CS

SPI2CLK to SCL

SPI2SIMO to SDO

============================================================

#include "sys_common.h"

#include "stdio.h"

#include "spi.h"

void main(void)

{

spiDAT1_t dataconfig1_t;

dataconfig1_t.CS_HOLD = FALSE;

dataconfig1_t.WDEL = TRUE;

dataconfig1_t.DFSEL = SPI_FMT_0;

dataconfig1_t.CSNR = 0xFE;

uint16 RX_Data_Master[16] = { 0 };

_enable_IRQ();

spiInit();

while(1){

spiGetData ( spiREG2, &dataconfig1_t, 16, RX_Data_Master);

printf("Value at p1: %f\n", *RX_Data_Master);

};

}

=========================================================

For Halcogen I enabled SP11 driver, enabled SP12 driver,enabled SP13 driver.

Under VIm Channel 0-31, Enable SPI2 Level 0 and Level 1 channels.

SPI1 TAB
 - SPI1 Global SubTAB
       - Uncheck Master Mode
       - Uncheck Internal Clock

SPI2 TAB
 - SPI2 Global SubTAB
       - check Master Mode
       - check Internal Clock

- SPI2 Port SubTAB
        - check DIR for SOMI

SPI3 TAB
 - SPI3 Global SubTAB
       - Uncheck Master Mode
      - Uncheck Internal Clock

  • Yuanfa,

    In order to use printf in your code, the following statement has to be added to your linker command file (sys_lnk.cmd):


    /* USER CODE BEGIN (4) */
        .sysmem       : {} > RAM
    /* USER CODE END */

    I've also attached a simple "Hello World" to demonstrate the usage of printf: 3247.Hello_World.zip

    Please have a try and let me know your result.

  • hi Jean-Marc,

    thanks for helping me, my printf is working fine after I import

    "stdio.h". I think the issue seems more of how I use SPI to get the output from the gyroscope.

    I am currenly trying to do something similar to http://www.elecfreaks.com/wiki/index.php?title=Triple_Axis_Gyro_-_L3G4200D to access the gyro's X Y and Z value.

     

    Regards,

    Yuanfa

  • Hi all,

    Maybe I change my question abit to help me understand. From my understanding, if I transmit 0x8F, follow by transmitting 0x00, I will get 0xD3 meaning the communication was successful. But I keep on receive 0. The code I did is below this message.

    Regards,

    Yuanfa

    =================================================================

    void main(void) {
    
    	spiDAT1_t dataconfig1_t;
    	dataconfig1_t.CS_HOLD = FALSE;
    	dataconfig1_t.WDEL    = TRUE;
    	dataconfig1_t.DFSEL   = SPI_FMT_0;
    	dataconfig1_t.CSNR    = 0xFE;
    
    	uint16 TX_Data_Master[16] = { 0x8F  };
    	uint16 TX_Data_Master2[16] = { 0x00 };
    	
    	uint16 RX_Data_Master[16] = { 0 };
    
    	_enable_IRQ();
    
    	spiInit();
    
    	spiTransmitData (spiREG2, &dataconfig1_t, 16, TX_Data_Master);
    	spiTransmitAndReceiveData(spiREG2, &dataconfig1_t, 16, TX_Data_Master2, RX_Data_Master);
    
    	printf("Value at p1: %d\n", *RX_Data_Master);
    	while (1);
    
    }

  • Yuanfa,

    Just to clarify, the real problem was the missing .sysmem statement in the linker command file.

    If this printf question is answered, could you please mark the answer as verified so we can close the thread.

    I recommend to open a new one if you have a different question.

  • Hi Jean-Marc,

    Thanks for your reply again, I did not have issue with the printf function by itself as there is an example project file in Code Composer studio for hello world. I will try to recreate a new topic.

    Have a great day! :)

    Regards,

    Yuan Fa