CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

AHRS BNO055(gy-955) read

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
hamid9543



Joined: 31 Jan 2013
Posts: 63

View user's profile Send private message

AHRS BNO055(gy-955) read
PostPosted: Thu Jul 21, 2022 9:16 am     Reply with quote

My code to reading the z-Euler angle from AHRS bno055 is as follows, but only 0.00 is printed.
i tested code in arduino uno and it works correctly!

Code:

#include <16F1937.h>
#use delay(internal=32MHz)
#use i2c(Master,Fast=400000,sda=PIN_C4,scl=PIN_C3,force_hw)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=PORT1)

#define BNO055 0x52
float Yaw=0;

unsigned int8 status;
unsigned int8 get_ack_status(unsigned int8 address)
{
   unsigned int8 status;
   
   i2c_start();
   status = i2c_write(address);
   i2c_stop();
   
   if(status==0)  return(TRUE);
   else           return(FALSE);
}

void Search_i2c()
{
   printf("\n\rStart:\n\r");
   delay_ms(1000);
   unsigned int8 count = 0;
   for(unsigned int8 i=0x10; i < 0xF0; i+=2)
   {
    status = get_ack_status(i);
    if(status == TRUE)
      { 
         printf("Addr:%X\n\r",i);
         count++;
         delay_ms(500);
      }
   }
   if(count == 0)  printf("Nothing Found\n\r");
   else            printf("Chips Found=%u\n",count);
}

void BNO055_Config()
{
i2c_start();                                   
i2c_write(BNO055);                               
i2c_write(0x3E);       // Power Mode                                         
i2c_write(0x00);       // Normal:0X00 (or B00),Low Power: 0X01 (or B01),Suspend Mode: 0X02 (orB10)                                       
i2c_stop();                                                         
delay_ms(100);                                                         

i2c_start();                                                       
i2c_write(BNO055);                                                 
i2c_write(0x3D);       // Operation Mode                   
i2c_write(0x0C);       //NDOF:0X0C (or B1100),IMU:0x08 (or B1000),NDOF_FMC_OFF: 0x0B (or B1011)                                                                                   
i2c_stop();                                                         
delay_ms(100);          //Operation Mode switching time maximum=20ms
}

void BNO055_read()    //reg_addr_Yaw=0x1A
{
i2c_start();
i2c_write(0x52);     // 0x1A :GY955_SLAVE_WRT
i2c_write(0x1A);       //reg_addr_Yaw=0x1A
i2c_start();
i2c_write(0x53);   // 0x1B ::GY955_SLAVE_RD
Yaw = (int16)(i2c_read()|i2c_read(0)<<8 )/16.00;
i2c_stop();
}

void main()
{
   delay_ms(2000);
   BNO055_Config();
   delay_ms(1000);
   Search_i2c();
   while(TRUE)
   {   
   BNO055_read();
   printf("%f\r\n",Yaw);     
   }

}
Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Thu Jul 21, 2022 10:37 am     Reply with quote

Big problem is here:

Yaw = (int16)(i2c_read()|i2c_read(0)<<8 )/16.00;

Problem is you are trying to rotate an 8bit value 8 bits..

Yaw = (i2c_read)|((int16)i2c_read(0)<<8 ))/16.00;

This casts the second read to an int16 before the rotation.
On the Arduino the default integer is an int16.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group