Solved: I2C and a new old guy with the AVR

Go To Last Post
21 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi all,

 

I have a perplexing issue which I know is exceedingly simple and someone will point it out before I post a bunch of code examples.

 

Its this simple I have a MCP23017 one from China that I have been fiddling with the past few days. I have a LM75 on the same I2C bus (yes I'm using pullups :-) 

 

I have been able to talk to the LM75 no problem for days. Can't talk to the MCP2307 so I pull out an Arduino and download the I2C portscanner software. It says it find my MCP23017 at 0x20.

All right then I've confirmed its responding to its I2C address. I pop it back onto breadboard with LM75 and mess with it again for 20-30 - no luck.

 

I now dl'ed some I2C software to blink an LED on the MCP23017. It works the MCP23017 is blinking the correct LED. Ok so that address must be right 0x20 is coded in the demo Arduino software. I still can't get it to work on other board so I put the Saleae on it and now see that the demo software that has 0x20 coded and working is actually sending a 0x40...

 

I go into my software change the ox20 to ox40 and finally I'm talking to the MCP23017 and the LM75 no problem. What the heck is going on?

 

Probably foolishly simple but to a new guy this is very mysterious...

 

Thanks ever so much anyone who can shed some light on my ignorance...

 

EDIT: I should add that I realize this is a bit shift but I'm perplexed at to where it's happening... Is this just a difference in the two libraries I'm using? I'm using some simple ones our of Make AVR and then comparing to what is coded in the Arduino libraries. I don't use Arduino... 

 

 

EDIT FINAL: Figured it out. Tried to delete this post. Should have realized Arduino was dealing with the direction bit and if you click on the protocol analyzer options there is a show 7 bit address option. When your over tired simple things can be magic :-)

 

Last Edited: Fri. Nov 16, 2018 - 01:14 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What the heck is going on?

You seem to have figure it out, congratulations. wink It's a common problem with the I2C addressing, some code expects it one way some other another way.

 

And you don't really want to delete this post, it will come useful to someone else.

 

And how old is new OLD guy? If less that 80 then you are still young like many of us here. laugh

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I had a similar problem with the MCP about 2 weeks ago!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think as JS said this is a inherent potential trap for everybody.

Technically the I2C slave address is only 7 bits. the last bit is an indicator if you want to read or write. But hope you checked the I2C bus specification, which is public and downloadable, and figured that out already.

Now some code libraries require you to enter an '8bit' I2C address. That is the 7bits address left shifted by 1 bit(that bit is normally 0, but to confuse things more It also can be 1, but ignore that for now)

On the other hand some libraries require you to enter the 7bits address and they left shift it themselves.

so that is 1 side of the confusion......

On the other side there are the vendors of the I2C bus peripherals. And as you might have guessed.....

There are some vendors that will give you the 7bits address that you have to left shift/or not

And other manufacturers will give you the 8bits address that you then have to right shift/or not......

 

So with I2C addressing always make sure you know what the datasheet is giving you and also what the code is expecting with respect to slave addressing.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Thanks for the responses folks. It makes me feel marginally better. smiles. Still wondering why I didn't move the Saleae over. My wife tells me to quit calling myself the old guy - I just turned 50. Nice to hear so many keep at it. 

 

I read specs always before asking questions. I haven't asked many questions here but it will be safe to say that when I ask questions most times it will be about the specification itself I'm having trouble with or a question directly related to digital circuitry.

 

When I quit programming professionally I started making ceramics - eventually earning an ok living as a ceramic artist. Now at 50 I'm learning microcontrollers and some basic electronics -sticking with the 1's and 0's as one gentleman said here. 

 

I bought: 

 

Make: AVR Programming by Elliot Williams

   - Such a fantastic resource. Really like this guys teaching style a lot. I think if you had one book this would be the one and you should pay for it too as knowledge like this is not easy to come by. 

 

Forrest Mims - Circuit Scrapbook

Make Electronics, and More Electronics by Charles Platt

Encyclopedia of Electronics Vol 1 - 3, Platt

 

Complete Electronics Self-Teaching Guide - Earl Boysen & Harry Kybett

- Working on this one 30-60 a day. Its not for the faint of heart.

 

Any other suggestions for someone new? I looked for other good AVR books but seems most are fairly out of date. 

 

Thanks again and looking forward to being an active and useful part of this incredible resource and group.

 

Edit:

 

I wanted to give a HUGE shout out to Saleae. I wrote those guys a letter telling them I was a hobbyist and I would sure like to own one of their devices just couldn't see spending that much money when I need a scope (Any suggestions for a decent scope - Hantek of Ebay any good?)

 

Anyways they sold me a Saleae 16 for enthusiast price and it is such a sweet, perfect machine. There are companies 20 times the size of Saleae that would never give a discount like that. I think these guys are great and deserve to be supported.  

 

Cheers,

