
Buenas amigos un saludo luego de pasar por el buscador no consigo solventar mi duda y se la expongo a ver si logran ver algún error del cual no me he percatado, ya que el dspic30f4013 al momento que le llega el dato desde el maestro usando la dirección de esclavo específica para este, simplemente se para la comunicación y los pic se trancan.
Acá les dejo el código en CCS donde básicamente recib0 una cadena por i2c al dspic30f4013 en modo esclavo desde el maestro un 18f4550 y en el caso de que el maestro necesite datos del esclavo este le retorna una cadena.
Este código funciona correctamente para recibir los datos del maestro y para responderle ya que fue probando con el pic 16f1503 satisfactoriamente en modo esclavo solo que al pasar el codigo al dspic ya no funciona y cuelga el bus completo el cual tiene 8 esclavos funcionando perfectamente con el mismo codigo solo que todos los esclavos son 16f1503.
Gracias por cualquier ayuda
///////////////////////////////////////////////////////////////////////////////////////////////////
// PIC
///////////////////////////////////////////////////////////////////////////////////////////////////
#include <30F4013.h>
#device ADC = 12 //ADC 12 bits
//#device *=16
//#device PASS_STRINGS=IN_RAM
//#device ICSP=1
///////////////////////////////////////////////////////////////////////////////////////////////////
// Fuses y ajuste de Clock
///////////////////////////////////////////////////////////////////////////////////////////////////
//#FUSES HS // High speed clock
//#FUSES HS2_PLL4 // Crystal osc <= 4mhz for PCM/PCH , 3mhz to 10 mhz for
#FUSES HS2_PLL8 // The xtal freq is divided by 2 and multiplied by 8 (maximum using 20MHz xtal)
#FUSES NOCKSFSM // Clock Switching is disabled, fail Safe clock monitor is disabled
#FUSES PUT64 // Power On Reset Timer value
#FUSES NOBROWNOUT // No brownout reset
#FUSES NOMCLR // Master Clear pin enabled
#FUSES NOPROTECT // Code not protected from reading
#FUSES WPSA512
#FUSES WPSB16
#FUSES NOWDT // No Watch Dog Timer
#FUSES NOWRT // Program memory not write protected
#FUSES NODEBUG // No Debug mode for ICD
#FUSES ICSP1 // ICD uses PGC1/PGD1 pins
#FUSES RESERVED // Used to set the reserved FUSE bits
#use delay(clock=80000000) // 20MHz / 2 * 8 = 80MHz = 80000000
//#use delay(clock=20Mhz, crystal) // A 20 Mhz crystal is used
//#use delay(crystal=20Mhz, clock=40Mhz) // A 20 Mhz crystal is used
///////////////////////////////////////////////////////////////////////////////////////////////////
// Configuracion de puertos
///////////////////////////////////////////////////////////////////////////////////////////////////
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
#use fast_io(D)
#use fast_io(F) // PARA PERMITIRNOS CONFIGURAR MANUALMENTE
///////////////////////////////////////////////////////////////////////////////////////////////////
// Canal de Comunicación : I2C
///////////////////////////////////////////////////////////////////////////////////////////////////
#define SDA_i2c PIN_F2
#define SCL_i2c PIN_F3
#USE I2C(SLAVE, sda=SDA_i2c, scl=SCL_i2c, ADDRESS=0x18, FORCE_HW, FAST=400)
//#USE I2C(SLAVE, sda=SDA_i2c, scl=SCL_i2c, ADDRESS=0x18, FORCE_HW, FAST)
//#USE I2C(SLAVE, I2C1 , ADDRESS=0x18, FORCE_HW, FAST)
///////////////////////////////////////////////////////////////////////////////////////////////////
// DECLARACIONES
///////////////////////////////////////////////////////////////////////////////////////////////////
#define DELAY 1000
int1 FLAG_have_string = FALSE;
unsigned int8 count_i2c_data;
int8 j=0;
#define lenbuff_string_i2c 7
char string_i2c[lenbuff_string_i2c] = {'\0','\0','\0','\0','\0','\0','\0'};
#define lenbuff_string_i2c_return 32
char string_i2c_return[lenbuff_string_i2c_return] = {'H','O','L','A','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','\0'};
//{'\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0'};
char temporal_string[6];
///////////////////////////////////////////////////////////////////////////////////////////////////
// Configuracion de los puertos del PIC
///////////////////////////////////////////////////////////////////////////////////////////////////
// 1=input,0=output 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
// x x x x x x x x x x x x x x x
// IRX_A_TRIS 0b 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
// x x x x x x
// IRX_B_TRIS 0b 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1
// x x x x x x x x x x x x x x
// IRX_C_TRIS 0b 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
// x x x x x x x x x x x x
// IRX_D_TRIS 0b 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
// x x x x x x x x x
// IRX_F_TRIS 0b 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0
#define IRX_A_TRIS 0b0000000000000000
#define IRX_B_TRIS 0b0001111000000011
#define IRX_C_TRIS 0b0000000000000000
#define IRX_D_TRIS 0b0000000000000000
#define IRX_F_TRIS 0b0000000000000000
///////////////////////////////////////////////////////////////////////////////////////////////////
// limpia la memoria
///////////////////////////////////////////////////////////////////////////////////////////////////
#ZERO_RAM
///////////////////////////////////////////////////////////////////////////////////////////////////
// Modelado de funciones
///////////////////////////////////////////////////////////////////////////////////////////////////
void Inicializacion(void);
///////////////////////////////////////////////////////////////////////////////////////////////////
// INTERRUPCIONES
///////////////////////////////////////////////////////////////////////////////////////////////////
#INT_SI2C
void si2c_interrupt()
{
char state,incoming;
state = i2c_isr_state();
if(state < 0x80)//Master envia datos
{
incoming = i2c_read();//An array will be needed to store data if more than one byte is transferred
if (state == 0)
{
count_i2c_data = 0; //here need to read but not store
j = 0;
}
else
{
string_i2c[count_i2c_data++] = incoming;
if ( incoming == 0 )
FLAG_have_string=TRUE;
}
}
if(state >= 0x80)//Master pide datos
{
i2c_write(string_i2c_return[j++]); // send actual data
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// INICIALIZACION DE VARIABLES
///////////////////////////////////////////////////////////////////////////////////////////////////
void Inicializacion(void)
{
//setup_oscillator(OSC_CRYSTAL, 20000000);
SET_TRIS_A(IRX_A_TRIS);
SET_TRIS_B(IRX_B_TRIS);
SET_TRIS_C(IRX_C_TRIS);
SET_TRIS_D(IRX_D_TRIS);
SET_TRIS_F(IRX_F_TRIS);
ENABLE_INTERRUPTS(INT_SI2C);
//ENABLE_INTERRUPTS(INT_MI2C);
ENABLE_INTERRUPTS(INTR_GLOBAL);
}
void comprobar_i2c_string(void)
{
int8 z;
if(FLAG_have_string == TRUE)
{
FLAG_have_string = FALSE;
output_toggle(PIN_C14);
for(z = 0;z<lenbuff_string_i2c;z++) // Bucle que pone a 0 todos los
{
string_i2c[z]='\0'; // caracteres en el buffer
}
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// MAIN
///////////////////////////////////////////////////////////////////////////////////////////////////
void main(void)
{
Inicializacion(); // INICIALIZACION DE VARIABLES
delay_ms(DELAY);
while(TRUE)
{
comprobar_i2c_string();
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// FIN MAIN
///////////////////////////////////////////////////////////////////////////////////////////////////