MCP23017 - declaration?

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

Ok can someone either help me understand the declaration:

MCP23017 device;
uint8_t data;

I tried to find "device" and am probably missing something.

I think its called used during initialization

void mcp23017_init(MCP23017 *obj, uint8_t address)
{
	obj->address = MCP23017_BASE_ADDRESS + address;
	
	//	set addressing style
	mcp23017_write_register(obj,MCP23017_IOCON,0x00);
	
	obj->data = 0x0000;
	mcp23017_write_word(obj,MCP23017_IODIRA);	//	make all output
}

I don't understand this method or how its used or works. I don't know what I should be looking for.

any pointers or help would be appreciated.

Nigel

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

Quote:
I tried to find "device" and am probably missing something.
It's just an arbitrary variable name, and could've been named anything.

MCP23017 *obj

obj->address = MCP23017_BASE_ADDRESS + address; 

Lets me know that MCP23017 is a structure, so look in your C book about struct and how it works. You'll have to find in which file MCP23017 is defined for whatever code you're using, to see how it's setup.

If you don't have a C book...go to THIS forum's "sticky" section on main page and click "...Online C books...", then go down to "The Generic C Tutorials" and click the first one.

1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1

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

Thank you

Nigel

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

Hmm a little more understanding but I had to cut and paste the whole of the MCP23017.c in to my code as it kept failing to recognize the .c file! I did place it in the same folder as my main code and included it in the project. it compiles and runs but hangs .. I need to let it have the correct chip address for the mcp23017. getting there!

its not the first time ive had to cut and paste a majority of the .c included files. I guess I need to read up on including files.

thanks again Indiana...

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

Normally there is an associated .h file which you #include into your other files. There is a tutorial on managing large projects (or something similar) by abcminiuser (Dean) as well as plenty of stuff on the interwebs on the concept of .h files with C. Knowing the underlying concepts should make the whole thing clearer.

Realise that #include is basically doing a cut and paste of the file - but convention would not have you #include a C file.

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

Exactly the tutorial I was going to mention. You should not have to cut/paste *.c & *.h files. The tut. will show you how it's done.

You're welcome, nigelf

1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1

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

Thanks guys,

I did in fact add the .h that's why it puzzled me so. I know I have so much to learn and relearn. The Royal Air Force brought me up in computing on Pascal then Coral 64. I did some programming with Delphi (Pascal) but have been out of programming for some years. I really appreciate the pointers.

I like this site due to the helping people help them selves attitude and not just handing the info on a platter.

Regards
Nigel Fenton