Page 1 of 1

9DoF Sensor Access

PostPosted: Wed Oct 09, 2019 6:39 pm
by GettinBetter
Setup:
EasyPIC V7 board/ICD3/MCC
Using PIC18F45K22/8MHz
XC8/C90
Bosch BNO055 Sensor.


Hi Chaps & Chapesses,
Trying to Access the above named sensor, just a simple proof of communication by reading gyro X to terminal.
Here's a couple of links to the data sheets...

Files bno055.c, bno055.h & support files
https://github.com/BoschSensortec/BNO055_driver

Quick Start Guide
https://ae-bst.resource.bosch.com/media/_tech/media/application_notes/BST-BNO055-AN007.pdf

BNO055 Data Sheet
https://ae-bst.resource.bosch.com/media/_tech/media/datasheets/BST-BNO055-DS000.pdf

PIC18F45K22 Data Sheet
http://ww1.microchip.com/downloads/en/DeviceDoc/40001412G.pdf

I'm using the MCC to configure the I2C, and the USART. I've used the MCC quite a bit now, I know how to use the button just not how to use all the information it generates.

So following the guides as best I can I've come up with this....

Code: Select all
/*
 main.c
 */

#include "mcc_generated_files/mcc.h"
#include "bno055.h"


int8_t RAW_Tempdata;

void main(void)
{
    // Initialize the device
    SYSTEM_Initialize();
    EUSART1_Initialize();

    // Enable the Global Interrupts
    INTERRUPT_GlobalInterruptEnable();
    // Enable the Peripheral Interrupts
    INTERRUPT_PeripheralInterruptEnable();
   
    printf("EasyPIC-V7, 8MHz, ICD3, BNO055 (9DOF)Sensor \n\r");
    printf("EUSART1 to Terminal readout Test, 05-Oct-19 \n\r");
    printf("BNO055 communication \n\n\r");
   
   
    __delay_ms(700);             // Wait for BNO055 POST to complete
    BNO055_OPERATION_MODE_NDOF();           // Change from config mode to use sensors
    BNO055_CONFIG_MODE_SWITCHING_DELAY(20);   // config mode delay
   
    while (1)
    {
        RAW_Tempdata = BNO055_GYRO_DATA_X_LSB_VALUEX_POS(); 
        printf("Gyro X : %4d ",RAW_Tempdata);
    }
}
/**
 End of File
*/


I've added the files the MCC generates, as I couldn't load the project (it exceeds the 256Kib forum limit)
If I can get one little bit of data out, I'll get the rest, even if it kills me :D

Any suggestions would be appreciated.

Regards
Les

Re: 9DoF Sensor Access

PostPosted: Fri Oct 11, 2019 9:42 am
by Roche
Usual stuff for iic debug - start with a scope on clock and data lines...

Re: 9DoF Sensor Access

PostPosted: Fri Oct 11, 2019 6:24 pm
by GettinBetter
Roche wrote:Usual stuff for iic debug - start with a scope on clock and data lines...


Yup, would do, if only I can get something to compile...
Here's todays effort....perhaps you guys can see something?

Code: Select all
/*
 main.c
 */
/************************************/
/*    FILE INCLUDES                */
/************************************/
#include "mcc_generated_files/mcc.h"
#include "bno055.h"

/************************************/
/*    DEFINITIONS                   */
/************************************/
#define   I2C_BUFFER_LEN 8
#define I2C0 5
#define   BNO055_I2C_BUS_WRITE_ARRAY_INDEX   ((u8)1)

/************************************/
/*    DECLARATIONS               */
/************************************/

s8 BNO055_I2C_bus_read(u8 dev_addr, u8 reg_addr, u8 *reg_data, u8 cnt);
s8 BNO055_I2C_bus_write(u8 dev_addr, u8 reg_addr, u8 *reg_data, u8 cnt);
s8 I2C_routine(void);

/************************************/
/*   STRUCTURES                   */
/************************************/

struct bno055_t bno055;


/************************************/
/*    FUNCTIONS                    */
/************************************/

void BNO055_delay_msek(u32 msek)
{
   __delay_ms(msek);
}

