News:

;) This forum is the property of Proton software developers

Main Menu

BNO055 9 axis orientation sensor Bosch

Started by chris_cb_uk, Dec 22, 2021, 10:00 AM

Previous topic - Next topic

chris_cb_uk

Purchased one of these Adfruit demo boards with sensor and voltage shifts to run at 5v to cut out the maths involved as in fusion mode you can read pitch roll and heading as simple output variables.  I'm having a bit of a crisis where I'm now questioning everything.
Firstly the address is a 7 bit, because of the board's addressing its $28, turning it to 8 bit with an extra 0 on LSB is then $50 or %001010000.  It's not responding at the moment, using 18F4550 on hardware SDA and SCL pins. Code snippet below.  On booting the devices goes into configuration mode and awaits instruction,  NDOF $0C bringing it into one of fusion modes where the maths is handled internally by the sensor's processor to give processed simple angular degrees out.

I am however now getting myself hung up over the I2C in/ out command and because it's not working I'm questioning everything.  The manual says the LSB is overridden by the command for in / out as to it being a 1 or a 0 depending on read/ write, so assume that I it doesn't matter if I write at $51 or $50 as it'll alter itself anyway?

I've upped the pullup resistors to the recommended 10k, and confirmed that I2C is working fine with the same pins by using other sensors without issue.

Any pointers to confirm my sanity would be warmly received

     
    Device = 18F4550
    Declare Xtal = 16   
    Declare LCD_DTPin = PORTB.4
    Declare LCD_RSPin = PORTB.2
    Declare LCD_ENPin = PORTB.3
    Declare LCD_Type 0
    Declare LCD_Interface 4
    Declare LCD_Lines 2
    Declare I2C_Slow_Bus On
   
Symbol SDApin = PORTB.0 ' Alias the SDA (Data) line
Symbol SCLpin = PORTB.1 ' Alias the SSL (Clock) line

 
Dim pitch       As      Word
Dim roll        As      Word
Dim heading     As      Word
Dim temp        As      Word

refresh:
Symbol bno055    =     %001010001   'target address of adfruit unit
Symbol bno055w    =     %001010000
Symbol OPR_MODE     =     $3d    'operation mode.  Unit boots up to configure on startup.  Need to change
DelayMS 20                                     ' Give sensor needed power up time
 
  I2COut SDApin,SCLpin,bno055w, OPR_MODE, [%00001100] ' sets up fusion Mode NDOF $0c
 
start:

DelayMS 200
Cls
DelayMS 10

 I2CIn SDApin,SCLpin,bno055,$1e,[pitch.LowByte]
 I2CIn SDApin,SCLpin,bno055,$1f,[pitch.HighByte]
 
I2CIn SDApin,SCLpin, bno055,$1c,[roll.LowByte]
 
I2CIn SDApin,SCLpin,bno055,£1d,[roll.HighByte]
I2CIn SDApin,SCLpin,bno055, $1a,[heading.LowByte]
         
I2CIn SDApin,SCLpin,bno055,$1b,[heading.HighByte]
   
I2CIn SDApin,SCLpin,bno055,$34,[temp]
 

Print At 1,1,"P", Dec6 pitch, At 1,9,"R", Dec6 roll
Print At 2,1, "H",Dec6 heading, At 2,11  ,"T", Dec2 temp
GoTo start

trastikata

#1
Please refer to the BNO055 datasheet I²C read access page 92.

It's a two phase read access (some sensor are using this method) - first you have to write to the register you are reading from and then start reading from it.

Also I see you are reading from several consecutive registers in a random order - best is if you read them in sequence instead, otherwise you have to write to each individual address before you can read it.

P.s. 10k pull-up resistors at 400kHz is a bit high, better use 2k to 5k. resistors.

BNO.jpg

chris_cb_uk

Thanks for the reply.  I had originally 4k7 in which everything else responded to well.  The 10k was a suggestion on the official Bosch forum.
I acknowledge the comments about random readings, so I also deleted all the other commands just to try reading the temperature on it's own.

