AW: SRF08, Hardware I2C on ATMega32, and delays

"Andreas Trenkwalder" <[email protected]> Fri, 9 May 2003 19:01:17 +0200
Newsgroups gmane.comp.hardware.avr.general
Message-ID <001001c3164c$9f4c9e30$6401a8c0@FLITWICK>
> Has anyone on the list used the Hardware I2C on the mega parts to
> communicate with the SRF08 sonar modules?  
Yes, I'm working on it :)

> If so, have you ever had to
> use a delay between reading the registers of one module, and another?
I
> have to place a delay of like 200 or so nS between accesses of the
> modules, or the I2C bus just seems to hang...  
I couldn't notice such a behaviour. Maybe this is a issue with your I2C
driver. I adapted the I2C driver from the Procyon AVRlib
(http://hubbard.engr.scu.edu/avr/avrlib/) for my needs. This driver is
interrupt driven and based on a "state machine" which manages that the
I2C bus is only accessed when the last transmission is completed (= when
the bus is idle). 

> Do I really need this delay?  Am I doing something wrong, or has any
one
> else had the same issue?
> 
I need a delay only between sending the range command and getting the
result. While ranging the module does not respond on I2C activity, so
you will get always 0xff when you read a register. I used this to way
til ranging is complete (have a look to the code snipped at the bootom).

If you explain more detailed what you are doing I could do some test on
my setup after the weekend.

regrads,
Andreas


---
unsigned int srf08_ping(unsigned char range_unit)
{
  i2c_masterSendTwoBytes(address, SRF08_COMMAND, range_unit);       
  do
  { 
    i2c_masterSendByte(address, SRF08_ECHO_1);
  } while (((u08)i2c_masterReceiveWord(address)) == 0xFF);
  	
  i2c_masterSendByte(address, SRF08_ECHO_1);
  return (i2c_masterReceiveWord(address));
}