View previous topic :: View next topic |
Author |
Message |
JamesW, Kent, England Guest
|
i2c issues/question - setup_spi(false) prevents hw i2c why?? |
Posted: Thu May 14, 2009 11:46 am |
|
|
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
|
|
Posted: Thu May 14, 2009 11:55 am |
|
|
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
|
|
Posted: Thu May 14, 2009 2:03 pm |
|
|
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
|
|
Posted: Fri May 15, 2009 5:51 pm |
|
|
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. |
|
|
|