I suppose this displays my lack of understanding on the actual I2CIN/OUT command in terms of it's actual mechanics. but I was under the impression that when you use the I2CIN with an address it will send out the Address and Control and await for the OutputData?

So the two phase action for temperature would be I2Cout SDApin,SCLpin,$50,$34,[xxx] followed by I2Cin SDApin,SCLpin,$51,$34,[temperature] ? and this would repeat for the other parameters?

I don't know what it is with datasheets but I really struggle to interpret the I2C references.  The BNO055 reference flips between tables and across the 105 pages.



trastikata

Try this instead:

Device = 18F4550
Declare Xtal = 16   
Declare LCD_DTPin = PORTB.4
Declare LCD_RSPin = PORTB.2
Declare LCD_ENPin = PORTB.3
Declare LCD_Type 0
Declare LCD_Interface 4
Declare LCD_Lines 2

Declare SDA_Pin PORTB.0
Declare SCL_Pin PORTB.1
Declare Slow_Bus On

Dim pitch       As      Word
Dim roll        As      Word
Dim heading     As      Word
Dim temp        As      Word

refresh:
Symbol bno055    =     %001010001   'target address of adfruit unit
Symbol bno055w    =     %001010000
Symbol OPR_MODE     =     $3d    'operation mode.  Unit boots up to configure on startup.  Need to change
DelayMS 20                                     ' Give sensor needed power up time

BStart
    BusOut bno055w, OPR_MODE, [%00001100]
BStop
 
start:

DelayMS 200
Cls
DelayMS 10

BStart
    BusOut bno055w
    BusOut $1A
    BReStart
    BusOut bno055
    BusIn heading.LowByte
    BusIn heading.HighByte
    BusIn roll.LowByte
    BusIn roll.HighByte
    BusIn pitch.LowByte
    BusIn pitch.HighByte
BStop

BStart
    BusOut bno055w
    BusOut $34
    BReStart
    BusOut bno055
    BusIn temp
BStop


Print At 1,1,"P", Dec6 pitch, At 1,9,"R", Dec6 roll
Print At 2,1, "H",Dec6 heading, At 2,11  ,"T", Dec2 temp
GoTo start

chris_cb_uk

Thanks for taking the time to modify this.  Just tried it but is giving random values.  I've also reverted back to 4k7 for the pullups as well to go back to a known working with I2C.  Just looking at the code and the symbol addresses on your code are 9 long? 

trastikata

QuoteJust looking at the code and the symbol addresses on your code are 9 long?

How so? The addressing is 7-bit device address plus read-write bit, 8 in total.

Be careful with the units, I simply corrected the I2C part, now when I took a better look it seems you are mixing the variable types signed and not signed, bytes and words. Some of the data coming from the sensor is using signed variables! You should really take the time analyzing the datasheet.

Here's the same code but with corrected variable types:

Device = 18F4550
Declare Xtal = 16   
Declare LCD_DTPin = PORTB.4
Declare LCD_RSPin = PORTB.2
Declare LCD_ENPin = PORTB.3
Declare LCD_Type 0
Declare LCD_Interface 4
Declare LCD_Lines 2

Declare SDA_Pin PORTB.0
Declare SCL_Pin PORTB.1
Declare Slow_Bus On

Dim pitch       As      SWord
Dim roll        As      SWord
Dim heading     As      Word
Dim temp        As      SByte

Symbol bno055    =     %001010001   'target address of adfruit unit
Symbol bno055w    =    %001010000
Symbol OPR_MODE     =     $3d    'operation mode.  Unit boots up to configure on startup.  Need to change

Main:
Clear : DelayMS 20                                     ' Give sensor needed power up time

BStart
    BusOut bno055w, OPR_MODE, [%00001100]
BStop
 
start:

DelayMS 200
Cls
DelayMS 10

BStart
    BusOut bno055w
    BusOut $1A
    BReStart
    BusOut bno055
    BusIn heading.LowByte
    BusIn heading.HighByte
    BusIn roll.LowByte
    BusIn roll.HighByte
    BusIn pitch.LowByte
    BusIn pitch.HighByte
BStop

BStart
    BusOut bno055w
    BusOut $34
    BReStart
    BusOut bno055
    BusIn temp
