Joan
Joined: 29 May 2004 Posts: 41 Location: Barcelona, Spain
|
16F88 Master & Slave Mode |
Posted: Tue Jun 15, 2004 10:56 am |
|
|
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)
{
}
}
------------------------------------------------------------------------------- |
|