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

Problem With SPI again..

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



Joined: 19 Jan 2012
Posts: 6

View user's profile Send private message

Problem With SPI again..
PostPosted: Thu Mar 08, 2012 7:11 am     Reply with quote

Hi everyone, I come back because I have a new problem..
I use ISIS for simulation .. But I need a clock to simulate the SCK from SPI..

Thank's For help

Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

Forget Proteus.
PostPosted: Thu Mar 08, 2012 9:32 am     Reply with quote

Throw proteus away. It's so full of bugs most of the guys here, who can help, will not even try.

Follow the CCS forum guide.

Post a SHORT compilable section of code which shows the problem, with your version No.

Tell us CONCISELY what your code does / does not do, and what you think it should do.

Use real hardware.

Mike
temtronic



Joined: 01 Jul 2010
Posts: 9225
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Mar 08, 2012 1:49 pm     Reply with quote

No...it's the same problem, you're STILL trying to use Proteus!!!
Mike's RIGHT, throw it away......!!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Mar 08, 2012 2:14 pm     Reply with quote

This post has a simple program to generate an SPI clock and data (for
testing, to see with an oscilloscope):
http://www.ccsinfo.com/forum/viewtopic.php?t=44760&start=1
karimpain



Joined: 15 Feb 2012
Posts: 39
Location: italia

View user's profile Send private message AIM Address MSN Messenger ICQ Number

PostPosted: Fri Mar 09, 2012 12:06 pm     Reply with quote

Really i don't understand the real problem or maybe your question. But look at this master and slave codes and using isi proteus. It works and either i think in reality hope it can help you. Don't forget to connect the csk together and sdo of the master to sdi of slave:
Master code:
Code:

#include <16F877a.h>
#fuses HS
#use delay(clock=20000000)

#define SLAVE_SELECT  PIN_C0
#define DI            PIN_C4
#define DO            PIN_C5
#define CLK           PIN_C3

#byte port_c=7
#byte port_d=8

void main() {

   byte value;
   set_tris_c(0x10);
   set_tris_d(0xff);
 
   output_low(CLK);
   setup_spi(SPI_MASTER | SPI_H_TO_L | SPI_CLK_DIV_16);
   
   while(true){
   
      value=port_d;
      spi_write(value);
      delay_ms(10);
      output_high(SLAVE_SELECT);
   }
}

slave code:
Code:

#include <16F877a.h>
#fuses HS
#use delay(clock=20000000)

#define DI            PIN_C4
#define CLK           PIN_C3

#byte port_b=6
#byte port_c=7
#byte port_d=8

void main() {

   byte value;
   set_tris_c(0x14);
   set_tris_d(0x00);

   setup_spi(SPI_SLAVE | SPI_H_TO_L|SPI_CLK_DIV_16);
   while(true){
    spi_read(0);

  if(spi_data_is_in()){
    value=spi_read();
    port_d=value;
    switch (value)
      {
      case 0x01:
      port_d=0x01;
      break;
      case 0x02:
      port_d=0x02;
      break;
      case 0x04:
      port_d=0x04;
      break;
      case 0x08:
      port_d=0x08;
      break;
      case 0x10:
      port_d=0x10;
      break;
      case 0x20:
      port_d=0x20;
      break;
      case 0x40:
      port_d=0x40;
      break;
      default:port_d=0x00;
      break;}
    delay_ms(10);
  }
   }
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Mar 09, 2012 1:22 pm     Reply with quote

Quote:

void main() {

byte value;
set_tris_c(0x10);
set_tris_d(0xff);

output_low(CLK);
setup_spi(SPI_MASTER | SPI_H_TO_L | SPI_CLK_DIV_16);

while(true){

value=port_d;
spi_write(value);
delay_ms(10);
output_high(SLAVE_SELECT);
}

This is not a good example program. It doesn't initialize the SS line
to an inactive level at the beginning. Also, it only sets SS high inside
the loop. It never sets SS low, which it should do before the spi_write().

If it works in Proteus, then it shows how bad Proteus is, because it means
Proteus doesn't check the SS line for the SPI slave.
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