BStop


Print At 1,1,"P", SDec6 pitch, At 1,9,"R", SDec6 roll
Print At 2,1, "H",Dec6 heading, At 2,11  ,"T", SDec2 temp
GoTo start

chris_cb_uk

Quote from: trastikata on Dec 22, 2021, 01:24 PMHow so? The addressing is 7-bit device address plus read-write bit, 8 in total.
My code = Symbol bno055    =     %0010,1000,1 was in my original example with added commas to demonstrate 9. I understand this as wrong now and using the screenshot from the datasheet above for address $28 this gives the binary for write as %01010000 and write %01010001.  This is still the part I'm struggling to understand with the I2Cin/ out command.  Does the command automatically apply the bold read / write depending on it's in/ out status meaning that the 1,0 is irrelevant for this command?
Like I've said in previous posts I struggle to understand the datasheets as it's really not logical in my brain to interpret to understand, but once captured I'm fine going forward.

Just tried this code again and it's still sending rubbish numbers.  Hmmm

trastikata

Start first by reading the some read-only registers like Chip ID, ACC_ID and MAG_ID to see if you get their reset values.

chris_cb_uk

Quote from: trastikata on Dec 22, 2021, 02:14 PMStart first by reading the some read-only registers like Chip ID, ACC_ID and MAG_ID to see if you get their reset values.
Thanks, I'll do this to establish a reliable connection and work back from there.  Incidentally is there a reason why you used the bus command as opposed to I2C commands?

trastikata

#9
With the bus command you can issue a Restart condition as required by the sensor datasheet, whereas I am not sure if it will work with the new I2C commands.

If you can, run this code to see if it works?

Device = 18F4550
Declare Xtal = 16   
Declare LCD_DTPin = PORTB.4
Declare LCD_RSPin = PORTB.2
Declare LCD_ENPin = PORTB.3
Declare LCD_Type 0
Declare LCD_Interface 4
Declare LCD_Lines 2

Symbol SDApin = PORTB.0 ' Alias the SDA (Data) line
Symbol SCLpin = PORTB.1 ' Alias the SSL (Clock) line
Declare Slow_Bus On

Dim pitch       As      SWord
Dim roll        As      SWord
Dim heading     As      Word
Dim temp        As      SByte

Symbol bno055    =     %001010001   'target address of adfruit unit
Symbol bno055w    =    %001010000
Symbol OPR_MODE     =     $3d    'operation mode.  Unit boots up to configure on startup.  Need to change

Main:
Clear : DelayMS 20                                     ' Give sensor needed power up time


    I2COut SDApin,SCLpin, bno055w, OPR_MODE, [%00001100]

 
start:

DelayMS 200
Cls
DelayMS 10

    I2CIn SDApin,SCLpin,bno055,$1A,[heading.LowByte,heading.HighByte,roll.LowByte,roll.HighByte,pitch.LowByte,pitch.HighByte]
    I2CIn SDApin,SCLpin,bno055,$34,[temp]


Print At 1,1,"P", SDec6 pitch, At 1,9,"R", SDec6 roll
Print At 2,1, "H",Dec6 heading, At 2,11  ,"T", SDec2 temp
GoTo start

chris_cb_uk

Just tried the new suggestion, still no improvement.  I've stripped back everything and just trying to read the ID registers 0 through 3.  Thinking that as they're ID's they won't change.  However they still are, there seems to be a timing error somewhere as I'm getting changing numbers but they're the same number sequence which makes me think it's either dropping or picking up something out of sequence in the command.

Stephen Moss

Quote from: chris_cb_uk on Dec 22, 2021, 02:01 PMDoes the command automatically apply the bold read / write depending on it's in/ out status meaning that the 1,0 is irrelevant for this command?
No, the In/Out part of the command is telling the complier to set the TRIS bit for the data pin as input or outout, as the same pin is used for both sending and reciveing data the compiler needs a way of knowing if has to be set to an input depending on if you want to transmit or recieve data.
Also some I2C device use an 8bit address with a separate read/write control byte, so if the command manipulated the LSB it would be altering the address being sent to such a device.

