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

Problem with i2c_start() condition

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



Joined: 07 Mar 2008
Posts: 28

View user's profile Send private message

Problem with i2c_start() condition
PostPosted: Sun Mar 16, 2008 2:49 am     Reply with quote

Hi Smile I have a strange problem with the i2c bus. The pic is in master mode and should transmit data over the i2c, which is received from rs232. Here is the code:
Code:
#include <16F877A.h>
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES HS                       //High speed Osc (> 4mhz)
#FUSES PUT                      //Power Up Timer
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD                    //No EE protection
#FUSES NOWRT                    //Program memory not write protected

#use delay(clock=10000000)

#use i2c(Master, sda=PIN_C4, scl=PIN_C3, force_hw)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)

#define START_BYTE 0x41

int c;
int value_X;
int value_Y;

void INIT(void)
{
   setup_adc(ADC_CLOCK_INTERNAL);
   setup_adc_ports(NO_ANALOGS);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
}


void main()
{
   INIT();
   for(;;)
   {
      if(kbhit())
      {
         c = getc();
         if(c == START_BYTE)
         {
            value_X = getc();
            value_Y = getc();
            i2c_start();
            i2c_write(0x10);
            i2c_write(value_X);
            i2c_write(value_Y);
            i2c_stop();
         }
      }
   }
}


When i use the hardware i2c the PIC receives the data from rs232, but it stops at i2c_start() and i have to restart it. When i use software i2c this problem disapears... Any ideas why this happens ?
Thanks in advance Smile
P.S. The compiler is 4.057
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Mar 16, 2008 8:43 am     Reply with quote

Quote:
#use i2c(Master, sda=PIN_C4, scl=PIN_C3, force_hw)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)

#define START_BYTE 0x41

int c;
int value_X;
int value_Y;

void INIT(void)
{
setup_adc(ADC_CLOCK_INTERNAL);
setup_adc_ports(NO_ANALOGS);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED); // Delete this line
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
}

The setup_spi() statement re-configures the MSSP module.
It destroys the i2c mode setup that was done by the force_hw parameter.
To fix the problem, delete the line for setup_spi().
sv_shady



Joined: 07 Mar 2008
Posts: 28

View user's profile Send private message

PostPosted: Sun Mar 16, 2008 1:22 pm     Reply with quote

Thanks a lot Smile
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