Jump to content
Sign in to follow this  
dersk

Mapping I2c Driver To 16f677

Recommended Posts

Has anyone mapped the i2c_driver.h to the 16F677? I'm having some trouble - I pasted below some of the code from the header. In the 16F677, there's only one SSPCON and there's no BCLIF.

 

I've been going through and deleting references to them - is there an easier way? The references to SSPCON2 and BCLIF are numerous and I'm not sure it'll work when I'm done. Is there a way to assign them dummy values?

 

Thanks for any help.

 

////////////////////////////////////////////////////////////////////////////
// i2c hardwareware implementation template arguments
////////////////////////////////////////////////////////////////////////////
#define i2c_ARGS	3, PORTC, TRISC, 4, PORTC, TRISC, e_SSPCON1, e_SSPCON2, \
				e_SSPSTAT, e_SSPBUF, e_SSPIF_BIT, e_SSPIF_PIR,			\
				e_BCLIF_BIT, e_BCLIF_PIR, 7, e_SSPADD, (i2c_reset_wdt | i2c_SMP |i2c_HW)

// variables cannot be passed as template arguments. The following constants map to
// the PIC registers and PIC's i2c register locations. These constants are
// then used by the templated functions. 
#define PORTC		0x0f82
#define TRISC		0x0f94
#define e_SSPCON1	0xfc6
#define e_SSPCON2	0xfc5
#define e_SSPSTAT	0xfc7
#define e_SSPADD	0xfc8
#define e_SSPBUF	0xfc9
#define e_SSPIF_PIR	0xf9e
#define e_BCLIF_PIR	0xfa1
#define e_SSPIF_BIT	3
#define e_BCLIF_BIT	3

 

The code now looks like:

 

////////////////////////////////////////////////////////////////////////////
// i2c hardwareware implementation template arguments
////////////////////////////////////////////////////////////////////////////
#define i2c_ARGS	6, e_MSSP_PORT, e_MSSP_TRIS, 4, e_MSSP_PORT, e_MSSP_TRIS, e_SSPCON, \
				e_SSPSTAT, e_SSPBUF, e_SSPIF_BIT, e_SSPIF_PIR,						\
				7, e_SSPADD, (i2c_reset_wdt | i2c_SMP |i2c_HW)

// variables cannot be passed as template arguments. The following constants map to
// the PIC registers and PIC's i2c register locations. These constants are
// then used by the templated functions. 
#define e_MSSP_PORT	PORTB
#define e_MSSP_TRIS	TRISB
#define e_SSPCON	0x014
#define e_SSPSTAT	0x094
#define e_SSPADD	0x093
#define e_SSPBUF	0x013
#define e_SSPIF_PIR	0x00c
#define e_SSPIF_BIT	3

Share this post


Link to post
Share on other sites

I've tried to adapt a variety of different I2C protocols, but so far none of them have worked. Is there a way to know whether I am on the right track? Usually the code halts once it hits anything with i2c in it.

Share this post


Link to post
Share on other sites

I'm trying to map the I2C example to a 18F2515, but without much luck. It just says 'preprocessing error' and quits. Somewhat more exhaustive error reporting would be appreciated from the preprocessor.

Share this post


Link to post
Share on other sites
Usually the code halts once it hits anything with i2c in it.

 

Do you have pull-ups on the bus? The software won't run until you do.

 

I got stung with that when I started out with the I2C. I knew they were supposed to be there, I just didn't add them.

 

I would suggest adding a few debug LEDs to see where you code is getting stuck otherwise, and go from there.

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...