Therefore as your salve address is %0101001 you have two options, either you can create two symbols, one for read  & one for write, i.e.
%01010010 for Write and
%01010011 for Read or
create one address symbol, i.e. Slave_Address = %0101001x, where x can be 1 or 0 and changed on the fly, i.e.
RW_Variable = Slave_Address & %11111110 for Write and
RW_Variable = Slave_Address | %00000001 for Read

Note the 8bit combined Address with R/W bit, not 9bit as used in the examples above which would be incorrect.

Also it apears that the pull up resistors for the SCL and SDA pins are internal to the Bosch device & that Adafruit have added some on both the 3.3V side for the device and the 5V side for thier board I/O so you don't need to add them youself as then you are putting them in parallel, changinf the pull up resistnace, and if I recall correctly you only need one set on a bus, not one set per slave.   

chris_cb_uk

I've tried to use the Bus function and incorporated the bus acknowledge as per the above I2C register access, just trying to read a constant i.e. chip ID but still producing random nonsense.
Declare SDA_Pin PORTB.0
Declare SCL_Pin PORTB.1
Declare Slow_Bus On

Dim value1          As      Byte
Dim value2          As      Byte
Dim value3          As      Byte
Dim ack            As      Bit


Main:
Clear : DelayMS 200                                   

start:

Cls
DelayMS 10

BStart
    BusOut %01010000
    BusIn ack
    BusOut %00000000
    BusIn ack 
BReStart
    BusOut %01010001
    BusIn ack
    BusIn value1
    BusAck
    BusIn value2
    BusAck
    BusIn value3
BStop

Print At 1,1, "3 ", Hex value3, At 1,9,"2 ", Hex value2
Print At 2,1, "1 ", Hex value1
GoTo start

JonW

Have you looked at the logic state of the Protocol select pins to ensure you are using I2C mode?

Page 99 of the manual


chris_cb_uk

Quote from: JONW on Dec 23, 2021, 11:24 AMHave you looked at the logic state of the Protocol select pins to ensure you are using I2C mode?

Page 99 of the manual



Yes the Adafruit module ties the PS1 PS2 to GND via 10k resistors.

chris_cb_uk

Quote from: Stephen Moss on Dec 23, 2021, 10:07 AMNo, the In/Out part of the command is telling the complier to set the TRIS bit for the data pin as input or outout, as the same pin is used for both sending and reciveing data the compiler needs a way of knowing if has to be set to an input depending on if you want to transmit or recieve data.

That is great, thanks for clarifying that for me.  It was an element I had in my head of extra complication which I couldn't understand or understand what the fog of the function actually does.

JonW

#16
Try this


Device = 18F26K22
           
Xtal = 16                        ' using pll at full speed (62.5nS/instruction)
All_Digital = true
'Declare Bootloader = 0
'Declare CCP1_Pin PORTC.2
'Declare Hserial_Baud = 115200 ' Set baud rate to 9600
'Declare Hserial_RCSTA = %10010000      ' Enable serial port and continuous receive
'Declare Hserial_TXSTA = %00100100      ' Enable transmit and asynchronous mode
'Declare Hserial_Clear = On ' Enable Error clearing on received characters      ' Clear the buffer before receiving

Declare SDA_Pin PORTB.0
Declare SCL_Pin PORTB.1
Declare Slow_Bus On



;Declare Adin_Res = 10 ' 10-bit result required
;Declare Adin_Tad = 64_FOSC ' RC oscillator chosen
;Declare Adin_Stime = 50 ' Allow 50us sample time

;Watchdog = 0 ; Disable the Watchdog timer     
 ;All_Digital = true
