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.

BOOSTXL-SENSHUB

Other Parts Discussed in Thread: HALCOGEN

Is sensorhub compatible with AVR atmega 640?I m giving 4 connections at present to my AVR!

3.3 v

gnd

sda

scl

Are This sufficient ? Problem with my present code is that all sensor reading registers are giving zero reading!!!

Also what should value of power management1 register?

Please Reply Fast???

  • Hello Akshay,

    This question would be best answered by the Tiva Microcontrollers forum, and I have moved this post over for best support.

    Thanks and Best Regards,

    Wen-Shin Wang

  • akshay desai said:
    Is sensorhub compatible with AVR atmega 640?

    Fact in evidence suggests that "brand A" forum may also be wise destination...

  • Hi,

    3.3V GND SDA SCL pins are sufficient to interface with the i2c sensors!

    I have this setup up running with Hercules RM48 MCU.

    To read out MPU9150 register values you have to write 0x00 to Power Management 1 (0x6B) to clear the SLEEP mode (device is in SLEEP mode after power on event and after device reset).

    Regards,

    Matthias

  • Thanks Matthias,

    I am trying that all.But i am still having some problems.First i had I2C hang up problem but now i solved that after taking acknowledgement signals.Now i am reading the xyz data registers of gyroscope but it is reading zero.

    I am not using interrupt right now just polling.

    My code is as shown below:

    void mpu9150_write(uint8_t register_address,uint8_t data)
    {
    I2C_SendStart();
    I2C_SendAddress(mpu9150address+write);
    I2C_SendData(register_address);
    I2C_SendData(data);
    I2C_SendStop();
    }

    //< Need to initialize I2C Master first before sensor_init >//

    void sensor_init(void)
    {

    mpu9150_write(power_management1_reg,0);
    mpu9150_write(sampleratedivider_reg,0);
    mpu9150_write(gyro_config_reg,0);
    mpu9150_write(acc_config_reg,0);
    mpu9150_write(Fifoenable_reg,0);
    mpu9150_write(i2c_master_control_reg,0);
    mpu9150_write(int_bypass_config_reg,0);
    mpu9150_write(Interruptenable_reg,0);
    mpu9150_write(signalpath_reset_reg,0);
    mpu9150_write(usercontrol_reg,0);
    mpu9150_write(power_management2_reg,0);

    }

    void raw_gyro_data(void)
    {


    I2C_SendStart();
    I2C_SendAddress(mpu9150address+write); //< Main Slave Address

    I2C_SendData(67+write);      // 67 is starting address of gyroscope

     _delay_us(25);          // for sending repeated start need a little delay

    I2C_SendRepeatedStart();
    I2C_SendAddress(mpu9150address+read); //< Main Slave Address



    g[0]=I2C_ReadData(I2C_READ_NOT_LAST_DATA); //< Xacceleration High Byte
    g[1]=I2C_ReadData(I2C_READ_NOT_LAST_DATA); //< Xacceleration low Byte
    g[2]=I2C_ReadData(I2C_READ_NOT_LAST_DATA); //< Yacceleration High Byte
    g[3]=I2C_ReadData(I2C_READ_NOT_LAST_DATA); //< Yacceleration low Byte
    g[4]=I2C_ReadData(I2C_READ_NOT_LAST_DATA); //< Zacceleration High Byte
    g[5]=I2C_ReadData(I2C_READ_LAST_DATA); //< Zacceleration low Byte

    I2C_SendStop();


    /*** for x axis data ***/


    rawdata.Gx =(int) (g[0] << 8) | g[1];

    /*** for y axis data ***/

    rawdata.Gy=(int) (g[2] << 8) | g[3];

    /*** for z axis data ***/

     rawdata.Gz = (int)(g[4] << 8) | g[5];

    }

     My I2C read function is as shown below:

    unsigned char I2C_ReadData(unsigned char status)
    {
    unsigned recv_data;

    if(status) //< true if last data is read
    {
    TWCR=(1<<TWINT)|(1<<TWEN); //< Clear TWI interrupt flag,Enable TWI,Enable NACK
    while (!(TWCR & (1<<TWINT))); //< Wait till complete TWDR byte transmitted
    while(I2C_status != 0x58); //< Check for the acknowledgment
    recv_data=TWDR;
    }
    else //< true if we want to read more data
    {
    TWCR=(1<<TWINT)|(1<<TWEN)|(1<<TWEA); //< Clear TWI interrupt flag,Enable TWI,Enable ACK
    while (!(TWCR & (1<<TWINT))); //< Wait till complete TWDR byte transmitted
    while(I2C_status != 0x50); //< Check for the acknowledgment
    recv_data=TWDR;
    }
    return recv_data;
    }

    My Main.C file code:

    int main(void)
    {
    _delay_ms(100);
    lcd_mega_Initialize();
    I2C_InitMaster();
    sensor_init();

    while(1)
    {

    raw_acc_data();

    // Printing data on LCD

    lcd_mega_gotoxy1(0);
    lcd_mega_Showvalue(rawdata.Ax);
    lcd_mega_gotoxy1(4);
    lcd_mega_Showvalue(rawdata.Ay);
    lcd_mega_gotoxy1(8);
    lcd_mega_Showvalue(rawdata.Az);
    }
    }

    Waiting For Reply.I am not getting what is the problem in the code.

  • Hi,

    please find my example code below (RM48 HALCOGEN generated functions for hercules):

    //initialization

    mpu9150state.ID = MPU9150_ReadReg(0x75);

    //perform reset

    MPU9150_WriteReg(0x6B, 0x00);

    delay(25ms)

    //Setup sensorconfiguration

    MPU9150_WriteReg(0x1A, 0x2);

    delay(10ms)

    MPU9150_WriteReg(0x1B, 0x00);

    MPU9150_WriteReg(0x1C, 0x01);

    MPU9150_WriteReg(0x37, 0xB0);

    MPU9150_WriteReg(0x38, 0x01);

     

    // somewhere in main:

    mpu9150state.temptemp = MPU9150_ReadReg(0x41) << 8 | (MPU9150_ReadReg(0x42) & 0xFF);

    mpu9150state.temperature = mpu9150state.temptemp/340.0f + 35.0f;

    mpu9150state.tempaccelx = MPU9150_ReadReg(0x3B) << 8 | (MPU9150_ReadReg(0x3C) & 0xFF);

    mpu9150state.accelx = (float) mpu9150state.tempaccelx/16384.0f;

    and so on....

    //

    uint8 MPU9150_ReadReg(uint8addr) {

    uint8 data;

    //Wait until I2C is not busy

    while (i2cREG1->STR & I2C_BUSBUSY);

    //Ensure that I2C master mode is cleared

    while (i2cREG1->MDR & I2C_MASTER);

    /* set I2C slave address */

    i2cSetSlaveAdd(i2cREG1, mpu9150state.I2Caddress);

    i2cClearSCD(i2cREG1);

    i2cREG1->MDR |= I2C_MASTER;

    /* Initiate Start condition for Transmission */

    i2cSetStart(i2cREG1);

    i2cSendByte(i2cREG1, addr);

    /* Wait until data is sent */

    while (i2cIsTxReady(i2cREG1) == 0);

    i2cREG1->MDR &= ~I2C_TRANSMITTER; //Clear TRX bit to set as receiver

    while (i2cREG1->MDR & I2C_TRANSMITTER);

    /* ReStart */

    i2cREG1->DRR;

    i2cSetStart(i2cREG1);

    i2cREG1->MDR |= I2C_NACK_MODE; //set NACKMOD bit

    data = i2cReceiveByte(i2cREG1);

    i2cSetStop(i2cREG1);

    return data;

    }

     

    Hope this helps...

    Regards

    Matthias

  • Thanks,

    But do we need to bring mpu9150 out of sleep mode everytime we are reading sensor data registers??

  • I never got another response than 0, performing register reads while SLEEP mode enabled.

  • Thanks Matthias,

    I am assigning  powermanagement register1 a zero value and bringing out of sleep mode in sensor init function.

    so i hav to write to this register everytime i read gyro data?? 

  • No, not before every read!

    The MPU9150 default state is SLEEP, after power on event and reset.

    So you have to disable Sleep mode within your initialization code, to be able to configure the sensor and communicate.

    Please refer to the MPU9150 datasheet for additional information.

  • Thanks Matthias,

    So I am doing that only but it still reads zero.check out my code below for avr atmega640:

    void sensor_init(void)
    {

    mpu9150_write(power_management1_reg,0);
    mpu9150_write(sampleratedivider_reg,0);
    mpu9150_write(gyro_config_reg,0);
    mpu9150_write(acc_config_reg,0);
    mpu9150_write(Fifoenable_reg,0);
    mpu9150_write(i2c_master_control_reg,0);
    mpu9150_write(int_bypass_config_reg,0);
    mpu9150_write(Interruptenable_reg,0);
    mpu9150_write(signalpath_reset_reg,0);
    mpu9150_write(usercontrol_reg,0);
    mpu9150_write(power_management2_reg,0);

    }

    void raw_gyro_data(void)
    {


    I2C_SendStart();
    I2C_SendAddress(mpu9150address+write); //< Main Slave Address

    I2C_SendData(67+write);      // 67 is starting address of gyroscope

     _delay_us(25);          // for sending repeated start need a little delay

    I2C_SendRepeatedStart();
    I2C_SendAddress(mpu9150address+read); //< Main Slave Address



    g[0]=I2C_ReadData(I2C_READ_NOT_LAST_DATA); //< Xacceleration High Byte
    g[1]=I2C_ReadData(I2C_READ_NOT_LAST_DATA); //< Xacceleration low Byte
    g[2]=I2C_ReadData(I2C_READ_NOT_LAST_DATA); //< Yacceleration High Byte
    g[3]=I2C_ReadData(I2C_READ_NOT_LAST_DATA); //< Yacceleration low Byte
    g[4]=I2C_ReadData(I2C_READ_NOT_LAST_DATA); //< Zacceleration High Byte
    g[5]=I2C_ReadData(I2C_READ_LAST_DATA); //< Zacceleration low Byte

    I2C_SendStop();


    /*** for x axis data ***/


    rawdata.Gx =(int) (g[0] << 8) | g[1];

    /*** for y axis data ***/

    rawdata.Gy=(int) (g[2] << 8) | g[3];

    /*** for z axis data ***/

     rawdata.Gz = (int)(g[4] << 8) | g[5];

    }

  • akshay desai said:
    .check out my code below for avr atmega640:

    And surely - w/in AVR-Land - a Stellaris/rebrand poster awaits support...  (or not!)

    Inappropriateness of this ongoing back-forth was far earlier identified/posted.  And rebrand posts sit unanswered...

  • Not clear!!Can u Please Elaborate?

  • This forum - (Tiva ARM MCUs) exists to aid/abet such users.

    Your use/interest is outside this focus - and as pertinent and appropriate issues remain unsolved - seems improper to dilute a limited resource.

    Vendor poster has "bent the rules" in your behalf - hate to see already reduced vendor presence futher diluted...

    Other vendor's forum/support - far more suitable for your clearly, Non Tiva support...

  • But i am talking about sensorhub.

  • akshay desai said:
    .check out my code below for avr atmega640:

    Facts earlier in evidence (above) are far outside proper bounds for this vendor's MCU forum.

    This is not a "booster forum" - and movement in that direction will predictably result in reduced MCU aid/comfort.

    Reasoning by extension - should not then this forum extend to support any/all "accessory boards" - ever produced?  And - offer tech aid/comfort/quick & full support for an unlimited number of competing MCU vendors?  (Recall - poster's order: "Please Reply Fast!" (solve his AVR code issue)   on what planet - my friend?)

    This  is a slippery/dangerous slope (broken bodies/further horrors below) - and should be resisted/repelled... 

    Tacit encouragement (displayed here - in multiple) clearly outside, "best/proper" use of a valued (yet limited) resource...  Unintended (& under-examined) consequence of such, "forum expansion" leads to nightmare (foreign MCU invasion) scenario - deserves at least some guideline/safeguard...

  • Are there any chances of sensors to get damaged,if i give 5V to them ????