Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

SRF02 ranger interface via USART (Serial)

Status
Not open for further replies.

haseeb123

Newbie level 6
Joined
Jun 7, 2011
Messages
14
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,416
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);


		}




}
 

Hello,

I have the same problem of you !
How have you resolve it ?

Best regards ;)

Max
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top