Config_Start
 FOSC = INTIO67        ' Int OSC Block
 ;FOSC = HSHP          ' HS oscillator (high power > 16 MHz)
 PLLCFG = On          ' Oscillator multiplied by 4
 PRICLKEN = On        ' Primary clock enabled
 FCMEN = Off          ' Fail-Safe Clock Monitor disabled
 IESO = Off            ' Internal/External Oscillator Switchover mode disabled
 PWRTEN = On          ' Power up timer enabled
 BOREN = SBORDIS      ' Brown-out Reset enabled in hardware only (SBOREN is disabled)
 BORV = 190            ' Brown Out Reset Voltage set to 1.90 V nominal
 WDTEN = Off          ' Watch dog timer is always disabled. SWDTEN has no effect.
 WDTPS = 128          ' Watchdog Timer Postscale 1:128
 CCP2MX = PORTC1      ' CCP2 input/output is multiplexed with RC1
 PBADEN = Off          ' PORTB<5:0> pins are configured as digital I/O on Reset
 CCP3MX = PORTB5      ' P3A/CCP3 input/output is multiplexed with RB5
 HFOFST = On          ' HFINTOSC output and ready status are not delayed by the oscillator stable status
 T3CMX = PORTC0        ' Timer3 Clock Input (T3CKI) is on RC0
 P2BMX = PORTB5        ' ECCP2 B (P2B) is on RB5
 MCLRE = EXTMCLR      ' MCLR pin enabled, RE3 input pin disabled
 STVREN = Off          ' Stack full/underflow will not cause Reset
 LVP = Off            ' Single-Supply ICSP disabled
 XINST = Off          ' Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
 Debug = Off          ' Disabled
 Cp0 = On            ' Block 0 (000800-001FFFh) not code-protected
 CP1 = On            ' Block 1 (002000-003FFFh) not code-protected
 CP2 = On            ' Block 2 (004000-005FFFh) not code-protected
 CP3 = On            ' Block 3 (006000-007FFFh) not code-protected
 CPB = On            ' Boot block (000000-0007FFh) not code-protected
 CPD = Off            ' Data EEPROM not code-protected
 WRT0 = Off            ' Block 0 (000800-001FFFh) not write-protected
 WRT1 = Off            ' Block 1 (002000-003FFFh) not write-protected
 WRT2 = Off            ' Block 2 (004000-005FFFh) not write-protected
 WRT3 = Off            ' Block 3 (006000-007FFFh) not write-protected
 WRTC = Off            ' Configuration registers (300000-3000FFh) not write-protected
 WRTB = Off            ' Boot Block (000000-0007FFh) not write-protected
 WRTD = Off            ' Data EEPROM not write-protected
 EBTR0 = Off          ' Block 0 (000800-001FFFh) not protected from table reads executed in other blocks
 EBTR1 = Off          ' Block 1 (002000-003FFFh) not protected from table reads executed in other blocks
 EBTR2 = Off          ' Block 2 (004000-005FFFh) not protected from table reads executed in other blocks
 EBTR3 = Off          ' Block 3 (006000-007FFFh) not protected from table reads executed in other blocks
 EBTRB = Off          ' Boot Block (000000-0007FFh) not protected from table reads executed in other blocks
Config_End

EData -4,-4,172,138,82,65



Dim SDA    As LATB.0
Dim SCL    As LATB.1


'-------------------------------------------------------------------------------------
'     
'                          Variable Declarations

'-------------------------------------------------------------------------------------

    Dim value1          As      Byte
    Dim value2          As      Byte
    Dim value3          As      Byte
    Dim ack            As      Bit




'-------------------------------------------------------------------------------------
'     
'                          SET UP PIC

'-------------------------------------------------------------------------------------

        ANSELA =    %00000011    ; RA0 & RA1 as Analog
        Clear ANSELB
        Clear ANSELC
        Clear INTCON
        Clear INTCON2
        Clear INTCON3
        SSPCON1 =  %00000000
        T3CON =    %00000000
        TRISA =    %00000000
        TRISB =    %00000000
        TRISC =    %10000010
        VREFCON0 =  %11100000    ; 2.048V reference
        VREFCON1 =  %11101000
        OSCCON =    %01111000    ;16MHz EXT XTAL x 4
     OSCCON2 =  %10000100    ;Sys clock from 4xPLL     

        SDA = 1      ' Config pins so device has required start conditions
        SCL = 1     
        DelayMS 200
