![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
Guest
|
problem with hmc6352, using a PIC16F873A |
Posted: Mon Jan 12, 2009 7:56 am |
|
|
hi!
I have a problem with this compass, with the I2C protocol. When I try to see the signal from the scope I get nothing but a single pulse, which amplitude is 3.3V, the voltage of the compass, I don't know if I'm doing a bad connection (I've followed the recommendations from the datasheet to connect everything), or if I put the scope probe in a wrong place (i just put it directly to the SDA and SCL lines).
the code for the compass is:
Code: |
#include <16F873A.h>
#fuses HS, NOPROTECT, NOWRT, NOLVP
#use delay(clock=20000000)
#use i2c(Master, sda=PIN_C4, scl=PIN_C3)
int16 lect;
int16 leer(){
int16 lsb;
int16 msb;
i2c_start();
i2c_write(0x42);//direccion de escritura de la brujula
i2c_write(0x41);//pedir resultados
i2c_stop();
delay_ms(7); // 1 ms de más
i2c_start();
i2c_write(0x43);//direccion de lectura
msb = i2c_read();
lsb = i2c_read(0);
i2c_stop();
return((int16)lsb | ((int16)msb << 8));
}
void main(){
setup_adc_ports (NO_ANALOGS);
setup_adc (ADC_OFF);
setup_spi (SPI_SS_DISABLED);
setup_timer_0 (RTCC_INTERNAL | RTCC_DIV_1);
setup_timer_1 (T1_INTERNAL | T1_DIV_BY_8);
setup_timer_2 (T2_DISABLED, 0, 1);
setup_comparator (NC_NC_NC_NC);
setup_vref (FALSE);
lect=leer();
}
|
thank you! |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Mon Jan 12, 2009 10:42 am |
|
|
It is not clear from your question, but it sounds a little as if you are running the sensor on a different supply from the PIC?. If so, then this may be your problem. The Schmitt inputs used on the I2C inputs, _require_ a minimum input voltage of 0.8*Vdd. For a 5v PIC, 3.2v. Now a logic output, will never quite swing 'to' it's supply, and it is probable that the PIC is not actually seeing the I2C lines reach their required voltage level....
Try either switching to a LF PIC, and running this at 3.3v as well (10MHz max though), or pulling the I2C lines up to 5v.
Alternatively use software I2C (different pins on the PIC), and chose pins with standard logic inputs, rather than ST inputs.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
|
Posted: Mon Jan 12, 2009 1:39 pm |
|
|
thanks, i got some pulses from the scope, but i have another question:
how can I "see" the value of the heading with the scope?, i mean how can I know where is the North, the South, etc. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Mon Jan 12, 2009 2:33 pm |
|
|
In default mode (as it wakes up), the number read is just the heading, in 1/10th degree steps. Remember that the heading will be in magnetic 'terms', so affected by local things, and by your magnetic variation.
So, start by using a union to combine the lsb/msb, or the make16 function to do the same. Then the numer you get divided by ten, is the heading in degrees, relative to the local magnetic north. For me (in the SE UK), I would have to add '42' to the number read (4.2 degrees local magnetic variation). A local airfield, or an aviation chart will give you this number.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Mon Jan 12, 2009 5:42 pm |
|
|
Quote: | Schmitt inputs used on the I2C inputs, _require_ a minimum input voltage of 0.8*Vdd. For a 5v PIC, 3.2v. | . Not quite right. Normal I2C Vih,min level is 0.7*Vdd, but it can be configured to lower SMB levels of 1.4V with 16F873A. |
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
|
Posted: Tue Jan 13, 2009 6:50 am |
|
|
Ttelmah wrote: | In default mode (as it wakes up), the number read is just the heading, in 1/10th degree steps. Remember that the heading will be in magnetic 'terms', so affected by local things, and by your magnetic variation.
So, start by using a union to combine the lsb/msb, or the make16 function to do the same. Then the numer you get divided by ten, is the heading in degrees, relative to the local magnetic north. For me (in the SE UK), I would have to add '42' to the number read (4.2 degrees local magnetic variation). A local airfield, or an aviation chart will give you this number.
Best Wishes |
right, but do i have to read the pulses in the SDA line as a binary number? because i only have the scope.
thanks a lot |
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
|
Posted: Tue Jan 13, 2009 10:20 am |
|
|
i want to use hyperterminal to see the results, how can I do this? I'm using a RJ-11 DB-9 RS232 cable.
thanks |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|
Powered by phpBB © 2001, 2005 phpBB Group
|