View previous topic :: View next topic |
Author |
Message |
Arera
Joined: 23 Sep 2007 Posts: 386 Location: Wuppertal, Germany
|
Posted: Sun Feb 27, 2022 12:24 am Post subject: Melexis MLX90393 on I2C |
|
|
Hi all,
I'm trying to use the Melexis MLX90393 magnetic field sensor, using I2C.
I've used I2C before and I'm not new to BASCOM, so my question is not how to use I2C in general, but especially with this very part.
Setting and reading the status byte works, but all registers read &H0, wich is obviously faulty.
Anyone with experience with that MLX90393 out there?
Thanks a lot!
(BASCOM-AVR version : 2.0.8.5 ) |
|
Back to top |
|
|
Per Svensson
Joined: 03 Oct 2004 Posts: 235 Location: Gothenburg, Sweden
|
Posted: Wed Mar 09, 2022 9:45 am Post subject: |
|
|
I have not used the 90393 which is a 3-axis magnetometer, but I have experience from the 90316 which is a rotational sensor.
The 90316 works very well, but unfortunately it use SPI instead of I2C, so the bottom line is that I probably cannot help you as there
might be too much difference to be of any assistance.
If you still want my SPI driver for the 90316 then just tell me.
/Per |
|
Back to top |
|
|
Arera
Joined: 23 Sep 2007 Posts: 386 Location: Wuppertal, Germany
|
Posted: Wed Mar 09, 2022 11:34 am Post subject: |
|
|
Thanks a lot for for your kind offer, Per!
Meanwhile i found out what went wrong, I've got everything running well. I did not reply nor close this thread, for it is a bit off topic to bascom anyway, and there was little response up to now.
For those interested:
1: When reading the status-byte by using the EX-command, you will receive an error, in case mode "SM" is active.
This is even anounced in the datasheet, somewhere in a dark corner....
I expected that something you switch "off" does not give an error, just because it has been switches of before.
2: Most of the registers really read &H00, I didn't expect that.
3: This is not prooven, but I changed one more thing: instead of using all the single commands like i2cstart, i2cwbyte..., I changed to the use of I2csend and i2creceive.
Maybe this provides better timing, and maybe MLX90393 is sensitive to that, I don't really know.
What I know: i2csend/receive works like a charm and is easier to use, but it took me some minutes to understand that the buffer-byte-array holds the bytes to send before receiving,
and holds the received bytes after. That applies to all the TX and RX bytes.
The helpfile is not clear about that. Maybe Mark Alberts could improve that a little to help those shallow minded guys like I am.
One sentence that confused me aswell in the helpfile: "Take care not to send to many bytes". The number of bytes is given in the datasheet, so how can I care more?
Marc |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Wed Mar 09, 2022 3:11 pm Post subject: |
|
|
it is good practice to always give an update if you ask a question here.
about i2creceive : yes the remark about the to (too) many bytes is not making sense. this statement was derived from the 8051 version. and the help topic as well. i agree it is unclear.
i will have that fixed. anyway, you can optional send some data, and also optional receive data. since there is only 1 variable it seemed logic that it needed to be set first. but the help is not clear.
There is an example however that demonstrates how to send/receive :
Code: | Dim Buf(10)as Byte
Buf(1) = 1 : Buf(2) = 2
I2creceive Slave , Buf(1) , 2 , 1 'send two bytes and receive one byte
Print Buf(1) 'print the received byte
End |
_________________ Mark |
|
Back to top |
|
|
Arera
Joined: 23 Sep 2007 Posts: 386 Location: Wuppertal, Germany
|
Posted: Wed Mar 09, 2022 8:07 pm Post subject: |
|
|
Quote: | but it took me some minutes to understand | , it ain't no big thing, 2-3 minutes, to be clear.
My suggestion to be clearer than you already are (see first comment):
Code: | Dim Buf(10)as Byte
Buf(1) = 1 : Buf(2) = 2
I2creceive Slave , Buf(1) , 2 , 1 'send bytes Buf(1) and Buf(2), then receive one byte into Buf(1)
Print Buf(1) 'print the received byte
End |
After all, talking about such tiny issues showes what level BASCOM is!
Thanks Mark! |
|
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
|
|