I was visiting the website buy they ran out of stock again. I wanted to ask if u have 3AD accelerometers and if u can send them in international order (to portugal or poland)
Cause i am really trying to find cheap and good accelerometers and your seems to bee the best.
When plugged into spare eeprom socket of the Propeller Platform, the address line is grounded, so you can only have one that way...
But, the 3AD module itself has 1 address pin (pin #7), so you can have two devices on the same I2C bus in principle.
Just have one with pin#7 grounded and another with pin#7 at Vdd.
:blank:Darn ... should have read the datasheet before getting them. Yes, pin# 7 of 3AD connects to pin# 4 on the MMA7445L. I'll probably need to connect 3AD via SPI but it seems pin#7's trace to pin#6 before AVdd is beneath the chip, or am I wrong? The rework is almost impossible then ...
Is there any other way to connect these 5 3AD to a prop? Any advice is very welcome. Thanks.
I have heard of people swapping over SDA and SCL to talk to a second device at the same address on the same bus. From a wiring point of view Prop === 3AD1 =x= 3AD2
Your routines become something like
PUB Initialize'(SCL) | SDA
(take reading from 3AD-1)
PUB Initialize'(SDA) | SCL
(take reading from 3AD-2)
Its probably not good to do this with the EEPROM on same SDA and SCL lines, but since you're talking about separate pins its probably worth a try.
How about 1 prop, 10 pins (5 separate I2C interfaces), either 1 cog in a fast round-robin detection, or if you need, use 5 cogs each talking to their own 3AD at maximum rate.
Or you could share the clock (SCL) line amongst all, use 6 pins instead of 10 (1xSCL and 5xSDA). Much less scary
The prop is wonderfully flexible at this kind of thing (compared to other micros where you have a single fixed I2C interface)
Thanks. Yes, you're right! Sometimes the PIC/Atmel thinking keeps haunting my mind :P
OK, the 1 prop with 10 pins looks delicious. So, looking at the code, while making the changes, I seems to have a problem:
1. The address for MMA7445L is $1D for all 5, right? So if I perform a read:
'*** In Main
x[0] := i2c.GetAccelX8 '<-- which on of the 5 it is getting??
'*** In GG_PSB_i2cDriver
PUB GetAccelX8
return Get1ByteAccelReg($06)
PRI Get1ByteAccelReg(nReg)|m,v
m:=GetAccelReg(nReg)
'need to swap bytes
v:=m>>8
return (v<<24)~>24 'result is signed 8 bit...
PUB GetAccelReg(reg) |ackbit ,x
'Retrieve contents of acclerometer register
START
ackbit:=Write(MMA7455_Address<<1)
ackbit:=Write(reg)
STOP
x:=in(MMA7455_Address)
'Going to swap high and low bytes...
return x
I'm writing:
OBJ
I2C : "GG_PSB_i2cDriver"
CON
SCL_1 = 8
SCL_2 = 10
SCL_3 = 12
SCL_4 = 14
SCL_5 = 16
VAR
long x[5], y[5], z[5]
PUB Main
I2C.Initialise(SCL_1)
I2C.Initialise(SCL_2)
I2C.Initialise(SCL_3)
I2C.Initialise(SCL_4)
I2C.Initialise(SCL_5)
repeat
repeat i from 0 to 4
x[i] := i2c.GetAccelX8
y[i] := i2c.GetAccelX8
z[i] := i2c.GetAccelX8
waitcnt(cnt + clkfreq/100)
'*** In GG_PSB_i2cDriver, change to
PUB Initialize(in_SCL) | in_SDA
in_SDA := SCL + 1
outa[in_SCL] := 1 ' reinitialized. Drive SCL high.
dira[in_SCL] := 1
dira[in_SDA] := 0 ' Set SDA as input
repeat 9
outa[in_SCL] := 0 ' Put out up to 9 clock pulses
outa[in_SCL] := 1
if ina[in_SDA] ' Repeat if SDA not driven high
quit
I've figured it out now. I'll have to use Mike Green's Basic_i2CDriver as a boilerplate & mod from there. I'll post it after the changes & please help me to see if I made any bo-bo. Thanks.
This is an updated driver that supports as many 3AD as your available pins on 1 prop. I've tested using 2 3AD & it worked. Attached is the revised version for anyone interested.
I have a question but sorry, might be a silly one:
In the PSB_i2cDriver, why is the address always has a bitwise shift left?
PUB GetAccelReg(reg) |ackbit ,x
'Retrieve contents of acclerometer register
START
ackbit:=Write(MMA7455_Address<<1) '<--Why need to shift when sending to Write
ackbit:=Write(reg)
STOP
x:=in(MMA7455_Address)
'Going to swap high and low bytes...
return x
You need the shift because in really, there are 2 addresses for the device... A read address and a write address. The last bit decides if it's read or write...
I'm trying to implement a 1-to-8 I2C Switch & was trying to write a simple object. I was able to detect the 3AD on its SD0/SC0 but the readings I got were mostly -1. While reading the code, it looks like (sorry if I'm reading it wrongly) that the PUB Read function in PSB_i2cDriver reads 2 byte instead of 1 like in the Basic_i2c_Driver. May I know why?
Thank you.
In PSB_i2cDriver:
PUB Read(ackbit):data'(SCL, ackbit): data | SDA
'' Read in i2c data, Data byte is output MSB first, SDA data line is
'' valid only while the SCL line is HIGH. SCL and SDA left in LOW state.
data := 0
dira[SDA]~ ' Make SDA an input
repeat 8 ' Receive data from SDA
outa[SCL]~~ ' Sample SDA when SCL is HIGH
data := (data << 1) | ina[SDA]
outa[SCL]~
outa[SDA] := ackbit ' Output ACK/NAK to SDA
dira[SDA]~~
outa[SCL]~~ ' Toggle SCL from LOW to HIGH to LOW
outa[SCL]~
dira[SDA]~
repeat 8 ' Receive data from SDA
outa[SCL]~~ ' Sample SDA when SCL is HIGH
data := (data << 1) | ina[SDA]
outa[SCL]~
outa[SDA] := NAK'ackbit ' Output ACK/NAK to SDA
dira[SDA]~~
outa[SCL]~~ ' Toggle SCL from LOW to HIGH to LOW
outa[SCL]~
outa[SDA]~ ' Leave SDA driven LOW
In Basic_i2c_Driver:
PUB Read(SCL, ackbit): data | SDA
'' Read in i2c data, Data byte is output MSB first, SDA data line is
'' valid only while the SCL line is HIGH. SCL and SDA left in LOW state.
SDA := SCL + 1
data := 0
dira[SDA]~ ' Make SDA an input
repeat 8 ' Receive data from SDA
outa[SCL]~~ ' Sample SDA when SCL is HIGH
data := (data << 1) | ina[SDA]
outa[SCL]~
outa[SDA] := ackbit ' Output ACK/NAK to SDA
dira[SDA]~~
outa[SCL]~~ ' Toggle SCL from LOW to HIGH to LOW
outa[SCL]~
outa[SDA]~ ' Leave SDA driven LOW
Added: Rayman, its ok. I've found a solution to this problem so you don't need to bother to reply me. Thanks!
Comments
I was visiting the website buy they ran out of stock again. I wanted to ask if u have 3AD accelerometers and if u can send them in international order (to portugal or poland)
Cause i am really trying to find cheap and good accelerometers and your seems to bee the best.
Good work btw!
Thanks
Best regards.
Vasco Baptista
http://www.vascotech88.pt.vu
We purchased 5 pcs of the above & have a number of questions:
1. Noticed the address is set at x1D. If need to chain them up on I2C, how could I change the address of each unit?
2. Instead of using default pin (28 & 29), if I use another 2 pins:
a. I need to add the "Initialize" function in the main code, correct?
b. SCL & SDA will change to, eg., SCL = 16, SDA = 17
Thanks!
But, the 3AD module itself has 1 address pin (pin #7), so you can have two devices on the same I2C bus in principle.
Just have one with pin#7 grounded and another with pin#7 at Vdd.
Is there any other way to connect these 5 3AD to a prop? Any advice is very welcome. Thanks.
Your routines become something like
PUB Initialize'(SCL) | SDA
(take reading from 3AD-1)
PUB Initialize'(SDA) | SCL
(take reading from 3AD-2)
Its probably not good to do this with the EEPROM on same SDA and SCL lines, but since you're talking about separate pins its probably worth a try.
I'll look for other options. I do need to read 5 3AD & having 5 props sending data to another master prop would burn my budget thru & thru
How about 1 prop, 10 pins (5 separate I2C interfaces), either 1 cog in a fast round-robin detection, or if you need, use 5 cogs each talking to their own 3AD at maximum rate.
Or you could share the clock (SCL) line amongst all, use 6 pins instead of 10 (1xSCL and 5xSDA). Much less scary
The prop is wonderfully flexible at this kind of thing (compared to other micros where you have a single fixed I2C interface)
OK, the 1 prop with 10 pins looks delicious. So, looking at the code, while making the changes, I seems to have a problem:
1. The address for MMA7445L is $1D for all 5, right? So if I perform a read:
I'm writing:
This is an updated driver that supports as many 3AD as your available pins on 1 prop. I've tested using 2 3AD & it worked. Attached is the revised version for anyone interested.
Thanks Tubular for the idea.
Thank you Tubular! I'm going to connect all 5 tomorrow & test them
Do you think you could do some without the headers mounted? I'll get another 10 either from you or GG.
Thanks
(Mill max, available in various stack heights)
Of course you can only have one 3AD in each stack, unless you modify that address pin
Thanks. Pls let me know once you have them.
@Tubular,
Thanks. Actually, I need them to be as flat as possible.
In the PSB_i2cDriver, why is the address always has a bitwise shift left?
Thanks.
I'm trying to implement a 1-to-8 I2C Switch & was trying to write a simple object. I was able to detect the 3AD on its SD0/SC0 but the readings I got were mostly -1. While reading the code, it looks like (sorry if I'm reading it wrongly) that the PUB Read function in PSB_i2cDriver reads 2 byte instead of 1 like in the Basic_i2c_Driver. May I know why?
Thank you.
In PSB_i2cDriver:
In Basic_i2c_Driver:
Added: Rayman, its ok. I've found a solution to this problem so you don't need to bother to reply me. Thanks!