Hola
Tras poner a comunicar por i2c un master con dos esclavos y mandarle datos a distintas direcciones
y ver que el terminal virtual de protesus me imprime ambas tramas, la de su direcion y la
de la otra, decido probar en placa, y le coloco unos led como banderas.
Otra cosa que no logro comprender porque si lo monto en placa parece hacer todo bien
excepto una cosa de los esclavos me enciende dos veces en vez de una.
me explico si del master enciendo led rojo cuando envio y cuando temino de enviar apago
en el esclavo enciende led rojo dentro de la interrupcion y cuando sale le apago desde el main y le enciendo led verde y retardo el apagado.
despues hace lo mismo con el segundo esclavo.
pero porque me parpadea dos veces si solo le puse una..
que cosa mas rara.
/*********************************************
*
* MASTER main_jn.c:
*
**********************************************/
#include "main_jn.h"
void main()
{
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_CLOCK_DIV_2);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
//Setup_Oscillator parameter not selected from Intr Oscillator Config tab
// TODO: USER CODE!!
int8 dato=0;
delay_ms(1000); //Hay que dejar tiempo que se inicialize el esclavo
while(true)
{
output_high(PIN_B7);
delay_ms(1000);
i2c_start(); // Condicion Inicio
i2c_write(PIC2);// Direccion dispositivo
delay_ms(3); // *** Necesario ***
i2c_write(dato);// dato
delay_ms(3); // *** Necesario ***
i2c_write(++dato);// dato
i2c_stop(); // Stop
output_low(PIN_B7);
delay_ms(1000);
output_high(PIN_B6);
delay_ms(1000);
i2c_start(); // Condicion Inicio
i2c_write(PIC3);// Direccion dispositivo
delay_ms(3); // *** Necesario ***
i2c_write(dato);// dato
delay_ms(3); // *** Necesario ***
i2c_write(++dato);// dato
i2c_stop(); // Stop
output_low(PIN_B6);
delay_ms(1000);
}
}
/*********************************************
*
* MASTER main_jn.h:
*
**********************************************/
#include <18F2550.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES XT //Crystal osc <= 4mhz for PCM/PCH , 3mhz to 10 mhz for PCD
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOBROWNOUT //No brownout reset
#FUSES BORV20 //Brownout reset at 2.0V
#FUSES NOPUT //No Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES NOPBADEN //PORTB pins are configured as digital I/O on RESET
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOCPB //No Boot Block code protection
#FUSES MCLR //Master Clear pin enabled
#FUSES LPT1OSC //Timer1 configured for low-power operation
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES PLL12 //Divide By 12(48MHz oscillator input)
#FUSES CPUDIV4 //System Clock by 4
#FUSES USBDIV //USB clock source comes from PLL divide by 2
#FUSES VREGEN //USB voltage regulator enabled
#use delay(clock=20000000)
#define I2C_SDA PIN_B0
#define I2C_SCL PIN_B1
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
#use i2c(Master,Slow,sda=PIN_B0,scl=PIN_B1)
//Leds que se iluminaran
#DEFINE LED1 PIN_B7 //PIN 3
#DEFINE PIC2 0x02 //Direccion dispositivo PIC 2 (esclavo)
#DEFINE PIC3 0x04 //Direccion dispositivo PIC 3 (esclavo)
/*********************************************
*
* MASTER main_s1_jn.c:
*
**********************************************/
#include "main_s1_jn.h"
//VARIABLES GLOBALES
int8 buffer[2];
int1 recibido=0;
#int_SSP
void SSP_isr(void) //Rutina Interrupción I2C
{
disable_interrupts(int_ssp); // *** Necesario ***
output_high(PIN_B7);
buffer[0]=i2c_read();
buffer[1]=i2c_read();
recibido=1;
}
void main()
{
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_CLOCK_DIV_2);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
//enable_interrupts(INT_SSP);
//enable_interrupts(GLOBAL);
//Setup_Oscillator parameter not selected from Intr Oscillator Config tab
// TODO: USER CODE!!
delay_ms(50);
//lcd_init();
//lcd_putc("fPreparado...");
printf("\n\r Preparado...");
delay_ms(300);
enable_interrupts(int_ssp);
enable_interrupts(global);
while(true)
{
if(recibido==1)
{
delay_ms(500);
output_low(PIN_B7);
output_high(PIN_B6);
delay_ms(500);
output_low(PIN_B6);
//printf(lcd_putc,"fb[0]=%U b[2]=%u",buffer[0],buffer[1]);
printf("\n\r fb[0]=%U b[2]=%u",buffer[0],buffer[1]);
recibido=0;
enable_interrupts(int_ssp); // *** Necesario ***
}
}
}
/*********************************************
*
* MASTER main_s1_jn.h:
*
**********************************************/
#include <18F2550.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOBROWNOUT //No brownout reset
#FUSES BORV20 //Brownout reset at 2.0V
#FUSES NOPUT //No Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES NOPBADEN //PORTB pins are configured as digital I/O on RESET
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOCPB //No Boot Block code protection
#FUSES MCLR //Master Clear pin enabled
#FUSES LPT1OSC //Timer1 configured for low-power operation
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES PLL12 //Divide By 12(48MHz oscillator input)
#FUSES CPUDIV4 //System Clock by 4
#FUSES USBDIV //USB clock source comes from PLL divide by 2
#FUSES VREGEN //USB voltage regulator enabled
#use delay(clock=20000000)
#define I2C_SDA PIN_B0
#define I2C_SCL PIN_B1
#DEFINE PIC2 0x02
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
#use i2c(Slave,Slow,sda=PIN_B0,scl=PIN_B1,address=PIC2)
#define use_portb_lcd TRUE //Necesario si usamos el portB para el LCD, y que sea compatible con LCD.C
#include <LCD.C>
Que le esta sucediendo al circuito ?
¿que se me pasa por alto y no deberia?
sigo con esto..