Discussion in "8051 Discussion Forum" started by    siddique    Jun 17, 2014.
Tue Jun 17 2014, 06:30 pm
#1
hi guys,
i'm working on my compass sensor from 3 days. i think my approach is not correct. i'm getting random values which i dont think is the exact data.
request guidance from the people who have worked on this... i'm doing it with at89s52 controller.

waiting for a fast reply
Wed Jun 18 2014, 10:16 am
#2
You need to post some more information like what configuration you're doing in the device and what commands are you sending. I am assuming your I2C is perfect and only problem is with the compass related code. You can post the code snippet if not the whole code so it becomes easy to understand what you have been doing with compass.

[Topic moved to 8051 Discussion Forum]
 siddique like this.
Wed Jun 18 2014, 08:09 pm
#3
hi ajay,
i've attached the code. pls let me know if there is anything wrong.
ps: this code is still under process so there is a huge part of the code commented.
Thu Jun 19 2014, 11:48 am
#4
Please zip the files before attaching, We only allow archives, images and pdfs to be uploaded.
Thu Jun 19 2014, 03:26 pm
#5
i've attached the rar file.
Attachment
Wed Jun 25 2014, 10:26 am
#6
The first look at your program... are you sure you know what you're doing?
start();
i2c_out_byte(0x3c);
nack();
i2c_out_byte(0x00);
nack();
i2c_out_byte(0x70);
nack();
stop();

You're sending NAK after every byte transfer so probably your compass is not getting configured at all. check your code again and retry.
Wed Jun 25 2014, 11:14 am
#7
hi,
its working fine. i'm getting all the data correctly (with the nack).
thanks a lot for your support.
Wed Jun 25 2014, 11:24 am
#8
Good that its working but bad that you're getting data with NAK you must review your i2c implementation.
Wed Jun 25 2014, 11:33 am
#9
ok, but in i2c we have to send an ACK or NACK after each data right??
Thu Jun 26 2014, 10:08 am
#10
As per I2C protocol, when reading from slave you should send ACK for all bytes and to end communication you send NACK. and when writing to slave device you should always get ACK from slave if NAK is returned you should stop communication at that point.

See I2C tutorial for more information: http://www.8051projects.net/i2c-twi-tutorial/

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

MnoioCoove
Tue May 21 2024, 02:06 am
PedroDug
Sun May 19 2024, 05:39 pm
JewelAmuck
Sun May 19 2024, 03:06 pm
Minniemus
Sun May 19 2024, 07:39 am
Andyhet
Sat May 18 2024, 07:28 am
BrettTibre
Fri May 17 2024, 06:14 pm
Gordonfax
Fri May 17 2024, 10:28 am
Davidspils
Fri May 17 2024, 10:19 am