CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

problem with hmc6352, using a PIC16F873A

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Guest








problem with hmc6352, using a PIC16F873A
PostPosted: Mon Jan 12, 2009 7:56 am     Reply with quote

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!
Ttelmah
Guest







PostPosted: Mon Jan 12, 2009 10:42 am     Reply with quote

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
Guest








PostPosted: Mon Jan 12, 2009 1:39 pm     Reply with quote

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.
Ttelmah
Guest







PostPosted: Mon Jan 12, 2009 2:33 pm     Reply with quote

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
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Mon Jan 12, 2009 5:42 pm     Reply with quote

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.
Guest








PostPosted: Tue Jan 13, 2009 6:50 am     Reply with quote

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
Guest








PostPosted: Tue Jan 13, 2009 10:20 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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