|
|
View previous topic :: View next topic |
Author |
Message |
RotorcraftJOE
Joined: 29 Apr 2005 Posts: 0
|
Using BOTH available synchronous serial ports |
Posted: Fri Apr 29, 2005 7:17 am |
|
|
Hello,
I'm attempting to use either a PIC18F8722 or PIC18F6722, one of the chips with TWO synchronous hardware serial ports. I'd like one port to allow fast hardware I2C and the other to be configured for SPI. I can't figure out how to set the pins and/or fuses such that the compiler will allow this setup. Any advice on setting these pins correctly? Thank you VERY much in advance!
-Joe |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun May 01, 2005 4:02 pm |
|
|
Quote: |
I'm attempting to use either a PIC18F8722 or PIC18F6722, one of the
chips with TWO synchronous hardware serial ports. I'd like one port to
allow fast hardware I2C and the other to be configured for SPI. I can't
figure out how to set the pins and/or fuses such that the compiler will
allow this setup. Any advice on setting these pins correctly ?
|
I don't have the latest version of PCH, so I can't check if CCS supports
the MSSP2 or not.
I compared the data sheets for the 18F8722 and the 18F452, and for
for MSSP1, the register addresses and the bit locations are identical
between the two PICs. This means that it's likely that the built-in
CCS functions for SPI and i2c will work correctly, at least for channel 1,
on the 18F8722.
If there's no support for channel 2, then I suggest that you use channel 1
as your i2c port, because it's the more complex protocol.
Then write your own SPI routines to work with the channel 2 hardware.
To learn how to write those routines, you could compile a test program
that uses all the SPI functions, and do it for channel 1. Then look at
the ASM code and see how CCS does it. Then write your own code,
which essentially copies the CCS code, but write it in C.
Example:
This example will show how to re-write the spi_write() function so
it works with the MSSP2. First, let's see how CCS does it for the
"channel 1" MSSP.
(I don't have a version of PCH that supports the 18F8722, so I'll do
this example for the 18F452. All the register addresses, etc., are
identical to the MSSP1 on the 18F8722, so this example will work.)
Code: |
#include <18F452.h>
#fuses XT, NOWDT, NOPROTECT,PUT,BROWNOUT,NOLVP
#use delay(clock=4000000)
//=================
void main()
{
spi_write(0x55);
while(1);
} |
Compiling the above program with PCH 3.188 gives the following code
for the spi_write() function:
Code: |
0000 00305 .................... spi_write(0x55);
0012 50C9 00306 MOVF FC9,W // Read SSPBUF
0014 0E55 00307 MOVLW 55
0016 6EC9 00308 MOVWF FC9 // Put data into SSPBUF
0018 A0C7 00309 BTFSS FC7.0 // Test BF bit of SSPSTAT
001A EF0C F000 00310 GOTO 0018 // Loop if BF = 0
|
We can re-write this code in C, as follows:
Code: |
#byte SSPBUF = 0xFC9
#byte SSPSTAT = 0xFC7
#bit BF_BIT = SSPSTAT.0
void my_spi_write(c)
{
char temp;
temp = SSPBUF; // Read SSPBUF
SSPBUF = c; // Write the character
while(!BF_BIT); // Wait until it's sent, before exiting.
} |
Now that you've done this, you can easily modify that code to work
with the MSSP2 on the 18F8722 by changing the register addresses.
We'll also change the name of the function to ssp2_spi_write() because
that's a better name that accurately describes what it's doing.
Look int the 18F8722 data sheet to get the addresses of the MSSP2
registers. They are in Table 5-2. Also look in Table 5-3 for the bit
locations.
Code: |
#byte SSP2BUF = 0xF66
#byte SSP2STAT = 0xF64
#bit SSP2_BF_BIT = SSP2STAT.0
void ssp2_spi_write(c)
{
char temp;
temp = SSP2BUF;
SSP2BUF = c;
while(!SSP2_BF_BIT);
} |
To complete the project, you need to write the other SPI routines for the
MSSP2 such as ssp2_spi_read() and ssp2_setup_spi() by following the
same method as shown above. |
|
|
Guest
|
ok thanks! |
Posted: Tue May 03, 2005 11:13 am |
|
|
ok thanks! I'm going to try your suggestion!
-Joe |
|
|
|
|
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
|