Autor Tema: Problema comunicación RS232/i2c memoria 24lc256 tutorial suky  (Leído 1331 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado nahuelgdy

  • PIC10
  • *
  • Mensajes: 5
Problema comunicación RS232/i2c memoria 24lc256 tutorial suky
« en: 29 de Marzo de 2019, 16:18:50 »
Hola buen día a todos! tengo un problema no me estaría funcionando mi programa: les adjunto el código, básicamente hice unas leves modificaciones al tutorial de suky nada más. Hice la prueba con el docklight y recibo como ruido solamente y ahora pareciera que estoy recibiendo algo pero no todo lo que transmití. Si alguien pudiera darme una mano como para orientarme un poco me ayudaría bastante.
Desde ya gracias. Les adjunto foto de lo que recibo en docklight.


#include <p18f2550.h>
#include <usart.h>
#include <delays.h>
#include <i2c.h>
#include <stdio.h>
#include <stdlib.h>


#pragma config FOSC=HS,PLLDIV=5,USBDIV=2,FCMEN=OFF,IESO=OFF,CPUDIV=OSC1_PLL2
#pragma config PWRT=ON,BOR=OFF,BORV=0,WDT=OFF,WDTPS=32768
#pragma config MCLRE=ON,LPT1OSC=OFF,PBADEN=OFF,CCP2MX=OFF
#pragma config STVREN=OFF,LVP=OFF,XINST=OFF,DEBUG=OFF
#pragma config CP0=OFF,CP1=OFF,CP2=OFF,CPB=OFF,CPD=OFF
#pragma config WRT0=OFF,WRT1=OFF,WRT2=OFF
#pragma config WRTB=OFF,WRTC=OFF,WRTD=OFF
#pragma config EBTR0=OFF,EBTR1=OFF,EBTR2=OFF,EBTRB=OFF


volatile char Data, datorecibido;
void HighISR(void);

void ByteWriteI2C(unsigned char ByteControl, unsigned char HighDireccion,
           unsigned char LowDireccion, unsigned char DataI2C);
unsigned char ByteReadI2C(unsigned char ByteControl, unsigned char HighDireccion,
           unsigned char LowDireccion);

// creo una nueva sección de código a partir de la dirección 0x08

#pragma code HighVector=0x0008  // en que dirección va a estar la interrupción
void IntHighVector(void)
{
_asm goto HighISR _endasm
}
#pragma code

// cierro sección

//rutina de interrupción

#pragma interrupt HighISR
void HighISR(void)
{

if (PIR1bits.RCIF==1); // si hay datos para leer en el buffer de recepción
{

Data=getcUSART();
datorecibido=1; // se recibió un dato
PIR1bits.RCIF=0; // borro bandera, el buffer ahora está vacío
}
}

//fin de rutina de interrupción



void main (void)
{

 OpenUSART(USART_TX_INT_OFF &
   USART_RX_INT_ON &
   USART_ASYNCH_MODE &
   USART_EIGHT_BIT &
   USART_CONT_RX &
   USART_BRGH_HIGH,129); //9600 BAUDIOS,8 bits , osc de 20 Mhz
OpenI2C(MASTER,SLEW_OFF);
SSPADD=49; // 100 Khz para osc de 20 Mhz
datorecibido=0;
RCONbits.IPEN=0; // deshabilitamos prioridades
INTCONbits.PEIE= 1;// activamos interrupción de periféricos
INTCONbits.GIE=1;// activamos las interrupciones globales
putrsUSART("prueba comunicación i2c con memoria 24lc512 \r\r");
putrsUSART("\r");
while(1)
{
while(datorecibido==0)
{
}
datorecibido=0;
ByteWriteI2C(0xA0,0x00,0x00,Data);
Delay1KTCYx(5);
putrsUSART("lectura de eeprom: \r");
putcUSART(ByteReadI2C(0xA0,0x00,0x00));

}

}

void ByteWriteI2C(unsigned char ByteControl, unsigned char HighDireccion,
        unsigned char LowDireccion, unsigned char DataI2C)
{
IdleI2C();
StartI2C();
while (SSPCON2bits.SEN);
WriteI2C(ByteControl);
WriteI2C(HighDireccion);
WriteI2C(LowDireccion);
WriteI2C(DataI2C);
StopI2C();
while (SSPCON2bits.SEN);
while (EEAckPolling(ByteControl));
}


unsigned char ByteReadI2C(unsigned char ByteControl, unsigned char HighDireccion,
           unsigned char LowDireccion)
{
unsigned char Valor;
IdleI2C();
StartI2C();
while (SSPCON2bits.SEN);
WriteI2C(ByteControl);
WriteI2C(HighDireccion);
WriteI2C(LowDireccion);
RestartI2C();
while(SSPCON2bits.RSEN); //mientras que el bit RSEN esté en 1 se reinicia la comunicación
WriteI2C(ByteControl | 0x01);
Valor=ReadI2C();
NotAckI2C();
StopI2C();
while (SSPCON2bits.ACKEN);// si ACKEN es 1 se habilita el envío del Ack por parte del maestro
return (Valor);
}



 

anything