![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
sv_shady
Joined: 07 Mar 2008 Posts: 28
|
Problem with i2c_start() condition |
Posted: Sun Mar 16, 2008 2:49 am |
|
|
Hi 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
P.S. The compiler is 4.057 |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Mar 16, 2008 8:43 am |
|
|
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(). |
|
![](templates/subSilver/images/spacer.gif) |
sv_shady
Joined: 07 Mar 2008 Posts: 28
|
|
Posted: Sun Mar 16, 2008 1:22 pm |
|
|
Thanks a lot ![Smile](images/smiles/icon_smile.gif) |
|
![](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
|