BasicMicro - Forums

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

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: I2Cin command use with MD25
PostPosted: Mon Aug 02, 2010 2:36 am 
Offline
Citizen

Joined: Sun Aug 01, 2010 11:46 pm
Posts: 6
Hi to all of you.

I've seen that sintax for I2C command for BASIC MICRO STUDIO has changed. I'm using 1.0.0.32 and a BasicAtomPro28. All is good when interfacing devices as SFR08.

But when I try to read on a device like MD25 (the popular double motor driver) I'm not able to obtain valid data.

I think to have tried all the possible combination of instructions but no success till now.

The more logical sequence seems to me the following

i2cout SDA, SCL, MotorR, [bReg]
i2cin SDA, SCL, MotorR, [bVal]

All function to write to MD25 are successful so I can move motors
If I use a different way to communicate (PC to MD25 via I2C adapter) I can read all quitely

here below follow a more complete code. Sonar works fine. MD25 no. I've back wrong data

; MiniABB/MD25 test program
; 10/09/05 by Corrado Grasso
; 10/07/10 by MM


; Costanti generali Comunicazione
; I2C
SDA Con P6 ' Define Data pin
SCL Con P7 ' Define Clk pin

; Motori
; Costanti
;
MotorW Con 0xB0 ' MD25 I2C Address
MotorR Con 0xB1 ' MD25 I2C Address

MtrModReg Con 0x0F ' Motor Mode Register
MtrCmdReg Con 0x10 ' Motor Command Register

MOTORCOUPLE Con 0x02 ' Motors coupled together
ZEROENC Con 0x20

; Variabili
;
abMW25 var byte(14)


;Sonar
; Costanti
;
SRF08aw Con 0xE0 ' Sonar I2C Address
SRF08ar Con 0xE1
SRF08bw Con 0xE2 ' Sonar I2C Address
SRF08br Con 0xE3

CmdReg Con 0x00 ' Sonar Command register
RngRegLSB Con 0x03 ' Sonar 1st Range register

; Variabili
;
RangeA Var byte ' 8 bit variable for Range
RangeB Var byte ' 8 bit variable for Range
bRange Var byte

Main

i2cout SDA, SCL, MotorW, [MtrModReg, MOTORCOUPLE]
i2cout SDA, SCL, MotorW, [MtrCmdReg, ZEROENC]

Loop
gosub bSonar[SRF08aw], RangeA
gosub bSonar[SRF08bw], RangeB
gosub vReadMW25

goto Loop


; Subroutines
;
; Sonar
;

bSnr Var byte
bDist Var byte
bSonar[bSnr]
i2cout SDA, SCL, bSnr,[CmdReg, 81] ; Request for a measure in CM
pause 66
i2cout SDA, SCL, bSnr+1,[RngRegLSB] ; third param is the I2c device address
i2cin SDA, SCL, bSnr+1,[bDist]
return bDist

;
; MD25
;
bReg Var byte
bValue Var byte
bReadMW25[bReg]
i2cout SDA, SCL, MotorR, [bReg] ; <---- I've also tried MotorW instead of MotorR
i2cin SDA, SCL, MotorR, [bValue]
Return bValue

bCount var byte
vReadMW25
for bCount = 0 to 16
gosub bReadMW25[bCount], abMW25(bCount)
next
return

End


May someone help me?


Top
 Profile  
 
 Post subject: Re: I2Cin command use with MD25
PostPosted: Mon Aug 02, 2010 2:05 pm 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 11:00 am
Posts: 903
Location: Temecula, CA
Based on the somewhat limited documentation on the Devantech website I think you must write the register address and then read that register back. So you have to write 4 register addresses and read each back in sequence.

Note that the read/write bit is set for oyu automatically by the i2cin and i2cout commands so you can ignore the read/write bit in the i2c commands.

Code:
encoder1 var long
encoder2 var long

main
;read encoder1
i2cout sda,scl,0xB0,[2]
i2cin sda,scl,0xB0,[encoder1.byte3]
i2cout sda,scl,0xB0,[3]
i2cin sda,scl,0xB0,[encoder1.byte2]
i2cout sda,scl,0xB0,[4]
i2cin sda,scl,0xB0,[encoder1.byte1]
i2cout sda,scl,0xB0,[5]
i2cin sda,scl,0xB0,[encoder1.byte0]

