The I2C protocol is a pain in the patoosie to understand.
I worked this one out for a Microchio 24C00 EEPROM, and MAYBE it can give you some help getting the range finder working.
This is a C program that talks through a driiver (that you don't have) through the PCI bus to this EEPROM.
Ignore most of everything, and concentrate on the eeprom_* routines.
You can contact me through this newsgroup for more help.
Good luck, (get an oscilloscope or better yet, a logic analyzer) and hang in there.
We've all been here before, and when you reach the other side you'll be very happy.
/* * tl_eeprom.c * * Basic revision G card EEPROM functionality test for Unix. * * This program implements an I2C protocol clocked-serial interface to a * Microchip 24C00 128-bit serial EEPROM * * The protocol will be difficult to understand without a thorough understanding * of the I2C protocol. * * See Microchip datasheet DS21178C for a description of the 24C00 EEPROM * * * I2C is a trademark of the Philips Corporation */
#include #include #include #include #include #include "ssepci.h" #include "ssepciioctl.h" #include "tl_eeprom.h"
void eeprom_init(int fdev); void eeprom_start(int fdev); void eeprom_stop(int fdev); unsigned long eeprom_read_ioctl(int fdev); void eeprom_write_ioctl(int fdev, unsigned long val); int eeprom_write_byte(int fdev, int address, unsigned char data); unsigned char eeprom_read_byte(int fdev, unsigned int address); unsigned char eeprom_get_ack(int fdev); void eeprom_send_ack(int fdev);
int board_init(int fdev);
void main() { int fdev; char strbuffer[80]; int i;
sprintf(strbuffer, "/dev/sse%d", 0);
/* Open the device */ if ((fdev = open(strbuffer, O_RDWR)) == -1) { switch (errno) { case ENOENT: printf("Board (%s) does not exist.\n", strbuffer); break; case EBUSY: printf("Board (%s) is in use.\n", strbuffer); break; default: printf("Board (%s): open failed with error %d.\n", strbuffer, errno); } } else { printf("tl_eeprom: Checking EEPROM on device %s\n", strbuffer); board_init(fdev);
eeprom_init(fdev);
for (i = 0; i < 8; i++) eeprom_write_byte(fdev, i, 0x10 + i); for (i = 8; i < 16; i++) eeprom_write_byte(fdev, i, 0x50 + i);
for (i = 0; i < 16; i++) printf("0x%02x ", eeprom_read_byte(fdev, i)); printf("\n");
close(fdev);
} }
int board_init(int fdev) { uint32_t arg[32];
/* First get the board count */ if (ioctl(fdev, IOCTL_SSEPCI_GET_BOARDCOUNT) == -1) { printf("tl_eeprom: error getting board count\n"); return (0); } /* Soft reset */ if (ioctl(fdev, IOCTL_SSEPCI_SOFT_RESET) == -1) { printf("tl_eeprom: error in soft reset on device\n"); return (0); } /* Program the clock */ arg[0] = CLOCK_35; if (ioctl(fdev, IOCTL_SSEPCI_SET_PLL, arg, O_RDWR, NULL, NULL) == -1) { printf("tl_eeprom: error setting clock\n"); return (0); } return(1); }
/*****************/ void eeprom_init(fdev) { eeprom_write_ioctl(fdev, EEPROM_SDA_ENABLE | EEPROM_SDA_HIGH | EEPROM_SCL_HIGH); eeprom_write_ioctl(fdev, EEPROM_SDA_ENABLE | EEPROM_SDA_HIGH | EEPROM_SCL_LOW); eeprom_stop(fdev); /* Issue several stops to insure proper reset */ eeprom_stop(fdev); eeprom_stop(fdev); eeprom_stop(fdev); }
void eeprom_stop(fdev) { eeprom_write_ioctl(fdev, EEPROM_SDA_ENABLE | EEPROM_SDA_LOW | EEPROM_SCL_LOW); eeprom_write_ioctl(fdev, EEPROM_SDA_ENABLE | EEPROM_SDA_LOW | EEPROM_SCL_HIGH); eeprom_write_ioctl(fdev, EEPROM_SDA_ENABLE | EEPROM_SDA_HIGH | EEPROM_SCL_HIGH); }
void eeprom_start(fdev) { eeprom_write_ioctl(fdev, EEPROM_SDA_ENABLE | EEPROM_SDA_HIGH | EEPROM_SCL_HIGH); eeprom_write_ioctl(fdev, EEPROM_SDA_ENABLE | EEPROM_SDA_LOW | EEPROM_SCL_HIGH); eeprom_write_ioctl(fdev, EEPROM_SDA_ENABLE | EEPROM_SDA_LOW | EEPROM_SCL_LOW); eeprom_write_ioctl(fdev, EEPROM_SDA_ENABLE | EEPROM_SDA_HIGH | EEPROM_SCL_LOW); }
void eeprom_putbyte(int fdev, unsigned char data) { int i; int bitvalue;
for (i = 0; i < 8; i++) { bitvalue = (((data & 0x80) >> 7) & 1); if (bitvalue == 1) { eeprom_write_ioctl(fdev, EEPROM_SDA_ENABLE | EEPROM_SDA_HIGH | EEPROM_SCL_LOW); eeprom_write_ioctl(fdev, EEPROM_SDA_ENABLE | EEPROM_SDA_HIGH | EEPROM_SCL_HIGH); eeprom_write_ioctl(fdev, EEPROM_SDA_ENABLE | EEPROM_SDA_HIGH | EEPROM_SCL_LOW); } else { eeprom_write_ioctl(fdev, EEPROM_SDA_ENABLE | EEPROM_SDA_LOW | EEPROM_SCL_LOW); eeprom_write_ioctl(fdev, EEPROM_SDA_ENABLE | EEPROM_SDA_LOW | EEPROM_SCL_HIGH); eeprom_write_ioctl(fdev, EEPROM_SDA_ENABLE | EEPROM_SDA_LOW | EEPROM_SCL_LOW); } data