View previous topic :: View next topic |
Author |
Message |
YUM
Joined: 27 May 2004 Posts: 12 Location: Austria
|
SPI AND I2C AND RS232 all together? |
Posted: Tue Feb 19, 2008 3:09 am |
|
|
Hello,
I would like to have on a PIC16F73:
1.) RS232 AND
2.) either (determined by a pin on start-up): SPI OR I2C
unluckily CCS (3.227) uses difference setup processes for these interfaces (#USE_RS232, #USE_I2C, setup_spi).
my fear is, and i think i had troubles with it once, that #USE_I2C will remain permanently in the program code and i can not completely overrule it with setup_spi (if determined by a pin on start-up).
Am i right?
Any work around?
thank you! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Feb 19, 2008 12:56 pm |
|
|
If you have a #use i2c() statement, and you're using hardware i2c,
the compiler will put in code at the start of main() to setup the MSSP
module for i2c. It will setup the SSPCON and SSPSTAT registers, and
it will also setup the TRIS for pins C3 and C4. You can see this code
if you look at the .LST file.
If you have a setup_spi() statement in main(), it will execute after
the start-up code for the i2c, and it will overwrite the values in SSPCON
and SSPSTAT. It will configure those registers for SPI mode.
It will also set the TRIS for pins C3 and C4. |
|
|
YUM
Joined: 27 May 2004 Posts: 12 Location: Austria
|
... in reply |
Posted: Wed Feb 20, 2008 12:56 am |
|
|
Hello and thanks for this first answer,
but it leads me to other questions:
1.)
why does CCS use different methods (#USE..., setup_....) to setup modules?
wouldn't it be nicer to have all of them as setup..., so i can use them in conditional statements?
(if ("pin is high") --> setup_spi)
(if ("pin is low") --> setup_i2c)
2.)
are the setups (any of the two possibilities) doing anything else, except setting 2 or 3 registers? |
|
|
|