;read encoder2
i2cout sda,scl,0xB0,[6]
i2cin sda,scl,0xB0,[encoder2.byte3]
i2cout sda,scl,0xB0,[7]
i2cin sda,scl,0xB0,[encoder2.byte2]
i2cout sda,scl,0xB0,[8]
i2cin sda,scl,0xB0,[encoder2.byte1]
i2cout sda,scl,0xB0,[9]
i2cin sda,scl,0xB0,[encoder2.byte0]

serout s_out,i9600,[dec encoder1," ",dec encoder2,13]
pause 100
goto main

I could not find anythign in the document on their website saying you could just write the first byte of the encoder registers and then read 4 bytes out to get all 4. This may work but I don't have a MD25 to try it on. Try the above code and let me know what happens.

Also in your code you define you register buffer as 14 bytes but you load 17 bytes into it. This is definitely a problem. You need to increase the size of abMW25 to 17 bytes. You for next goes from 0 to 16 which is 17 total positions.

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
 Post subject: Re: I2Cin command use with MD25
PostPosted: Tue Aug 03, 2010 3:46 am 
Offline
Citizen

Joined: Sun Aug 01, 2010 11:46 pm
Posts: 6
Thank you Nathan for your reply, but no joy.

In effect the data I've back are the same that for other solution. The sequence is 0x0C,0x80,0x80,0x80 for reading reg2,reg3,reg4 and reg5. And something similar for the rest.
(I've also a 0xBA...so no bits stucked also if we are talking about a serial bus...)

Using a PC USB-I2C adapter and its driver it's possible to read the whole range of register (17 bytes) with a unique command. Also reading are meaningful.

I'm starting to suspect something temporal/electrical although I've terminated I2C line with pull-up resistor as suggested. In any way writing on device is succesful


Array boundary: ops! You are right... :oops:


Thanks again.


Top
 Profile  
 
 Post subject: Re: I2Cin command use with MD25
PostPosted: Tue Aug 03, 2010 8:27 am 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 11:00 am
Posts: 903
Location: Temecula, CA
What pullup resistor value are you using? You only need it on the SDA line. The SCL line is always driven by the AtomPro.

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
 Post subject: Re: I2Cin command use with MD25
PostPosted: Tue Aug 03, 2010 10:40 pm 
Offline
Citizen

Joined: Sun Aug 01, 2010 11:46 pm
Posts: 6
I'm using a 10Kohm. Total line lenght is below 50 cm in a stellar configuration. Four device connected together.


Top
 Profile  
 
 Post subject: Re: I2Cin command use with MD25
PostPosted: Wed Aug 04, 2010 9:47 am 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 11:00 am
Posts: 903
Location: Temecula, CA
Change toa 1kohm. 10k is just barely enough for 100kbps. Also I suggest you elliminate the other devices until you can get one working.

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
 Post subject: Re: I2Cin command use with MD25
PostPosted: Fri Aug 06, 2010 12:57 pm 
Offline
Citizen

Joined: Sun Aug 01, 2010 11:46 pm
Posts: 6
Still no success.

:roll:


Top
 Profile  
 
 Post subject: Re: I2Cin command use with MD25
PostPosted: Sun Nov 21, 2010 12:00 am 
Offline
Citizen

Joined: Sun Aug 01, 2010 11:46 pm
Posts: 6
:D

Finally I got it.

The 5v for I2C bus and attached device must be not taken from MM25 card...

I have founded a warn in a forum about noise on 5v line for the former MM22 card. Using an external 5v line now all is good


Top
 Profile  
 
 Post subject: Re: I2Cin command use with MD25
PostPosted: Sun Nov 21, 2010 7:23 pm 
Offline
Master

Joined: Sun Aug 17, 2008 5:26 pm
Posts: 798
Location: CA bay Area
Thanks for the heads up about the final resolution to the problem.

_________________
kenjj
http://blog.basicmicro.com/
http://kjennejohn.wordpress.com/


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 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