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 - No Clock

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







SPI - No Clock
PostPosted: Mon Dec 27, 2004 12:29 pm     Reply with quote

I am an SPI newbie, got the RS232 & I2C to work on my 16F88, but not SPI. I am using the simple code below, complier Ver 3.212, and looking for the clock on RB4. I get just a low signal. Any ideas?

Code:

#include <16F88.h>
#device ICD=TRUE

#fuses NOWDT, NOPROTECT, NOLVP, INTRC_IO
#use delay(clock=8000000)
#use standard_io(A)
#use standard_io(B)

void main(){

   setup_spi(SPI_MASTER | SPI_L_TO_H | SPI_CLK_DIV_4);
   while (1) {
      spi_write(0x55);
      delay_ms(100);
      }
}



Thanks Barney
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Dec 27, 2004 2:02 pm     Reply with quote

The CCS setup_spi() function doesn't produce correct code for the 16F88
in that version. Try the following test program, which has a substitute
routine to setup the spi port. The routine attempts to copy the same
method used by CCS to setup the SPI.
This substitute routine is just for setting up the SPI Master mode.
I didn't attempt to make it work for setting up Slave mode.
I don't have a 16F88 to test, but the new routine should work.

Code:
#include <16F88.h>
#device ICD=TRUE
#fuses NOWDT, NOPROTECT, NOLVP, INTRC_IO
#use delay(clock=8000000)

#byte SSPCON = 0x14
#byte SSPSTAT = 0x94
#bit SPIEN = SSPCON.5

#define SDI_PIN  PIN_B1
#define SDO_PIN  PIN_B2
#define SCK_PIN  PIN_B4

void my_setup_spi(int16 value)
{
SPIEN = 0;
output_low(SDO_PIN);
output_float(SDI_PIN);
output_low(SCK_PIN);
SSPCON = value;
SSPSTAT = (char)(value >> 8);
}

//=======================

void main()
{

my_setup_spi(SPI_MASTER | SPI_L_TO_H | SPI_CLK_DIV_4);

while(1)
  {
   spi_write(0x55);
   delay_ms(100);
  }

}
Guest
Guest







PostPosted: Mon Dec 27, 2004 11:04 pm     Reply with quote

Thanks, worked like a champ.

Is there a known bug list anywhere?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Dec 27, 2004 11:09 pm     Reply with quote

No, just what you read on this forum. They have a version list
but they don't put everything in it. I'll inform CCS about this bug.
arrow



Joined: 17 May 2005
Posts: 213

View user's profile Send private message

PostPosted: Thu Jun 09, 2005 7:13 am     Reply with quote

Hi PCM programmer

Do you know if
SETUP_SPI(SPI_MASTER | SPI_H_TO_L | SPI_CLK_DIV_4);
has a problem for the 16F873 chip in
PICC version: 2.686?

All the best
arrow
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jun 09, 2005 1:59 pm     Reply with quote

View the output on the SPI pins with an oscilloscope and see if looks OK.
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