PDA

View Full Version : [18F4431] Trying to Set UP SPI Communication, SSPCON Register



Stephen
- 22nd January 2008, 00:21
Hi everyone,

I am trying to use PicBasic Pro to set up SPI communication on an 18F4431 and am having the following problem: whenever I try to set the SSPCON register (one of the control registers used by the SSP module), the compiler seems to have problems recognizing the name.

Has anyone been able to successfully set up SPI communication using PicBasic Pro?

Anyway, this is the code:
SSPCON = %0011000 ;this is line 31.
;WCOL clear word collision indicator
;SSPOV overflow indicator
;SSP enabled
;idle state for clock is high
;SPI master mode, clock is Fosc/4.

This is the error I get:

Executing: "C:\PBP\PBPW.EXE" -ampasmwin -oq -z -p18F4431 "mstr.bas"
PicBasic Pro Compiler 2.46, (c) 1998, 2005 microEngineering Labs, Inc.
All Rights Reserved.

C:\SPI TEST PLATFORM\MASTER\MSTR.BAS ERROR Line 31: Syntax error.Skipping link step. Not all sources built successfully.
BUILD FAILED: Mon Jan 21 18:18:31 2008

Regards,
Steve

Darrel Taylor
- 22nd January 2008, 00:53
Hi Steve,

The SSPCON declaration is missing from the PIC18EXT.bas file in the PBP folder.

You can add this line to either your main program, or the PIC18EXT.bas file.

SSPCON VAR BYTE EXT
<br>

Stephen
- 22nd January 2008, 01:55
Hi Steve,

The SSPCON declaration is missing from the PIC18EXT.bas file in the PBP folder.

You can add this line to either your main program, or the PIC18EXT.bas file.

SSPCON VAR BYTE EXT
<br>

Yep, that definitely solved it. Thanks a bunch!

Out of curiosity, what is this PIC18EXT file? I thought all the stuff that needed to be defined was in the include file?

Darrel Taylor
- 22nd January 2008, 03:48
The PIC??EXT.bas files are a "Bridge" between PBP and and all the registers defined by the assembler.

Each PIC has it's own set of registers depending on what features the chip has.
Even between chips with similar features, the registers may be at different addresses.

In the case of the 4431, each registers address is defined in the P18F4431.INC file in the MPASM folder. And since PBP does it's compiling before MPASM gets hold of it, PBP has no idea what those addresses are.

So it uses the PIC??EXT.bas file to define all the possible register names that might be found when using any PIC. That way they become "reserved words" that can't be accidentally used again. And more importantly, makes that name available for easy use in your program. Then at assembly time, only the names that are actually present in that chip become valid, and will have the appropriate address used for the registers.<hr>
The 18F4431 is a bit of an odd ball.
Most of the 18F's have an MSSP module which uses SSPCON1 and SSPCON2.

But the 4431 has the old style SSP module. It does pretty much the same thing, but there are 2 modes that it can't operate in, that the MSSP can. And the SSP module only has the 1 SSPCON register. Hence the problem with the missing register name.

As far as I can tell, only the 2331/2431/4331/4431 series has the old SSP.

hth,