Main:

        BusOut %01010010    'Slave address write  As there must be a write then read
        BusOut %00001000    ' Register 8
       
        DelayUS 50
       
        BusOut %01010011    'Slave address read    As there must be a write then read
        value1 = BusIn      ' Value 1 contains Reg 8 Value     
       
        Stop

   
    End


it simulates ok in Proteus, I set the SDA and SCL prior to the Bus commands to ensure the start bit is done correct (Bring SDA LOW while SCL is High).  According to the Positron manual a single Busout includes the ack.

Receives $FF or $00 if SDA is tied to either VCC or GND (I outputted value1 to serial terminal for debug). 

Have you looked at the waveforms on a scope?

J
           

chris_cb_uk

Sorry Jon, don't quite understand, what simulates ok? the I2C layout according to the manual or the communication with the BNO sensor?
 

JonW

The I2C cons with the devices and receiving data from the Busin command.  It cant simulate the devices as the simulator doesn't contain the Bosch parts.

I used the inbuilt I2C protocol analyser in ISIS and it reported errors with the previous code but adding a Bus Start command works so try this instead.


Device = 18F26K22
           
Xtal = 16                         ' using pll at full speed (62.5nS/instruction)
All_Digital = true
'Declare Bootloader = 0
'Declare CCP1_Pin PORTC.2
Declare Hserial_Baud = 115200 ' Set baud rate to 9600
Declare Hserial_RCSTA = %10010000       ' Enable serial port and continuous receive
Declare Hserial_TXSTA = %00100100       ' Enable transmit and asynchronous mode
Declare Hserial_Clear = On ' Enable Error clearing on received characters      ' Clear the buffer before receiving

Declare SDA_Pin PORTB.0
Declare SCL_Pin PORTB.1
Declare Slow_Bus On



;Declare Adin_Res = 10 ' 10-bit result required
;Declare Adin_Tad = 64_FOSC ' RC oscillator chosen
;Declare Adin_Stime = 50 ' Allow 50us sample time

;Watchdog = 0 ; Disable the Watchdog timer     
 ;All_Digital = true
Config_Start
 FOSC = INTIO67         ' Int OSC Block
 ;FOSC = HSHP           ' HS oscillator (high power > 16 MHz)
 PLLCFG = On           ' Oscillator multiplied by 4
 PRICLKEN = On         ' Primary clock enabled
 FCMEN = Off           ' Fail-Safe Clock Monitor disabled
 IESO = Off            ' Internal/External Oscillator Switchover mode disabled
 PWRTEN = On           ' Power up timer enabled
 BOREN = SBORDIS       ' Brown-out Reset enabled in hardware only (SBOREN is disabled)
 BORV = 190            ' Brown Out Reset Voltage set to 1.90 V nominal
 WDTEN = Off           ' Watch dog timer is always disabled. SWDTEN has no effect.
 WDTPS = 128           ' Watchdog Timer Postscale 1:128
 CCP2MX = PORTC1       ' CCP2 input/output is multiplexed with RC1
 PBADEN = Off          ' PORTB<5:0> pins are configured as digital I/O on Reset
 CCP3MX = PORTB5       ' P3A/CCP3 input/output is multiplexed with RB5
 HFOFST = On           ' HFINTOSC output and ready status are not delayed by the oscillator stable status
 T3CMX = PORTC0        ' Timer3 Clock Input (T3CKI) is on RC0
 P2BMX = PORTB5        ' ECCP2 B (P2B) is on RB5
 MCLRE = EXTMCLR       ' MCLR pin enabled, RE3 input pin disabled
 STVREN = Off          ' Stack full/underflow will not cause Reset
 LVP = Off             ' Single-Supply ICSP disabled
 XINST = Off           ' Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
 Debug = Off           ' Disabled
 Cp0 = On             ' Block 0 (000800-001FFFh) not code-protected
 CP1 = On             ' Block 1 (002000-003FFFh) not code-protected
 CP2 = On             ' Block 2 (004000-005FFFh) not code-protected
 CP3 = On             ' Block 3 (006000-007FFFh) not code-protected
 CPB = On             ' Boot block (000000-0007FFh) not code-protected
 CPD = Off             ' Data EEPROM not code-protected
 WRT0 = Off            ' Block 0 (000800-001FFFh) not write-protected
 WRT1 = Off            ' Block 1 (002000-003FFFh) not write-protected
 WRT2 = Off            ' Block 2 (004000-005FFFh) not write-protected
 WRT3 = Off            ' Block 3 (006000-007FFFh) not write-protected
 WRTC = Off            ' Configuration registers (300000-3000FFh) not write-protected
 WRTB = Off            ' Boot Block (000000-0007FFh) not write-protected
 WRTD = Off            ' Data EEPROM not write-protected
 EBTR0 = Off           ' Block 0 (000800-001FFFh) not protected from table reads executed in other blocks
 EBTR1 = Off           ' Block 1 (002000-003FFFh) not protected from table reads executed in other blocks
 EBTR2 = Off           ' Block 2 (004000-005FFFh) not protected from table reads executed in other blocks
 EBTR3 = Off           ' Block 3 (006000-007FFFh) not protected from table reads executed in other blocks
 EBTRB = Off           ' Boot Block (000000-0007FFh) not protected from table reads executed in other blocks
