|
|
View previous topic :: View next topic |
Author |
Message |
arunb
Joined: 08 Sep 2003 Posts: 492 Location: India
|
Strange problem with i2c slave on 16F690 [Solved] |
Posted: Mon Sep 30, 2013 1:20 pm |
|
|
Hi,
PCM: 3.249
MPLAB IDE: 8.60
Device: 16F690
I am trying to setup the 16F690 as an i2c slave. I used the EX_SLAVE.c code example for this. This works very well.
But when I add set_tris_a, set_tris_b, set_tris_c functions, the i2c communication stops and the 16F690 does not respond.
The same problem occurs when using enable_interrupt(INT_RDA).
The working code is given below.
Code: | #include <16F690.h>
#fuses INTRC_IO,NOWDT,PUT,NOPROTECT,NOCPD,NOBROWNOUT,NOIESO,NOMCLR,NOFCMEN
#use delay(clock=4000000)
#use rs232(baud=9600,xmit=pin_b7, rcv=pin_b5,parity=n,errors)
#use i2c(SLAVE,slow,SDA=pin_b4,SCL=pin_b6,address=0xA7)
BYTE address,buffer[0x10];
#INT_RDA
void usart()
{
}
#INT_SSP
void ssp_interupt()
{
BYTE incoming,state;
state=i2c_isr_state();
if (state<0x80) //Master is sending data
{
incoming=i2c_read();
if (state==1) //First received byte is address
address=incoming;
if (state==2) //Second received byte is data
buffer[address]=incoming;
}
if (state==0x80) //Master is requesting data
{
i2c_write(buffer[address]);
}
}
#zero_ram
void initialise()
{
setup_oscillator(OSC_INTRC|OSC_4MHZ);
setup_comparator(NC_NC_NC_NC);
// set_tris_a(0b11111111);
// set_tris_b(0b00101111);
// set_tris_c(0b00110111);
// enable_interrupts(INT_RDA);
enable_interrupts(INT_SSP);
enable_interrupts(GLOBAL);
}
void main()
{
initialise();
do{
}while(TRUE);
}
|
the problem starts when the set_tris_a, set_tris_b, set_tris_c and enable_interrupts(INT_RDA) lines are un-commented.
I am powering the 16F690 with a 3.3V supply, the pullups are 3.9K. However I don't think the problem is with the supply as the example code works very well.
Please help...
thanks
a |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Sep 30, 2013 1:33 pm |
|
|
Quote: | #INT_RDA
void usart()
{
} |
The source of the interrupt is the fact that there is a character sitting in
the UART's receive buffer. If you don't read the character (which removes
it from the buffer), it will sit there in the buffer and you will get an
interrupt over and over again. The program will appear to lock up.
To prevent this, read the character with getc() inside the #int_rda routine.
Quote: | #use i2c(SLAVE,slow,SDA=pin_b4,SCL=pin_b6,address=0xA7) |
#use i2c does not want an odd slave address. Change it to an even address. |
|
|
alan
Joined: 12 Nov 2012 Posts: 357 Location: South Africa
|
|
Posted: Mon Sep 30, 2013 1:34 pm |
|
|
As far as I know the SDA and SCL pins should be inputs.
Regards |
|
|
arunb
Joined: 08 Sep 2003 Posts: 492 Location: India
|
re |
Posted: Mon Sep 30, 2013 1:43 pm |
|
|
thanks for the reply, i shall try this out.
but why does the i2c communication lock up when only the set tris functions are used (no rda interrupt).
thanks
a |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
arunb
Joined: 08 Sep 2003 Posts: 492 Location: India
|
re |
Posted: Tue Oct 01, 2013 1:02 pm |
|
|
thanks for the reply, i made all the unused ports as input and pulled them high, its working well now,
thanks
a |
|
|
|
|
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
|