BasicMicro - Forums

www.basicmicro.com
It is currently Mon May 21, 2012 8:33 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: SRF08 with BAP
PostPosted: Fri Jan 06, 2012 12:20 am 
Offline
Citizen

Joined: Wed Jun 29, 2011 2:29 am
Posts: 21
I have seen some posts in this forum for communicating with sonar using Basic Atom Pro.

http://www.lynxmotion.net/viewtopic.php ... 3&start=15

I tried it out but nothing is coming. Is this syntax correct? Am I sending the sonar address correctly?

Code:
sda con p0
scl con p1
srf08 con 0xe0

cmdreg con  81
lightreg con 1
rangereg con 0

range var word
light var byte

main
i2cout sda, scl, srf08, [cmdreg]
pause 100
i2cout sda,scl, srf08, [rangereg]
i2cin sda,scl, srf08, [range.highbyte, range.lowbyte]
i2cout sda,scl, srf08, [lightreg]
i2cin sda,scl, srf08, [light]
serout s_out, i9600, [dec light," ",dec range, 13]
goto main


Thank you


Top
 Profile  
 
 Post subject: Re: SRF08 with BAP
PostPosted: Fri Jan 06, 2012 7:44 am 
Offline
Master

Joined: Tue Nov 21, 2006 9:34 am
Posts: 528
It always would help to have additional information, like how you have it hooked up and the like. But I do think the problem is your first I2COut, which does not give an Address to write to and the data to write to it. Here is a copy of an I2C function I played with a long time ago. So don't know if it still works...

Code:
; SRF helper functions      
SRF08a   Con 0xE0   ' 1st Sonar I2C Address
SRFCmdReg   Con 0      ' Sonar Command register
SRFLightReg Con 1      ' Sonar Light sensor register
SRFRangeReg Con 2      ' Sonar 1st Range register

srfLightVal    Var Byte   ' Light sensor
srfAdr var Byte
srfRange    Var Word   ' 16 bit variable for Range

SRFPing[srfAdr]
   ; Warning this has not been tested to see if it works or not...
    I2COut SDA, SCL, SRFPFail, srfAdr,  [SRFCmdReg, 80]   ; do a ping in inches...
    srfRange = 0
   pause 67
      
    ; lets try to wait until the Ping completes
    I2COut SDA, SCL, SRFPFail, srfAdr,  [SRFRangeReg]
    i2cin SDA, SCL, SRFPFail, srfAdr, [srfRange.HighByte, srfRange.LowByte]
      
    ; lets try to wait until the Ping completes
    ;i2cin SDA, SCL, srfAdr, SRFRangeReg, [srfRange.HighByte, srfRange.LowByte]
   return srfRange
SRFPFail
   return 0xffff   

SRFLight[srfAdr] 
    i2cin SDA, SCL, srfAdr, SRFLightReg, [SRFLightVal]
   return srfLightVal

Kurt


Top
 Profile  
 
 Post subject: Re: SRF08 with BAP
PostPosted: Mon Jan 09, 2012 3:22 am 
Offline
Citizen

Joined: Wed Jun 29, 2011 2:29 am
Posts: 21
I tried with your code but it is giving unexpected token type error. The syntax of i2cout function which you are using is different from the present syntax and it is

i2cout sda, scl, controlbyte, [addressbyte1, addressbyte2, {modifiers}databytes]

ControlByte - is a byte sized variable or constant (0-255) that sets the device ID and the device
address of the I2C device.

how to set the device id?


Top
 Profile  
 
 Post subject: Re: SRF08 with BAP
PostPosted: Mon Jan 09, 2012 7:45 am 
Offline
Master

Joined: Tue Nov 21, 2006 9:34 am
Posts: 528
It did not compile as I did not copy in the definition for SCL and SDA...

Code:
sda con p0
scl con p1


This is a function that takes the device ID as a parameter. That was because my robot was going to have a couple of these...

Kurt


Top
 Profile  
 
 Post subject: Re: SRF08 with BAP
PostPosted: Tue Jan 10, 2012 12:45 am 
Offline
Citizen

Joined: Wed Jun 29, 2011 2:29 am
Posts: 21
Thank you. But again it is showing error in i2cin function

i2cin SDA, SCL, srfAdr, SRFLightReg, [SRFLightVal]


Attachments:
untitled.JPG
untitled.JPG [ 130.21 KiB | Viewed 689 times ]
Top
 Profile  
 
 Post subject: Re: SRF08 with BAP
PostPosted: Tue Jan 10, 2012 6:58 am 
Offline
Master

Joined: Tue Nov 21, 2006 9:34 am
Posts: 528
Yes that is extra code from earlier version in the old I2C command format. You could simply remove it, if you are not going to call it.

Again warning, the code I cut and pasted will not do anything if you don't have code in place to call it...

To fix it, it would probably look like:
Code:
i2cout SDA, SCL, srfAdr,  [SRFLightReg]       ; first need to do an output with the address we wish to read from
i2cin SDA, SCL, srfAdr, [SRFLightVal]           ; Then we can read it in

Again I simply edited this in place here, so it may or may not compile, but you should be able to figure it out...


Top
 Profile  
 
 Post subject: Re: SRF08 with BAP
PostPosted: Tue Feb 14, 2012 10:39 pm 
Offline
Citizen

Joined: Wed Jun 29, 2011 2:29 am
Posts: 21
I tried and now no errors are coming. But the o/p is as shown below. Is it giving garbage value? what does this result mean?

please help me
Thanks in advance


Attachments:
untitled3.JPG
untitled3.JPG [ 102.34 KiB | Viewed 256 times ]
Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


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 post attachments in this forum

Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

phpBB SEO