i2c devices

Questions on control of serial busses
brucee
Site Admin
Posts: 33
Joined: Thu Dec 18, 2008 8:45 pm

i2c devices

Post by brucee »

> I'm also very interested in connecting external devices to this via
the
> I2C or other simple, multiple device networks if I can. Where is a
good
> place to start looking for pretrial devices; A/D and D/A I2C
converter,
> keypad and displays?

For simple devices I check what's available at Digikey. I lean
toward i2c as it is a standard. SPI basically means you have a clock
and a data line, and beyond that its up to the manuf how they define
it, and there is not a lot of consistency. Onewire is kind of a
standard though there is some variation in TI vs Dallas flavors.

Displays are always an issue, it depends on if you need 1 or sometime
down the road you need more. As there are always left overs from
last years cell phone, and those can be had very cheaply. Problem is
a year from now you won't be able to get another one. So there are a
number of vendors that supply displays to the embedded community, and
the price you pay is for consistency in the product line. I like the
CrystalFonz units for this, but there are many others.



YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

Re: i2c devices

Post by YahooArchive »

Hi folks,
Recently I updated my ARMite to new firmware version and try to using the I2CIN
and I2COUT to perform some operation on my I2C device. However, the example from
ARMite Help not clearly show. any guys can give me some example which is using
the captioned commands to drive the I2C device (eq Honeywell HMC6352 digital
compass,....etc). thanks!

YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

Re: i2c devices

Post by YahooArchive »

Brian,

I just went thru the firmware conversion. The help file is a little difficult to
understand. Here are some examples from my conversion. They are particular to my
hardware but may help you.

Dim InList(4) as String 'used for I2C operations
Dim OutList(4) as String

Function SetVCXOOffset(Offset as Integer)
OutList(0) = $10
OutList(1) = Offset >> 8
OutList(2) = Offset
I2COUT(I2CPin,I2CClk,$9C,3,OutList)
Return 0
End Function

Function ReadPLLAmp:
I2CIN (I2CPin,I2CClk,$95,-1,OutList,2,InList)
RETURN Inlist(1) + (InList(0) << 8)
End Function

Cheers, Dick

YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

Re: i2c devices

Post by YahooArchive »

Thanks. this is better now!

YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

Re: i2c devices

Post by YahooArchive »

Hi Dick,
Since I am newbie for I2C device so I might have terrible wrong on the coding.
would you mind comment on the following

My Device is simple and Write address is 0X42 and Read address is 0X43
to initiate the device get reading, I need to send a code 'A'--->$41 to the
device. and then read it from the device. My code is like the following
.......
....
OutList(0)= $41
....
..
I2COUT (0,1,$42,1,OutList) 'going to activate and get measurement
..
...
I2CIN (0,1,$43,-1,OutList,2,InList) 'Get the reading 2 Bytes
RETURN InList(0) + InList(1) <<8
...

Any Mistakes above?

YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

Re: i2c devices

Post by YahooArchive »

> ...
> I2CIN (0,1,$43,-1,OutList,2,InList) 'Get the reading 2 Bytes
> RETURN InList(0) + InList(1) <<8
> ...
>
> Any Mistakes above?

the precedence of + is greater than <<

so that return should either be

RETURN InList(0) + (InList(1) <<8)

YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

Re: i2c devices

Post by YahooArchive »

Hi Brian,

I think BasicNode has pointed out one problem with your code. The thing to
remember is that all the operations only use bytes. I think you picked up on
that.

In the Help File (new I think) is a useful write up on I2C under "Hardware
Specs"

It does work - I can vouch for that!. Dick

YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

Re: i2c devices

Post by YahooArchive »

You are correct.
The ARMite board operating good. However, i found the I2C device doesn't
response. In fact, the inter connection is very simple. only problem may be the
device has problem.

One more question, I read some WEB (using C as example) mentioned the I2C device
only need 7 bit instead of 8. if my device address is $42, do I need shift 1 bit
in ARMbasic?

thanks!

YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

Re: i2c devices

Post by YahooArchive »

I think you are referring to the addressing. The address is the 7 MS bits. The
LSB controls whether the master is writing (0) or reading (1) from the slave. I
believe ARM Basic corrects this bit for you. However I'd do it myself just to be
safe.

One point you might check. You must have pull-up resistors on the SDA and SCL
lines. The ARMmite will not drive them properly without a pull-up.

Dick

YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

Re: i2c devices

Post by YahooArchive »

PS - you might be trying to access the device at too high a speed. Add #define
I2Cspeed50 at the top of your code before the include for I2C.bas. Also make
sure you have a good common ground between the ARMite and your device.

Post Reply