Config_End

EData -4,-4,172,138,82,65



Dim SDA    As LATB.0
Dim SCL    As LATB.1


'-------------------------------------------------------------------------------------
'       
'                          Variable Declarations

'-------------------------------------------------------------------------------------

    Dim value1          As      Byte
    Dim value2          As      Byte
    Dim value3          As      Byte
    Dim ack             As      Bit




'-------------------------------------------------------------------------------------
'       
'                          SET UP PIC

'-------------------------------------------------------------------------------------

        ANSELA =     %00000011    ; RA0 & RA1 as Analog
        Clear ANSELB
        Clear ANSELC
        Clear INTCON
        Clear INTCON2
        Clear INTCON3
        SSPCON1 =  %00000000
        T3CON =     %00000000
        TRISA =     %00000000
        TRISB =     %00000000
        TRISC =     %10000010
        VREFCON0 =  %11100000     ; 2.048V reference
        VREFCON1 =  %11101000
        OSCCON =    %01111000     ;16MHz EXT XTAL x 4
      OSCCON2 =   %10000100     ;Sys clock from 4xPLL       

        SDA = 1      ' Config pins so device has required start conditions
        SCL = 1     
        DelayMS 200
        GoTo Main
       


Main:
        BStart
        BusOut %01010010     'Slave address write   As there must be a write then read

        BStart
        BusOut %00001000     ' Register 8

        DelayUS 50

        BStart
        BusOut %01010011     'Slave address read    As there must be a write then read
       
        BStart
        value1 = BusIn       ' Value 1 contains Reg 8.
        HRSOut Bin8 value1,13,10       
       
        Stop


chris_cb_uk

Understood! Looking at the code though there doesn't need to be a bus start after the initial slave address to send register information.  It's one bus command.
Then the bus starts again with slave address, then receives data, and will continue to do so pending acknowledgements and then bus stop.
I've got the setup hooked up to a Rigol scope which is supposed to I2C decode but it's not very good.  Though Interestingly I've set up the register as an incremental number to read all registers, nothing is changing at all.  So either I'm still missing a starting command, or this sensor is duff.

Device = 18F4550
Declare Xtal = 16   
Declare LCD_DTPin = PORTB.4
Declare LCD_RSPin = PORTB.2
Declare LCD_ENPin = PORTB.3
Declare LCD_Type 0
Declare LCD_Interface 4
Declare LCD_Lines 2
All_Digital = true
Declare SDA_Pin PORTB.0
Declare SCL_Pin PORTB.1
Declare Slow_Bus On

Dim value1          As      Byte
Dim regi            As      Byte

Main:
Clear : DelayMS 200                                     
regi=0
start:

DelayMS 300
Cls
bs1:
BStart
    BusOut %01010000
    BusOut regi
    DelayUS 50
BReStart
    BusOut %01010001
    BusIn value1
BStop

Print At 1,1,"V ", Hex2 value1, At 1,9,"R ", Hex2 regi
Inc regi

GoTo start