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 CCS Technical Support

HMC5843 with Logic Converter

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



Joined: 19 Feb 2013
Posts: 50

View user's profile Send private message Yahoo Messenger MSN Messenger

HMC5843 with Logic Converter
PostPosted: Fri Mar 01, 2013 10:19 am     Reply with quote

I have a problem with connection my PIC with the HMC5843 with Logic Converter.
HMC5843 like
https://www.sparkfun.com/products/9371

Logic Converter like

https://www.sparkfun.com/products/8745

The connection is like this :
The Pic and the compass have separated voltage source.
the HMC5843 is connected to 3 volt
and the PIC is connected to 5 volt
Then, I connected the SDA and SCL as the following :
each like is connected to the VCC by a resistance of 10 K ohm to the SDA Pin and then to the TX of the logic converter
and then the TX of the other side of the logic converter is connected directly to the PIC
the SCL has the same connection
I wrote the program :

Code:

#include<18f2550.h>
#fuses HS,NOPROTECT,NOWDT,NOLVP
#use delay(clock = 8000000)
#use I2C(MASTER, sda=PIN_B0, scl=PIN_B1)
void main()
{
   int32 data,data_x,data_y,data_z ;
   lcd_init(true);
   delay_ms(1000);
   printf("Welcome!!!");
   delay_ms(1000);
   lcd_clear();
   printf("It will start now");
   delay_ms(2000);

   i2c_start();
   i2c_write(0x3C);
   i2c_write(0x02);
   i2c_start();
   i2c_write(0x3D);
   data=i2c_read(0);
   i2c_stop();
      lcd_clear();
   
   
   delay_ms(100);
   printf("Block1");
   delay_ms(1000);
   i2c_start();
   i2c_write(0x3C);
   i2c_write(0x02);
   i2c_write(0x00);
   i2c_stop();
   lcd_clear();
   printf("x:");
   lcd_cursor_move(1,9);
   printf("Y:");
   lcd_cursor_move(2,1);   
   printf("Z:");
   while(true) {
      i2c_start();
      i2c_write(0x3C);
      i2c_write(0x03);
      i2c_write(0x3D);
             data_x = i2c_read(0)<<8; //msb
             data_x |= i2c_read(0);
            data_y = i2c_read(0)<<8; //msb
           data_y |= i2c_read(0);
              data_z = i2c_read(0)<<8; //msb
            data_z |= i2c_read(0);
              i2c_stop();
             delay_ms(100);
          lcd_cursor_move(1,3);
            printf("%Ld ",data_x);
          lcd_cursor_move(1,12);
            printf("%Ld ",data_y);
          lcd_cursor_move(2,4);
            printf("%Ld ",data_z);
            delay_ms(1000);
         
   }
 }



Regardless to the function :
lcd_cursor_move and lcd_clear .

I don't get results.
Where are my mistakes.
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Fri Mar 01, 2013 10:46 am     Reply with quote

I, for one, don't understand.

I need a schematic of exactly what you've done.
(ASCII art will do.)

Mike
amjad_alahdal



Joined: 19 Feb 2013
Posts: 50

View user's profile Send private message Yahoo Messenger MSN Messenger

PostPosted: Fri Mar 01, 2013 10:47 am     Reply with quote

I'm drawing what I have done using the Proteus , it's taking me some time

please wait
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Fri Mar 01, 2013 10:49 am     Reply with quote

Please only quote results from real hardware, not Proteus.

Mike
Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Fri Mar 01, 2013 10:59 am     Reply with quote

Several things leaping out.
First the PIC side of the converter also needs pullups. Say 4K7 to 5v.

Second in your read loop, you try to turn the bus round, but don't send the restart needed to do this.

Then third, you should not send 0 to every read transaction. Just I2c_read(), except the last transaction on a block, which wants the zero.

He is saying he is inputting the schematic to Proteus, so he can post it. The fact it isn't in Proteus already, says he is not simulating via Isis, so is OK here.... Smile

Best Wishes
amjad_alahdal



Joined: 19 Feb 2013
Posts: 50

View user's profile Send private message Yahoo Messenger MSN Messenger

PostPosted: Fri Mar 01, 2013 11:13 am     Reply with quote

The connection is shown in the link below

http://s22.postimage.org/nq9tzboy9/Compass_with_Logic_Converter.jpg

sorry, I didn't know how to upload it to the forum.
Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Fri Mar 01, 2013 11:50 am     Reply with quote

Yes. You _need_ the pullups on the PIC side. The PIC when driving I2C, is driving an open collector bus, which _relies_ on the pullups to pull it high. You don't have these.
Fix this, and the software problems and it may well work.
If not, download the I2C bus scanner program (code library), and see if it sees the device. If not you still have a hardware problem.

Best Wishes
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Fri Mar 01, 2013 2:18 pm     Reply with quote

Hi,

Pull-ups on the PIC side are probably not going to be your problem if you are using the posted logic level converter from Sparkfun. That is a "classic" n-channel MOSFET level converter with pull-ups on both the low and high voltage sides of the gate. The pull-ups that have been mentioned are already included on your converter.

John
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