Rod

 

 

Last Edited: Fri. Nov 16, 2018 - 06:28 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I just turned 50.

So still in kindergarten huh? As I said above 80 is the threshold for old..ish. cheeky We have a few around that age.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

js wrote:

above 80 is the threshold for old..ish. cheeky We have a few around that age.

 

Well y'all don't look that old!

 

--Mike

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ross McKenzie ValuSoft Melbourne Australia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for the encouragement re age.  That's a fact its not too late...

 

I wrote software as a kid, retired with a little money, took up ceramics for 20 years, never made much money but had a hell of good time. I always kept programming a bit. I have Grady Booch's first book on object oriented programming - see a little old. 

 

I'm learning the electronics for a art installation that I've been planning for a couple years. I have a couple questions if anyone is reading this thread otherwise I'll start a new one perhaps.

 

My installation will cover a few square metres. While CAN is not intended for my purposes I've purchased a couple controllers and receivers to try out. As this most certainly is not my field of specialty I ask if CAN seems to be an intelligent direction to take for inter AVR and device communication over larger distances than a circuit board, a 30' by 30' area for example. 

 

My perhaps flawed reasoning is, if its meant to deal with the noisy environment of cars, motorhomes, etc, it may very well be perfect for me.

 

Any thoughts, any suggestions?

 

Again thanks for the welcome...

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

CANbus and their controllers can be intimidatingly complex, why not use RS-485, its a fairly simple half duplex serial bus (USART) with many remotes? 

You should be able to find many examples if you google "Arduino RS-485" to examine and learn from, as well as freaks with experience.

 

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Searching on the internet and will search the depths of this site as well for more information on RS-485. Thanks...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ki0bk wrote:

...why not use RS-485, its a fairly simple half duplex serial bus (USART) with many remotes? 

 

I run RS485 in some very electrically challenging environments (note to self: take a photo this weekend), connecting a master and multiple slaves at high (100k+) speeds. It's simple and reliable.

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm learning the electronics for a art installation that I've been planning for a couple years.

Even though my artistic gift is limited to drawing stick figures (a bit better with PCBs...) I have done a few art type systems for real artists, this one uses isolated RS485 for comms over a Km pathway, it has been running for about 10 years. https://vimeo.com/7751252

 

It is now a bit run down due to lack of maintenance on the part of the end client but still mostly working.

 

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That's great! Still running is it? Not managed by a city or commercial entity? It looks like a fairly significant financial investment went into the installation.

 

Such amazing things we can do! 

 

Thanks for sharing that...

Cheers

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Brian Fairchild wrote:
I run RS485 in some very electrically challenging environments

Industrial plants, building automation systems, HVAC, are just a few of the places 485 is used.

 

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Not managed by a city or commercial entity?

Unfortunately YES!! The Gold Coast City council in Queensland Australia, last year I traveled there to see family (about 10 hours drive) and sent a report to the maintenance department but they didn't even bother replying even though they said they were interested in finding out any problems, quite a few problems are mechanical (ie vandal damage) but a couple are electronics.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

js wrote:
but they didn't even bother replying
Queenslanders!

Ross McKenzie ValuSoft Melbourne Australia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Rediron wrote:
I ask if CAN seems to be an intelligent direction to take for inter AVR and device communication over larger distances than a circuit board
Umm there is a clue in the name! CAN = Car Area Network. The idea is that it's for different nodes within a vehicle to be able to communicate. So, yes, I guess it's more than just across a circuit board but it's rarely more than about 3m between wired nodes. It's about connecting the lights to the door sensors and the wheel tick sensors to the ABS system and things like that.

 

I guess it depends what you mean by "larger distances".  For example you probably wouldn't use CAN to connect things at either end of an 80m warehouse.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

With one kind answer, much appreciated - thank you,  I was lead to this great document - Shouldn't need to need to ask much more after this. :)

 

When I first started writing software seriously in the early 90's we were working on the OSI protocol stack. The telco at that time still didn't have equipment dedicated to processing X.25 frames and at that time we had to bit stuff our own frames.  I only mention this as while the CAN system while not as suitable in this project as I thought it could be, it would be interesting, however,  to see if something like it is used in advanced robotic control systems as it has so many fail safe's built in such as CRC, etc.   With mission critical applications over smaller distances it seems CAN could be a great contender - I haven`t fully read the specs.  I`m an artist and a programmer, not an electronics guru by any stretch.  I just snuck in here to learn a few things.  Something else to google if I ever have time.

 

Thanks much for the RS485 heads up. 

 

R.

 

Fixed link-JS

Last Edited: Fri. Nov 30, 2018 - 07:12 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Fixed the link above, unfortunately it seems to get harder to add links, had several goes at it. sad

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

js wrote:

Fixed the link above, unfortunately it seems to get harder to add links, had several goes at it. sad

the link seems to be working here, so you did a great job JS ;)