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 CCS Technical Support

spi problems

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



Joined: 03 Mar 2006
Posts: 2

View user's profile Send private message

spi problems
PostPosted: Fri Mar 03, 2006 6:32 am     Reply with quote

hi forum, iam a ew user of the ccs compiler and after 8 years of assemby code thought i would try some c.
My problem is with the library 25640.c a question for anyone, i am having a few problems but will start simple. Is the driver for use on pics not supporting the spi module? i ask this because in the disassembly code it switches the clock lines high and low. The spi module takes care of this internally and you just poll the bf bit for transfer complete after loading the sspbuf, i have a project with this eeprom connected to a 16f777 and it works fine but not when running under this driver. i know what is in a location of the eeprom and for trial purposes just want to read that location to see how this works but it wont work. i will post some code for my other questions later.

thanks john
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Mar 03, 2006 1:30 pm     Reply with quote

Quote:
Is the driver for use on pics not supporting the spi module?

That's correct. CCS probably did it that way because a lot of students
use PICs that don't have a SSP module, such as the 16F628.

Quote:

I have a project with this eeprom connected to a 16f777 and it works
fine but not when running under this driver.

You need to configure the CCS driver to use the same pins that
your board is using. The 25640.C driver uses pins on Port B,
but according to your post, you're using the hardware SPI pins.
Look at the code below. Notice how I've added four #define
statements above the #include for the driver file. These statements
will override the default pins used by the driver. (Look in the
driver file to see the #ifndef statement which allows the override).

Also, note that I've put the chip select on Pin C0. If your
board has it on a different pin, then edit the #define statement
below to use the correct pin.
Code:

#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

// Tell the 25640.C driver to use the following pins
// instead of the default pins on Port B (which are
// listed in the driver file).
#define EEPROM_SELECT PIN_C0  // Chip select for SPI EEPROM
#define EEPROM_CLK    PIN_C3  // Pin C3 is SCK on PIC
#define EEPROM_DI     PIN_C5  // Pin C5 is SDO on PIC
#define EEPROM_DO     PIN_C4  // Pin C4 is SDI on PIC

#include <25640.c>


//============================
void main()
{
int8 result;

init_ext_eeprom();

write_ext_eeprom(0, 0x55);   
result = read_ext_eeprom(0);

printf("Wrote 0x55, Read %x \n\r", result);

while(1);
}
john



Joined: 03 Mar 2006
Posts: 2

View user's profile Send private message

25640 spi driver
PostPosted: Sat Mar 04, 2006 5:53 am     Reply with quote

Hi pcm programmer, thanks for your reply. I have the code reading and writing to the eeprom now, its fine. although this is ok my next quest is to modify a driver and rename it for the MAX6902 real time clock and be able to use the spi module as i did in my assembly code project. This ic uses the 1 1 spi mode and i wll need to be able to set this in the setup_spi() line. This should in turn reduce the code needed.

Thanks again
john Smile
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sat Mar 04, 2006 7:09 am     Reply with quote

For the different SPI mode settings in respect to the Motorola mode names, have a look at http://www.ccsinfo.com/forum/viewtopic.php?t=22928
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