9DoF Sensor Access

(instructions, reset, WDT, specifications...) PIC17Cxx, PIC18Fxxx

9DoF Sensor Access

Postby GettinBetter » Wed Oct 09, 2019 6:39 pm

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
Attachments
mcc_generated_files.zip
(27.31 KiB) Downloaded 284 times
History teaches us that history doesn't teach us.
User avatar
GettinBetter
 
Posts: 43
Joined: Wed Jun 06, 2018 8:48 pm

Re: 9DoF Sensor Access

Postby Roche » Fri Oct 11, 2019 9:42 am

Usual stuff for iic debug - start with a scope on clock and data lines...
Roche
 
Posts: 72
Joined: Fri Jul 11, 2014 12:35 pm
PIC experience: Professional 5+ years with MCHP products

Re: 9DoF Sensor Access

Postby GettinBetter » Fri Oct 11, 2019 6:24 pm

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
History teaches us that history doesn't teach us.
User avatar
GettinBetter
 
Posts: 43
Joined: Wed Jun 06, 2018 8:48 pm

Re: 9DoF Sensor Access

Postby jtemples » Mon Oct 14, 2019 1:09 am

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.
jtemples
Verified identity
 
Posts: 195
Joined: Sun May 25, 2014 2:23 am
Location: The 805
PIC experience: Professional 5+ years with MCHP products

Re: 9DoF Sensor Access

Postby GettinBetter » Tue Oct 15, 2019 11:29 pm

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
History teaches us that history doesn't teach us.
User avatar
GettinBetter
 
Posts: 43
Joined: Wed Jun 06, 2018 8:48 pm

Re: 9DoF Sensor Access

Postby pavilionPOK » Sat Nov 28, 2020 10:10 pm

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.
Last edited by ric on Wed Dec 02, 2020 5:03 am, edited 1 time in total.
Reason: spammy link removed, user banned.
pavilionPOK
Banned
 
Posts: 1
Joined: Sat Nov 28, 2020 10:06 pm


Return to 16-Bit Core

Who is online

Users browsing this forum: No registered users and 10 guests

cron