SRF08 Problems - Only one long flash at startup, is this a common problem?

Hi, I'm having problems interfacing with a SRF08 via a HCS12. When you connect it its ment to flash out its IIC address. I.e. one long pulse
then flash out the address. Firstly mine just does one long pulse, secondly how do you work out the address from a bunch of flashes? Do you have to time them, like 1 sec no flash then its a 0, next sec flash so 1 for that bit and so on? I'm not getting any responces from the device. In all probablity thats more down to my program but the lack of the address pulses is a bit of a concern. Esspecially since I've been trying to get it work for quite some time. I've had a look around on here and some other places but haven't seen anything on this particular problem. I also tried addressing the genral broadcast address 0x00 too to see if that prompted a responce to no avail. Is it syptimatic of a possible electrical connection problem?
Any ideas or suggestions or random thoughts on what it could be would be greatly appreciated.
Cheers Andy
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
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 * <http://www.microchip.com/download/lit/pline/memory/ic/21178c.pdf * * I2C is a trademark of the Philips Corporation */
#include <stdio.h> #include <fcntl.h> #include <errno.h> #include <stdlib.h> #include <unistd.h> #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 <<= 1;     }     eeprom_write_ioctl(fdev, EEPROM_SDA_DISABLE | EEPROM_SCL_LOW); }
unsigned char eeprom_getbyte(int fdev) {     int i;     int bitvalue;     unsigned char returnvalue;
    returnvalue = 0;     for (i = 0; i < 8; i++) {         eeprom_write_ioctl(fdev, EEPROM_SDA_DISABLE | EEPROM_SCL_HIGH);         bitvalue = EEPROM_DATA(eeprom_read_ioctl(fdev));         returnvalue <<= 1;         returnvalue |= (bitvalue & 1);         eeprom_write_ioctl(fdev, EEPROM_SDA_DISABLE | EEPROM_SCL_LOW);     }     eeprom_write_ioctl(fdev, EEPROM_SDA_ENABLE | EEPROM_SDA_HIGH | EEPROM_SCL_LOW);     return (returnvalue); }
unsigned long eeprom_read_ioctl(int fdev) {     int retval;     unsigned long val;     retval = ioctl(fdev, (4 << 16) | IOCTL_SSEPCI_READ_QL5604_PROM,          &val, O_RDWR, NULL, NULL);     if (retval != 0) {         printf("ioctl failed at %s %d\n", __FILE__, __LINE__);         perror("ioctl");     }     return (val); }
void eeprom_send_ack(int fdev) {     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); }
unsigned char eeprom_get_ack(int fdev) {     int val;
    eeprom_write_ioctl(fdev, EEPROM_SDA_DISABLE | EEPROM_SCL_HIGH);     val = EEPROM_DATA(eeprom_read_ioctl(fdev));     eeprom_write_ioctl(fdev, EEPROM_SDA_DISABLE | EEPROM_SCL_LOW);     return (val); }
void eeprom_write_ioctl(int fdev, unsigned long val) {     int retval;     retval = ioctl(fdev, (4 << 16) | IOCTL_SSEPCI_WRITE_QL5604_PROM,          &val, O_RDWR, NULL, NULL);     if (retval != 0) {         printf("ioctl failed at %s %d\n", __FILE__, __LINE__);         perror("ioctl");     } }
int eeprom_read_array(int fdev, unsigned char *buffer, unsigned int bytestoread) {     unsigned char command = EEPROM_DEVICE_ADDRESS;     int i;
    if (bytestoread > EEPROM_SIZE)         bytestoread = EEPROM_SIZE;
    command |= EEPROM_READ_MODE;    /* turn on read-mode */
    usleep(10);     eeprom_start(fdev);
    eeprom_putbyte(fdev, command);     if (eeprom_get_ack(fdev) != EEPROM_ACK) {         printf("eeprom_read_array() failed to get ack\n");         eeprom_stop(fdev);         return (0);     }     for (i = 0; i < bytestoread; i++) {         *(buffer + i) = eeprom_getbyte(fdev);         eeprom_send_ack(fdev);     }
    eeprom_stop(fdev);     return (i); }
