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

18F452, FRAM & SSPADD, How do I set SCL = 1Mhz clock

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



Joined: 19 Nov 2003
Posts: 45
Location: Oxford

View user's profile Send private message Visit poster's website

18F452, FRAM & SSPADD, How do I set SCL = 1Mhz clock
PostPosted: Fri Mar 05, 2004 9:23 am     Reply with quote

18F452
40Mhz Clock
PCH
FRAM FM24C256

I have some code which uses code that I found on this forum. The SCL runs whatever I do at 100KHz when I want to run it at a 1MHz, my suspicion is that I am not able to alter the special 12c registers. I know somewhere I have to set SSPCON, SSPADD and SSPSTAT

and what I have been doing is setting it up as follows

Code:

#include <18F452.h>
#device *=16 ADC=8

//------------------------------------------------------------------------
// DEFINES

#define EEPROM_PAGE_LEN 64 // Page length in bytes
#define EEPROM_PAGE_COUNT 512 // Nunber of pages in eeprom

#define EEPROM_I2C_WRITE_ADDR 0xA0
#define EEPROM_I2C_READ_ADDR 0xA1

//---------------------------------------------------------------------------
// COMPILER DIRECTIVES and HARDWARE CONFIGURATION

#fuses HS, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
#use Delay(Clock=40000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

#use i2c(Master, SDA=PIN_C4, SCL=PIN_C3, FORCE_HW) // Hardware i2c
#zero_ram

//--------------------------------------------------------------------------
// GLOBALS

char random_byte;
int value;
char page_write_buffer[EEPROM_PAGE_LEN];
char page_read_buffer[EEPROM_PAGE_LEN];

#byte SSPCON = 0x28 // setting bit 5 and 3 high = SSPEN and SSPM3
#byte SSPADD = 0x0A // with a 40MHz clock this should be right
#byte  SSPSTAT = 0x80 //setting bit 7 high = SMP


this gives me a 100KHZ clock when I want a 1MHz clock. I have changed SSPADD to 0x9 and I get the same I also have changed SSPCON to SSPCON1 and this does nothing either???

Do I need to add

Code:
#define SSPSTAT 0xFC7
#define SSPCON1 0xFC6
#define SSPADD 0xFC8 


here

Code:

#include <18F452.h>
#device *=16 ADC=8

//------------------------------------------------------------------------
// DEFINES

#define EEPROM_PAGE_LEN 64 // Page length in bytes
#define EEPROM_PAGE_COUNT 512 // Nunber of pages in eeprom

#define EEPROM_I2C_WRITE_ADDR 0xA0
#define EEPROM_I2C_READ_ADDR 0xA1

#define SSPSTAT 0xFC7  //
#define SSPCON 0xFC6 // PUT IT HERE!!!!!
#define SSPADD 0xFC8  //
   
//---------------------------------------------------------------------------
// COMPILER DIRECTIVES and HARDWARE CONFIGURATION

#fuses HS, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
#use Delay(Clock=40000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

#use i2c(Master, SDA=PIN_C4, SCL=PIN_C3, FORCE_HW) // Hardware i2c
#zero_ram

//--------------------------------------------------------------------------
// GLOBALS

char random_byte;
int value;
char page_write_buffer[EEPROM_PAGE_LEN];
char page_read_buffer[EEPROM_PAGE_LEN];

#byte SSPCON = 0x28
#byte SSPADD = 0x0A
#byte  SSPSTAT = 0x80


When I try this all i get is build fail error
Expecting an identifier
Expecting a declaration

I am using 2K2 pull up resistors on SDA and SCL

HELP ME WISE PEOPLE

I HAVE CHANGED ALL RANDOM VARIABLES AND AM SITTING HERE LOOKING STUPID!!!!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Mar 05, 2004 11:18 am     Reply with quote

Quote:
Do I need to add
#define SSPSTAT 0xFC7
#define SSPCON1 0xFC6
#define SSPADD 0xFC8


You are porting code that talks directly to registers, from a 16F877
to a 18F452. To do this, you need to change the addresses of
those registers to the appropriate addresses for the 18F452.

In CCS, a register address (or memory location) is declared with
a #byte statement. The original code used #byte statements.
You should do this in your ported code, as well.

So change your code to this:
#byte SSPSTAT = 0xFC7
#byte SSPCON1 = 0xFC6
#byte SSPADD = 0xFC8

You also need to check the data sheet for the 18F452, and see
if there are any differences in the register bits or usage, between
the 16F877 and the 18F452.
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