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

Using BOTH available synchronous serial ports

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
RotorcraftJOE



Joined: 29 Apr 2005
Posts: 0

View user's profile Send private message Send e-mail

Using BOTH available synchronous serial ports
PostPosted: Fri Apr 29, 2005 7:17 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sun May 01, 2005 4:02 pm     Reply with quote

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!
PostPosted: Tue May 03, 2005 11:13 am     Reply with quote

ok thanks! I'm going to try your suggestion!

-Joe
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