CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

SRF02 ranger interface via USART (Serial)

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
haseeb



Joined: 27 Apr 2011
Posts: 19

View user's profile Send private message

SRF02 ranger interface via USART (Serial)
PostPosted: Tue Sep 27, 2011 5:58 am     Reply with quote

Hello

Please can someone help me to get the SRF02 ranger to register correctly by sending the correct distance
in CM. At the moment it is only replying back '0' and its LED flashs according to my program loop.

First I used the ranger via I2C interface and that worked well. Now I changed that to serial interface via
changing tie the SRF02 pin 4 to zero volts.

Im using the PIC18F2620 internal OSC @ 4MHz programming in CCS compiler. Below is my small test
program. Please can someone help me to get the SRF02 ranger to register correctly by sending the correct
distance to my serial port and print that out to hypertermial.

Thanks
Haseeb


Code:

#include <18F2620.h>
#include <stdio.h>

#fuses INTRC_IO,NOWDT,NOPROTECT,NOLVP,NOPUT, NOPBADEN
 
// Set Speed to 4Mhz
#use delay(clock=4000000)

// Sonar
#use rs232(baud=9600, stop=2, parity=N, xmit=PIN_B2, rcv=PIN_C7, STREAM=Sonar)

// PC
#use rs232(baud=9600, xmit=PIN_B4, rcv=PIN_B3 ,STREAM=PC)



int range,

   sonar_address = 0x00, //sonar address (factory default)

   sonar_command = 0x54; //Enable Real Ranging Mode command '0x54' for...
                    //Result in centimeters & automatically Tx range back to...
                    //controller as soon as ranging is complete


void main(void)
{

   delay_ms(100); //startup delay




      while(true)
      {

         fputc(sonar_address, Sonar);  //Sonar address '0'
      
         fputc(sonar_command, Sonar);  //data 0x54
   
         
         while(!kbhit(Sonar)); //wait for char in USART buffer      

         range = fgetc(Sonar);   //dump range in variable   
   
   
         fprintf(PC,"Range is %u cm\n\r",range);   
         delay_ms(250);


      }




}
temtronic



Joined: 01 Jul 2010
Posts: 9199
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Sep 27, 2011 6:52 am     Reply with quote

Two items

1) add 'errors' to the use rs232() options....

2) is the sonar module direct TTL connection or more proper RS-232 ? Does it need MAX232 or equal chips to interface?
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Tue Sep 27, 2011 7:27 am     Reply with quote

Hi,

The SRF02 range finder module has a TTL serial interface, so it connects directly to the PIC serial port.

Are you sure that the module is still set to the default address of 0? The documentation implies that the address is "flashed" by the LED on power-up. A 0 address is one long flash of the LED. I don't know what you mean by "the LED flashes according to my program loop"? The SRF02 documentation does not mention that the LED also operates in a "serial receive" mode. It may, but it could also mean that your module is continually resetting?

Have you tried any other commands? A command that is totally unrelated to sonar ranging may be a good idea. Why not try command 93, and see if you can read the single byte firmware version?

Good Luck,

John
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group