Hola a todos, necesitaría saber si a alguien le ha funcionado el ejemplo que proporciona el CCS, sobre grabación de memoria externa serie, via I2C (ex_extee.c)
La verdad es que cuando ejecuto el programa y estoy apunto de leer o escribir, el micro se cuelga y muere la aplicación. La memoria es una 24c16.
Alguien saber porqué?
Cómo puedo solucionarlo?
Me podeis enviar alguna rutina para leer o escribir en una memoria serie 24c16 mediante el I2C?
Aqui os envío el programa de ejemplo del CCS.
Salu2 y gracias
FICHERO ----> ex_extee.c
#if defined(__PCB__)
#include <16c56.h>
#fuses HS,NOWDT,NOPROTECT
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_A3, rcv=PIN_A2) // Jumpers: 11 to 17, 12 to 18
#elif defined(__PCM__)
#include <16F877.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) // Jumpers: 8 to 11, 7 to 12
#elif defined(__PCH__)
#include <18F452.h>
#fuses HS,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) // Jumpers: 8 to 11, 7 to 12
#endif
#include <input.c>
#include <2402.c>
void main() {
byte value,cmd;
EEPROM_ADDRESS address;
init_ext_eeprom();
do {
do {
printf("
Read or Write: "

;
cmd=getc();
cmd=toupper(cmd);
putc(cmd);
} while ( (cmd!="R") && (cmd!="W") );
printf("
Location: "

;
#if sizeof(EEPROM_ADDRESS)==1
address = gethex();
#else
#if EEPROM_SIZE>0xfff
address = gethex();
#else
address = gethex1();
#endif
address = (address<<

+gethex();
#endif
if(cmd=="R")
printf("
Value: %X
",READ_EXT_EEPROM( address ) );
if(cmd=="W") {
printf("
New value: "

;
value = gethex();
printf("
"

;
WRITE_EXT_EEPROM( address, value );
}
} while (TRUE);
}
FICHERO ----> 24c16.c
#ifndef EEPROM_SDA
#define EEPROM_SDA PIN_B1
#define EEPROM_SCL PIN_B0
#endif
#use i2c(master,sda=EEPROM_SDA, scl=EEPROM_SCL)
#define EEPROM_ADDRESS long int
#define EEPROM_SIZE 2048
void init_ext_eeprom() {
output_float(eeprom_scl);
output_float(eeprom_sda);
}
void write_ext_eeprom(long int address, byte data) {
i2c_start();
i2c_write((0xa0|(byte)(address>>7))&0xfe);
i2c_write(address);
i2c_write(data);
i2c_stop();
delay_ms(11);
}
byte read_ext_eeprom(long int address) {
byte data;
i2c_start();
i2c_write((0xa0|(byte)(address>>7))&0xfe);
i2c_write(address);
i2c_start();
i2c_write((0xa0|(byte)(address>>7))|1);
data=i2c_read(0);
i2c_stop();
return(data);
}