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

16F88 Master & Slave Mode

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



Joined: 29 May 2004
Posts: 41
Location: Barcelona, Spain

View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger

16F88 Master & Slave Mode
PostPosted: Tue Jun 15, 2004 10:56 am     Reply with quote

I've adapted these codes from a 16F877 to a 16F88 with internal oscillator at 8 MHz. The Idea is to transmit data with I2C protocol between two 16F88 and a PCF8574 I/O Expander. The I/O works fine but the 16F88 in Slave mode doesn't works. Anybody knows why?

Thanx in advance.

Joan.

-------------------------------------------------------------------------------

For Master:

/* Standard Include for 16F88 Chip */
#include <16F88.h>
#byte OSCCON = 0x8F
#fuses NOWDT,NOPROTECT,NOLVP, NOMCLR, INTRC_IO

/* Delay for 8 mhz crystal */
#use delay (clock=8000000)

/* Setup RS232 */
#use RS232(baud=9600, xmit=PIN_A4,rcv=PIN_A5, INVERT)

/* Setup I2C */
#use I2C(MASTER, SDA=PIN_B1, SCL=PIN_B4, SLOW)

#define LED PIN_A1

main()
{
int8 i2c_command = 66;
int dato;
dato=0b10000000;
OSCCON = 0x7C;

while (true)
{

delay_ms(1000);
printf("Outputting: %c", i2c_command);

/* Master */
i2c_start(); // Start condition
i2c_write(0xa0); // Device address
i2c_write(i2c_command); // Write Command
i2c_stop(); // Stop condition

delay_ms (125);

//i2c_start(); // Condici�n de inicio en el bus I2C
//i2c_write(0b01110000); // Direcci�n (modo escritura) del dispositivo PCF8574
//rotate_right( &dato, 1);
//i2c_write(dato); // Se env�a el dato al PCF8574
//i2c_stop(); // Condici�n de stop

output_high(LED);
delay_ms(100);
output_low(LED);
delay_ms(100);
output_high(LED);
delay_ms(100);
output_low(LED);
delay_ms(100);

}
}

-------------------------------------------------------------------------------

For Slave:


/* Standard Include for 16F88 Chip */
#include <16F88.h>
#byte OSCCON = 0x8F
#fuses NOWDT,NOPROTECT,NOLVP, NOMCLR, INTRC_IO

/* Delay for 8 mhz crystal */
#use delay (clock=8000000)

/* Setup RS232 */
#use RS232(baud=9600, xmit=PIN_A4,rcv=PIN_A5, INVERT)

/* Setup I2C */
#use I2C(SLAVE, SDA=PIN_B1, SCL=PIN_B4, address=0xa0, SLOW)

#define LED PIN_A1

#INT_SSP
void ssp_interupt ()
{
byte incoming;
incoming = i2c_read();
incoming = i2c_read();

output_high(LED);
delay_ms(1);
output_low(LED);
delay_ms(1);

}


main()
{
OSCCON = 0x7C;

delay_ms(500);
enable_interrupts(GLOBAL);
enable_interrupts(INT_SSP);



while (true)
{

}
}

-------------------------------------------------------------------------------
ben500



Joined: 15 Jun 2004
Posts: 1

View user's profile Send private message

I2C: slave mode
PostPosted: Wed Jun 16, 2004 1:47 am     Reply with quote

It seams to have a lot of people who have that kind of problem: the slave does not acknowledge received bytes! Nobody knows the solution?
Is possible that it comes from compatibility between PICs or oscillator frequency or fuses or ...? I'm a newbie in pic programming so I can not see from where it could come from. Can someone help, please?
THANKS!
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