s8 BNO055_I2C_bus_write(u8 dev_addr, u8 reg_addr, u8 *reg_data, u8 cnt)
{
   s32 BNO055_iERROR = BNO055_INIT_VALUE;
   u8 array[I2C_BUFFER_LEN];
   u8 stringpos = BNO055_INIT_VALUE;

   array[BNO055_INIT_VALUE] = reg_addr;
   for (stringpos = BNO055_INIT_VALUE; stringpos < cnt; stringpos++)
      array[stringpos + BNO055_I2C_BUS_WRITE_ARRAY_INDEX] =
         *(reg_data + stringpos);
   return (s8)BNO055_iERROR;
}

    s8 BNO055_I2C_bus_read(u8 dev_addr, u8 reg_addr, u8 *reg_data, u8 cnt)
{
   s32 BNO055_iERROR = BNO055_INIT_VALUE;
   u8 array[I2C_BUFFER_LEN] = BNO055_INIT_VALUE;
   u8 stringpos = BNO055_INIT_VALUE;

   array[BNO055_INIT_VALUE] = reg_addr;

   for (stringpos = BNO055_INIT_VALUE; stringpos < cnt; stringpos++)
      *(reg_data + stringpos) = array[stringpos];
   return (s8)BNO055_iERROR;
    }

s8 I2C_routine(void)
{
   bno055.bus_write = BNO055_I2C_bus_write;
   bno055.bus_read = BNO055_I2C_bus_read;
   bno055.delay_msec = BNO055_delay_msek;
   bno055.dev_addr = BNO055_I2C_ADDR1;

   return BNO055_INIT_VALUE;
}

void main(void)
{
    // Initialize the device
    SYSTEM_Initialize();
    EUSART1_Initialize();

    // Enable the Global Interrupts
    INTERRUPT_GlobalInterruptEnable();
    // Enable the Peripheral Interrupts
    INTERRUPT_PeripheralInterruptEnable();
   
    printf("EasyPIC-V7, 8MHz, ICD3, BNO055 (9DOF)Sensor \n\r");
    printf("EUSART1 to Terminal readout Test, 05-Oct-19 \n\r");
    printf("BNO055 communication \n\n\r");
   
   
    BNO055_delay_msek(700);            // Wait for BNO055 POST to complete
    //BNO055_OPERATION_MODE_NDOF();           // Change from config mode to use sensors (compiler doesn't like it)
    BNO055_delay_msek(20);   // config mode delay
   
   
    while (1)
    {

            s16 gyro_datax = BNO055_INIT_VALUE;     //variable used to read the gyro x data

            s16 gyro_datay = BNO055_INIT_VALUE;     // variable used to read the gyro y data

            s16 gyro_dataz = BNO055_INIT_VALUE;     // variable used to read the gyro z data

            printf("Gyro X : %4d \n\n",gyro_datax);
            printf("Gyro Y : %4d \n\n",gyro_datay);
            printf("Gyro Z : %4d",gyro_dataz);

    }
}
/**
 End of File
*/


Regards
Les

Re: 9DoF Sensor Access

PostPosted: Mon Oct 14, 2019 1:09 am
by jtemples
You haven't provided complete code and you haven't told us what errors you're getting, so it's difficult for anyone to help.

Re: 9DoF Sensor Access

PostPosted: Tue Oct 15, 2019 11:29 pm
by GettinBetter
jtemples wrote:You haven't provided complete code and you haven't told us what errors you're getting, so it's difficult for anyone to help.


Ok, understood (note to self "Must do better"), but not to worry. I've abandoned the setup in this test, for a 16bit setup (PIC24), and there will be a familiarisation period for me on the new dev board(Explorer 16/32). Loads of new toys :D oh, and there'll be some SD card shenanigans to come lol. I'll repost when I get back up to speed with the new kit.
Cheers peeps.
Regards
Les

Re: 9DoF Sensor Access

PostPosted: Sat Nov 28, 2020 10:10 pm
by pavilionPOK
I had a similar problem when I could not open files in this format. My pc cannot readjust this code and does not display it on the screen in any way. Friends advised me to try to convert this file to pdf format at SPAMMY LINK REMOVED this format it is much more convenient and easier to display all the necessary documents, and I would do so in the future.