Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

RE: [AVR-Chat] Re: I2C devantech cmp03 problems.

2005-06-11 by wbounce

Thanks for the reply. 

As far as pinging all sonars I did that my other bot with 5 sonars with
no problem. Then I would read them one after the other with no problem.
I had to do that because the I2C bus was inaccessible during the ping. 

The sonar docs says 
"the SRF08 will not respond to any I2C activity whilst ranging.
Therefore if you try to read from the SRF08 you will get 355 while
ranging because the I2C data line is pulled high if nothing is driving
it. And as soon as the ranging the SRF08 will respond."  

I tried to fire them 1 after another and the 1st one would ping
correctly but then the rest would return invalid address. 
Therefore I could not have done your ping sensor1 and read sensor3. 

I have decided to 1st find out if the compass will work by itself with
nothing else ie no motor, sonars, gps, or wheel encoders. Just read the
compass and display the value. If that works I will add each piece back
in. If that doesn't then the compass is bad.


-----Original Message-----
From: AVR-Chat@yahoogroups.com [mailto:AVR-Chat@yahoogroups.com] On
Behalf Of arhodes19044
Sent: Thursday, June 09, 2005 4:15 PM
To: AVR-Chat@yahoogroups.com
Subject: [AVR-Chat] Re: I2C devantech cmp03 problems.


I have not checked your code yet, but.....

Pinging all 3 sonars at the same time?  It sounds (pun intended) to 
me as if interference will occur between sensors.

If you are not running the sensors at max firing frequency, then it 
probably would be best to: 

ping Sensor-1
read Sensor-3
after 70 ms from #1, Ping Sensor-2
read Sensor-1
after 70ms from #2, Ping Sensor-3
read Sensor-2
after 70ms from #3, repeat from the top....

you can add a compass reading in there somewhere.

-Tony


--- In AVR-Chat@yahoogroups.com, "wbounce" <wbounce@s...> wrote:
> I am trying to diagnose a problem I am having with the devantech 
> compass. I have 3 SRF08 sonars and a cmp03 compass connected to my 
> MavricII board (M128). Using winavr 3.4.1. I am using a set I2C
routines
> from Brian Dean's sample programs. I use the same routines to ping
the
> sonar as I do to read the compass so I am fairly certain they are
not
> the problem. Because I am pinging all 3 sonars at once, I moved my 
> reading of the compass to before I do the ping and after I have
read the
> ranges. I list the compass reading routines bearing16 calls 
> cmps03_get_word. The ErrorState is consistently being set to -30
which
> means a failed start condition. Yet as soon as it returned from 
> bearing16 it calls the sonar ping which calls the same call but it 
> succeeds. I have checked the connects to the compass. But after
ooking
> at the code writing this email up it has to be something other than 
> that. First 1st thought was bad connection which is usually the
problem
> when one of the sonars stop working but at least with a sonar it
has a
> led that flashes when it pings so I can tell it is working. How
can I
> tell the compass is working? And is there anything in this code
that
> would cause the I2c to fail?
> 
> 
> 	tempbearing = bearing16();
> 	if ( tempbearing > -1) 
> 		{
> 		CurrentBearing = tempbearing;
> 		}
> 	else
> 		{
> 		ErrorState = (int8_t)tempbearing;
> 		printf_P(PSTR("CError %i"),ErrorState);
> 		}
> 	
> 	printf_P(PSTR("pg "));	
>     srf08_ping(ALLDEVICES, RANGE_US);      /* initiate a ping, 
distance
> in cm */
> 
> 
> int16_t bearing16(void)
> {
>   uint16_t d;
>   int8_t rc;
> printf_P(PSTR("Be "));
>   rc = cmps03_get_word(0x60, 2, &d);
>   if (rc < 0) {
> 	ErrorState = rc;
>     return (int16_t )rc;
>   }
> 
>   return d;
> }
> 
> int8_t cmps03_get_word(uint8_t device, uint8_t addr, uint16_t *
value)
> {
>   uint8_t v1, v2;
> 
>   /* start condition */
>   if (i2c_start(0x08, 0))
>     return -30;
> 
>   /* address slave device, write */
>   if (i2c_sla_rw(device, 0, TW_MT_SLA_ACK, 0))
>     return -31;
> 
>   /* write register address */
>   if (i2c_data_tx(addr, TW_MT_DATA_ACK, 0))
>     return -32;
> 
>   /* repeated start condition */
>   if (i2c_start(0x10, 0))
>     return -33;
> 
>    /* address slave device, read */
>   if (i2c_sla_rw(device, 1, TW_MR_SLA_ACK, 0))
>     return -34;
> 
>   /* read data byte 1 */
>   if (i2c_data_rx(&v1, I2C_ACK, TW_MR_DATA_ACK, 0))
>     return -35;
> 
>   /* read data byte 2 */
>   if (i2c_data_rx(&v2, I2C_NACK, TW_MR_DATA_NACK, 0))
>     return -36;
> 
>   if (i2c_stop())
>     return -37;
> 
>   *value = (v1 << 8) | v2 ;
> 
>   return 0;
> }
> 
> 
> int8_t srf08_ping(uint8_t device, uint8_t cmd)
> {
>   /* start condition */
>   if (i2c_start(0x08, 0))
>     return -1;
> 
>   /* address slave device, write */
>   if (i2c_sla_rw(device, 0, TW_MT_SLA_ACK, 0))
>     return -2;
> 
>   /* write address */
>   if (i2c_data_tx(0x00, TW_MT_DATA_ACK, 0))
>     return -3;
> 
>   /* write command */
>   if (i2c_data_tx(cmd, TW_MT_DATA_ACK, 0))
>     return -4;
> 
>   if (i2c_stop())
>     return -5;
> 
>   return 0;
> }




 
Yahoo! Groups Links

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.