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

Software SPI

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



Joined: 05 Jul 2010
Posts: 129

View user's profile Send private message

Software SPI
PostPosted: Wed Jul 06, 2011 6:46 am     Reply with quote

Hi,

I'm trying to communcate with an 96C56 EEPROM using my own driver (rather than CCS' provided one) and need to use the software implementation of SPI.

I've written a short test program and the software seems to be crashing on the spi_write() instruction. Using a logic anaylser the output_high(SPISS) line gets exectued but nothing there after. I'm able to toggle the pins so I know it's not a hardware issue.

Is there something regarding the software versions I should be aware of/am doing wrong?

CCS PCH C Compiler, Version 4.116

Test program:

Code:

#include <18f4520.h>
#fuses INTRC_IO, NOMCLR, NOWDT, NOLVP, NOPUT
                       
#use delay(internal = 8Mhz, clock=32MHz)
#use rs232(baud=115200, xmit=PIN_C6, rcv=PIN_C7, ERRORS)



#define SPI_SS PIN_B4

#use spi(DI=PIN_B2, DO=PIN_B1, CLK=PIN_B3)

void main() {
delay_ms(1000);
while(TRUE){

   
// select slave - this device has high chip select
   output_high(SPI_SS);
   
   spi_write(10);
   delay_ms(1000);
}
}
SH



Joined: 06 Jul 2011
Posts: 3

View user's profile Send private message

PostPosted: Wed Jul 06, 2011 7:16 am     Reply with quote

There is an example for the 93C56:
C:\Program Files (x86)\PICC\drivers\9356spi

Maybe it will help you.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jul 06, 2011 2:15 pm     Reply with quote

Quote:
#use spi(DI=PIN_B2, DO=PIN_B1, CLK=PIN_B3)

spi_write(10);

The spi_write() function only uses the hardware SPI pins. You must use
the spi_xfer() function with #use spi() for software SPI. spi_xfer() is
intended to be used with #use spi().

The spi_write() and spi_read() functions are for the older setup_spi() method.

Also, depending upon your compiler version, the #use spi() library may
not default to parameters that you expect. It likely defaults to the exact
opposite of what you want. That's what I've found in older compiler
versions. You need to add the following parameters to your #use spi()
declaration:
Code:

MASTER, MSB_FIRST, BITS=8, MODE=0, BAUD=100000

If your SPI mode is different, or if your Baudrate is different, you can
change them to what you need.
Geps



Joined: 05 Jul 2010
Posts: 129

View user's profile Send private message

PostPosted: Thu Jul 07, 2011 9:20 am     Reply with quote

SH, for my application I have to use the software port so the CCS provided driver isn't any use unfortunately.

Thanks PCM - thought it might be something simple!
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