int eeprom_write_byte(int fdev, int address, unsigned char data) {     unsigned char command = EEPROM_DEVICE_ADDRESS;
    command &= ~EEPROM_READ_MODE;    /* Turn on write-mode */
    eeprom_start(fdev);
    eeprom_putbyte(fdev, command);     if (eeprom_get_ack(fdev) != EEPROM_ACK) {         printf("eeprom_write_byte() failed to get ack 0\n");         eeprom_stop(fdev);         return (0);     }     eeprom_putbyte(fdev, address);     if (eeprom_get_ack(fdev) != EEPROM_ACK) {         printf("eeprom_write_byte() failed to get ack 1\n");         eeprom_stop(fdev);         return (0);     }     eeprom_putbyte(fdev, data);     if (eeprom_get_ack(fdev) != EEPROM_ACK) {         printf("eeprom_write_byte() failed to get ack 2\n");         eeprom_stop(fdev);         return (0);     }     eeprom_stop(fdev);    /* the eeprom_stop state begins the EEPROM                  * write-cycle */     usleep(5000);        /* EEPROM write cycle is 4 milliSeconds                  * maximum */     return (1); }
unsigned char eeprom_read_byte(int fdev, unsigned int address) {     unsigned char command = EEPROM_DEVICE_ADDRESS;     unsigned char val;
    command &= ~EEPROM_READ_MODE;    /* turn on write-mode */
    eeprom_start(fdev);
    eeprom_putbyte(fdev, command);     if (eeprom_get_ack(fdev) != EEPROM_ACK) {         printf("eeprom_read_byte() failed to get ack\n");         eeprom_stop(fdev);         return (0);     }     eeprom_putbyte(fdev, address);    /* Start at address zero */     if (eeprom_get_ack(fdev) != EEPROM_ACK) {         printf("eeprom_read_byte() failed to get ack\n");         eeprom_stop(fdev);         return (0);     }     eeprom_start(fdev);    /* Multi-start condition for this command */
    command |= EEPROM_READ_MODE;    /* turn on read-mode */
    eeprom_putbyte(fdev, command);     if (eeprom_get_ack(fdev) != EEPROM_ACK) {         printf("eeprom_read_byte() failed to get ack\n");         eeprom_stop(fdev);         return (0);     }     val = eeprom_getbyte(fdev);     eeprom_send_ack(fdev);
    eeprom_stop(fdev);     return (val); }
--
- Alan Kilian <alank(at)timelogic.com>
Director of Bioinformatics, TimeLogic Corporation 763-449-7622
  Click to see the full signature.
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Andy,
You see normal behaviour, read: http://www.robot-electronics.co.uk/htm/srf08tech.shtml
0 short flashes means addr 0xe0
What platform are you on? There are a lot of programming examples on Gerry's site.
As a matter of fact, he has examples for 14 different platforms!!!! Odds are, that your platform is among those.
Bram
On 6 Apr 2004 19:32:37 -0700 andy snipped-for-privacy@yahoo.com (Dervish) wrote:

--
------------------------------------------------------------------------------
Bram Stolk, VR Engineer.
  Click to see the full signature.
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Excelent, thanks for that. I just wasn't sure if it was correct. You know when your developing software and keep trying differnt things and it still doesn't work you start to wonder if it's a hardware issue. Especially after awhile. But at least I now know the SRF08 isn't malfunctioning. Makes the thread title look a bit stupid tho huh? It must be my code. I'm using a HCS12 IIC module and doing it in assembler. I've had a look at some C programs which do work with the module but to my eyes my prog should do the same really. So I'll just need to keep trying I guess. Thanks for the help tho guys.
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
I got it ranging! Finally! Seriously I'm exstatic!!! Who of ever thought that a little LED flashing to show it's ranging whould evr bring someone so much joy? Robotics you gotta love it! :)
Thanks for the tips guys, if I didn't know that LED flashing at the start was normal I probebly wouldn't of kept trying for awhile. Cheers guys.
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

Polytechforum.com is a website by engineers for engineers. It is not affiliated with any of manufacturers or vendors discussed here. All logos and trade names are the property of their respective owners.