View previous topic :: View next topic |
Author |
Message |
uhrmacher
Joined: 15 Sep 2005 Posts: 60 Location: Donauwoerth
|
Posted: Mon Oct 05, 2015 2:50 pm Post subject: BNO055 readout with bascom.... |
|
|
Hi everybody,
i want to realize a application with the 9-axis orientation sensor BNO055 from Bosch. It is a I2C device, often used on arduino shield..... but since i use bascom very successful and for long time, simply i want to create the code with bascom.... cause arduino is more or less ATMEL family and is easily usable with bascom.
Normally i am familiar with the bascom I2c routines, but unfortunately i get stuck now with the I2C function, because the BNO055 device does have a a huge numbers of registers, which are containing the values of x y z axis positions, accelerations and much more parameters, and last but not least the config modes.
for a simple I2c device, normally i do:
i2receive, slave ,var
whats difficult to me, the BNO055 need additional to his I2C adress slave, to be talked with a registeradress and from this registeradress the you may get value...
also i tried code like this:
I2csend dev_adr '// adress of I2C sensor
I2csend gravity_x_reg '// send number of register from i want a data
I2creceive gravity_x_val '// wordvariable get value from sensor
thats what i have tried but with no result, i never have got a byte or wordvalue from the device. With an osci, i checked out the I2C bus and the signals are as far good.
so my question is, ist that possible with the I2C routines, to communicate wit this I2C sensor by using his I2C adress AND a register adress AND reading the valure from the register desired?? Most registers fit to byte, some fit to word ( 2 byte..)
any suggestions or hints are very welcome!
best regards
uhrmacher
[b][color=red](BASCOM-AVR version : 2.0.7.8 )[/b][/color]
Last edited by uhrmacher on Mon Oct 05, 2015 7:43 pm; edited 2 times in total |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Mon Oct 05, 2015 7:37 pm Post subject: Re: BNO055 readout with bascom.... |
|
|
uhrmacher wrote: | also i tried code like this:
I2csend dev_adr '// adress of I2C sensor
I2csend gravity_x_reg '// send number of register from i want a data
I2creceive gravity_x_val '// wordvariable get value from sensor
but it seems to be much more complicated. |
If that's all your problem, then use it this way, what minimum/maximum of complexity do you expect by driving a 100+ register chip?
You can encapsulate the required I2C commands within user functions, so you get desired functionality with clean interface.
This however:
Quote: | how should i use the I2C commands to ask the desired register of the sensor and as next step read the value exactly from that register? |
does not look like you've succeeded.
In the data sheet you find an example for multiple read, a single read simply stops earlier, but works the same.
The chip does automatically register increments, so the addressing sequence Start/Write SlA-W/Write RA only needs to be sent once and subsequent reads via (Re)Start/Write SlA-R/Read ACK, Read ACK, ..., Read NACK/Stop can read in complete sensor data. |
|
Back to top |
|
|
uhrmacher
Joined: 15 Sep 2005 Posts: 60 Location: Donauwoerth
|
Posted: Thu Oct 08, 2015 10:39 am Post subject: BNO_055 on Arduino ATMega328 no r/w access to register |
|
|
Hi again,
no, it is obviously not as simple as you think...
according to the datasheet, the sensor I2c read access is as follows:
a read sequence consits on a one-byte i2c write phae, followed by te i2c read phase.
The two parts of the transmission must be separated by a repeated start condition.
The i2c write phase adresses the slave and sends the register adress to be read.
After slave acknowledges the transmission, the master shouldgenerate again a start condition
and send the slave adress together wit a read bit (RW=1)
Then the master releases the bus and waits for the data bytes to be read from slave.
After each data byte the master has to generate an acknowledge bit (ack=0) to enable further data
transfer. A nack(ack=1) from the master stops the data to being transfered from the slave......
ok, i have written in arduino c code this working snippet example:
( for both examples: dev_adr = device adress
reg-adr = register adress
val1 = variable
Wire.beginTransmission((int)dev_adr); // start condition with i2c device adress 0x28
Wire.write((int)reg_adr); // write register adress
Wire.endTransmission();
Wire.requestFrom((int)0x28; 1 ); // read ( slave_adr, byte number )
while (Wire.available()) // loop as long as data to read
{
reading = Wire.read();
Serial.println(reading)
}
in bascom it should be like this:
I2cstart ' i2c start condition
I2cwbyte dev_adr ' write to device adress
I2cwbyte reg-adr ' write to register adress
i2srepstart ' restart the i2c bus
I2cwbyte dev_adr ' write device adress
I2crbyte val , nack ' get data
I2cstop
what i think..... may cause a problem is, to make i2c read, but not possible to define from device AND register to read.
Imagine: i2cread , dev_adr , reg_adr , numberofbytes ........this would be a locigal thing ??!!
please look to the bascom snippet, what is missing..i tried a lot different combinations but nothing works....
even it works with arduino c, i like very much to write the program with bascom, unfortunately strugglíng to get the data out.....
the i2c read access is described on page 92 of the BNO055 datasheet. there are two write cycle, 1. slave adress, 2. register adress, then a repeat bus start should be done
and a write cycle slave adress follows and then one or more data read cycles. as your code example....
the sensor and hardware is approved, cause arduino code reads successful from it.
https://www.bosch-sensortec.com/en/homepage/products_3/sensor_hubs/iot_solutions/bno055_1/bno055_4
best regards
Ingolf
Last edited by uhrmacher on Thu Oct 08, 2015 1:06 pm; edited 1 time in total |
|
Back to top |
|
|
i.dobson
Joined: 05 Jan 2006 Posts: 1570 Location: Basel, Switzerland
|
Posted: Thu Oct 08, 2015 11:22 am Post subject: |
|
|
Hello,
Every i2c chip has 2 addresses (write Address & Read Address).
In your code your doing
Code: |
I2cstart ' i2c start condition
I2cwbyte dev_adr ' write to device adress
I2cwbyte reg-adr ' write to register adress
i2srepstart ' restart the i2c bus
I2cwbyte dev_adr ' write device adress
I2crbyte val , nack ' get data
|
So your sending the write address twice! and not doing a ic2sop/i2cstart between switching between write and read. Try something like:-
Code: |
I2cstart ' i2c start condition
I2cwbyte dev_adr ' write to device adress
I2cwbyte reg-adr ' write to register adress
i2cstop ' stop i2c bus
incr dev_adr 'Swap to read address
i2cstart
I2cwbyte dev_adr ' read device adress
I2crbyte val , nack ' get data
i2cstop
|
Regards
Ian Dobson _________________ Walking on water and writing software to specification is easy if they're frozen. |
|
Back to top |
|
|
uhrmacher
Joined: 15 Sep 2005 Posts: 60 Location: Donauwoerth
|
Posted: Thu Oct 08, 2015 1:00 pm Post subject: |
|
|
Hello Ian,
oh, very fast reponse, thank you very much! I tried your suggestion, hm, yes i am afraid about the write adress twice, previous i tried also using i2crepstart
I2cstart ' i2c start condition
I2cwbyte dev_adr ' write to device adress
I2cwbyte reg-adr ' write to register adress
I2crepstart
I2cwbyte dev_adr ' read device adress
I2crbyte val , nack ' get data
i2cstop
but it wouldn´t work....
so i tried your suggestion, even with incr- dev_adr but has the result that i get a value,
i expect for example the BNO055 chip ID @register 0x00 with value 0xA0 . code returns 0x20 or 0x40,
so it reads somewhat unknown.
[I2cstart ' i2c start condition
I2cwbyte dev_adr ' write to device adress
I2cwbyte reg-adr ' write to register adress
i2cstop ' stop i2c bus
incr dev_adr 'Swap to read address
i2cstart
I2cwbyte dev_adr ' read device adress
I2crbyte val , nack ' get data
i2cstopcode][/code]
hm, i have not understand the incr dev_adr. The Sensor ( but its a sensormachine with controller ) has the unique I2C ID of 0x28, default. I think that i must not change?? Or you mean the register_adress??
The BN=055 has 0x7F registers inside who contains a lot of data, for accelaration, gyro, magnetic, kompass, values, caldata and offsets and config registers... so to read lsb and msb from a register i have to incr +1
but i am not at this step, actually the data are not accessible buy the code.... |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Thu Oct 08, 2015 1:11 pm Post subject: |
|
|
when using i2c the LS bit holds the read/write direction bit.
i2cwrite and i2cread set this bit to the proper value.
but when using the lower level statements, you need to send the proper address.
the base address can be &H28 but you use &H28 or &H29 in that case.
see this from the help :
Code: | Const Addressw = 174 'slave write address
Const Addressr = 175 'slave read address
I2cstart 'generate start
I2cwbyte Addressw 'slave adsress
I2cwbyte Adres 'address of EEPROM
I2cstart 'repeated start
I2cwbyte Addressr 'slave address (read)
I2crbyte Value , Nack 'read byte
I2cstop |
_________________ Mark |
|
Back to top |
|
|
uhrmacher
Joined: 15 Sep 2005 Posts: 60 Location: Donauwoerth
|
Posted: Thu Oct 08, 2015 2:08 pm Post subject: |
|
|
yes, i have read that and also coded in my example but the BNO055 don't like it.
[code]
Const Addressw = &h28 'slave write address
Const Addressr = &H29 'slave read address
register_adress = &H00 ' register &h00 of the BNO055 holds the ID Number = 160 dec.
I2cstart 'generate start
I2cwbyte Addressw 'slave adsress
I2cwbyteregister_adress 'address of EEPROM
I2cstop
I2cstart 'repeated start
I2cwbyte Addressr 'slave address (read) // her my question: if i write here only slave adress, woh the device knows that i wnat to read from register &h00?
I2crbyte Value , Nack 'read byte
I2cstop [/code]
with this code value is something but not 0xA0 (2 as expected, means, i2c reads not from device 0x28, register0x00
best regards
Ingolf |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Thu Oct 08, 2015 3:16 pm Post subject: |
|
|
after this :
I2cwbyteregister_adress 'address of EEPROM
I2cstop REMOVE THIS
I2cstart 'repeated start
you should remove the i2cstop since you use i2crepeated start.
it is best to use i2crepstart and not i2cstart. while in many processors i2crepstart just calls i2cstart, it is not the case for all processors. some have a special register where i2crepstart must be used.
it depends on soft i2c, twi, xmega and usi.
you also might have a look at i2creceive which can send and receive data. _________________ Mark |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Thu Oct 08, 2015 6:37 pm Post subject: Re: BNO_055 on Arduino ATMega328 no r/w access to register |
|
|
uhrmacher wrote: | according to the datasheet, the sensor I2c read access is as follows:
a read sequence consits on a one-byte i2c write phae, followed by te i2c read phase.
The two parts of the transmission must be separated by a repeated start condition.
The i2c write phase adresses the slave and sends the register adress to be read.
After slave acknowledges the transmission, the master shouldgenerate again a start condition
and send the slave adress together wit a read bit (RW=1)
Then the master releases the bus and waits for the data bytes to be read from slave. |
That's what I wrote:
Quote: | so the addressing sequence Start/Write SlA-W/Write RA only needs to be sent once and subsequent reads via (Re)Start/Write SlA-R/Read ACK, Read ACK, ..., Read NACK/Stop can read in complete sensor data. |
Quote: | no, it is obviously not as simple as you think... |
It actually is easy, only you don't understand. |
|
Back to top |
|
|
uhrmacher
Joined: 15 Sep 2005 Posts: 60 Location: Donauwoerth
|
Posted: Fri Oct 09, 2015 7:39 am Post subject: BNO055 read/write = solved |
|
|
solved!
the reason is, the BNO055 want to have 7 bitslave adress + 1 bit as read/write status....
so...
device adress = &h28 binary = 00101000
but for 7bit adress + r/w bit it is binary =0101000|0
7 bit slave adress + 0 for write = 01010000 = &h50
7 bit slave adress + 1 for write = 01010001 = &h51
..
I2cstart
I2cwbyte dev_adr_w
I2cwbyte reg_adr
I2cstart
I2cwbyte dev_adr_r
I2crbyte val1 , nack
I2c stop
..
thanks for your comments and hints that helps me solve the problem
best regards! |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Fri Oct 09, 2015 11:58 am Post subject: |
|
|
uhrmacher wrote: | ok, i tried also i2csend and ic2 receive but the value of the register read is still not the real value... |
You have first to make it work according datasheet with separate commands, on a working base you can retry again with I2CReceive.
Code: | I2cbyte dev_adr ' dev_adr = &H28, this ist the ID of the BNO055 |
&H28 is the 7-bit slave address where the RW bit is missing, I2CWByte needs an 8-bit value. R is 1 and W = 0.
Translated:
Code: | Start
Write SlA-W ' send SlaveAdress for Write
Write RA ' send RegisterAddress
(Re)Start ' RepeatedStart
Write SlA-R ' send SlaveAddress for Read
Read ACK ' read with Ack
'...
Read NACK ' last byte read with NACK
Stop ' Stop |
|
|
Back to top |
|
|
rkumetz
Joined: 23 Jan 2007 Posts: 165 Location: Vermont
|
Posted: Tue Feb 06, 2018 6:23 pm Post subject: |
|
|
Did you ever get this to work? I am looking at the BNO055 for a project as well. |
|
Back to top |
|
|
Matrixx
Joined: 30 Nov 2005 Posts: 158
|
Posted: Sun May 06, 2018 5:52 am Post subject: |
|
|
Still need BNO code...? |
|
Back to top |
|
|
rkumetz
Joined: 23 Jan 2007 Posts: 165 Location: Vermont
|
Posted: Mon May 07, 2018 12:42 am Post subject: |
|
|
I put the project aside to deal with more important issues but I could still use the code. |
|
Back to top |
|
|
EDC
Joined: 26 Mar 2014 Posts: 971
|
|
Back to top |
|
|
|
|
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 You cannot attach files in this forum You cannot download files in this forum
|
|