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

i2c problem with PIC16F876 and MD03 DC motor driver

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



Joined: 14 May 2007
Posts: 14

View user's profile Send private message

i2c problem with PIC16F876 and MD03 DC motor driver
PostPosted: Sat Jun 07, 2008 1:54 am     Reply with quote

Hello.
I have some problems in driving a dc motor with a PIC16F876 and MD03 DC motor driver. The MD03 is using a PIC16F872 in slave mode. Theoretically, all I have to do is to set my PIC on i2c master mode and control the DC motor using i2c_* functions. I configured the MD03 to work on 0xB0 address and tried to start the motor... nothing happens... Here is the master program:
Code:

#include <16F876.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#use I2C(master, SDA=PIN_C4, scl=PIN_C3)
unsigned int i=0, pin_state=0, state=0, last_state=0;

void main() {
    delay_ms(1000);
    printf("Starting up\n");
    printf("Delaying 5 seconds...\n");
    delay_ms(5000);
    set_tris_b(0x01);
    output_low(PIN_B1); // Select MUX157
    output_low(PIN_B2); // A
    output_low(PIN_B3); // B
    output_low(PIN_B4); // C
    i2c_start();
       i2c_write(0xB0);
       i2c_write(0x00);
       i2c_write(0x01);
   delay_ms(5000);
    i2c_stop();
      
while ( 1 )
    {
   for (i = 0; i<=7; i++)
   {
       if( !bit_test(i,0) )
       {
             output_low(PIN_B2);
         delay_us(20);   
       }
           else
       {   
              output_high(PIN_B2);
         delay_us(20);
       }
   
       if( !bit_test(i,1) )
       {
         output_low(PIN_B3);
         delay_us(20);
       }
           else   
       {
              output_high(PIN_B3);
         delay_us(20);
       }
      
       if( !bit_test(i,2) )
       {
         output_low(PIN_B4);
         delay_us(20);
       }
           else   
       {
              output_high(PIN_B4);
         delay_us(20);
       }
   
   pin_state = input(PIN_B0);
   if (pin_state)
       bit_set(state,i);
   else
       bit_clear(state,i);
   }
   delay_us(20);
        if ( state != last_state  )
        {
       output_high(PIN_B5);
       printf("Input = %3u\n", state);
       last_state = state;
       delay_us(20);
        }
   else
   {
       output_low(PIN_B5);
       delay_us(20);
   }
    }
    printf("Done :)\r\n");
    delay_ms(20);
}


The while loop is used to read some digital inputs of 3 multiplexers and works fine. The master SDA is connected to slave SDA ... same for SCL.
I wonder if there is something else that needs to be set in order to get it work.

Thank you
horkesley



Joined: 20 Feb 2007
Posts: 48
Location: Essex UK

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Sat Jun 07, 2008 1:59 am     Reply with quote

Hi,

At the risk of offending you, a simple question, have you got pull up resistors on SDA, SCL?

Regards
_________________
Horkesley Electronics Limited
c0de



Joined: 14 May 2007
Posts: 14

View user's profile Send private message

PostPosted: Sat Jun 07, 2008 2:47 am     Reply with quote

horkesley wrote:
Hi,

At the risk of offending you, a simple question, have you got pull up resistors on SDA, SCL?

Regards


Hi. You are not offending me Very Happy I'm a beginner and I accept any advices. The answer is no... I dont have pull ups on SDA and SCL. I'll try with pullups and come back with the result.
Thank you:)
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