CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

i2c issues/question - setup_spi(false) prevents hw i2c why??

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
JamesW, Kent, England
Guest







i2c issues/question - setup_spi(false) prevents hw i2c why??
PostPosted: Thu May 14, 2009 11:46 am     Reply with quote

Hi folks,

I've been having i2C issues recently and have been attempting to get hardware I2C running rather than the default software one. (My unit keeps locking up and I need to make it a little more resiliant)

Target device is 18F4685.

However despite numerous attempts and variations in #use i2c I got no-where.

In desperation I looked at the ccs wizard generated code and found the line setup_spi(false).

To me this looks like calling this function will turn off the spi interface - as it's not used it should have no effect.

However commenting out this line means that the hardware i2c works!

Any ideas why?

Thanks

James
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu May 14, 2009 11:55 am     Reply with quote

Quote:
However commenting out this line means that the hardware i2c works!

That's correct. setup_spi(FALSE) clears the SSPCON1 register.
The MSSP module can be configured for hardware i2c or SPI.
CCS should look to see if hardware i2c library is specified, and then
at least issue a warning message about setup_spi(FALSE), but they don't.

Just delete that line. That's how to fix it.
JamesW, Kent, England
Guest







PostPosted: Thu May 14, 2009 2:03 pm     Reply with quote

Fantastic - the help documentation should say this as well - especially as the setup_spi(false) line is added automatically if you are not using spi.

Delving deeper into the documentation, it also says that setting tris_c (or whatever) to inputs is essential so that the hardware/compiler can configure them as needed.

Given that the set_tris_x(y) command was abolished years ago, and to change the tris registers manually now, they need to be memory mapped using #byte tris_a 0x?? it should feature in the help in slightly bigger letters

Thanks

James
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri May 15, 2009 5:51 pm     Reply with quote

Quote:
Given that the set_tris_x(y) command was abolished years ago,

That's not true. It's in the current compiler. You're probably thinking
of the TRIS instruction. But that's not necessary. The TRISC register
is loaded with a "MOVWF TRISC" instruction. The compiler handles this.


Quote:

it also says that setting tris_c (or whatever) to inputs is essential so that the hardware/compiler can configure them as needed.

If you are using standard i/o mode the compiler inserts code to do this.
You don't need to do it. If you're using fast i/o mode, then it doesn't
set the TRIS. But, the PIC has those pins configured as inputs anyway,
when it's powered-up.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group