View previous topic :: View next topic |
Author |
Message |
kagalou
Joined: 19 Jan 2012 Posts: 6
|
Problem With SPI again.. |
Posted: Thu Mar 08, 2012 7:11 am |
|
|
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
|
Forget Proteus. |
Posted: Thu Mar 08, 2012 9:32 am |
|
|
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: 9243 Location: Greensville,Ontario
|
|
Posted: Thu Mar 08, 2012 1:49 pm |
|
|
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
|
|
|
karimpain
Joined: 15 Feb 2012 Posts: 39 Location: italia
|
|
Posted: Fri Mar 09, 2012 12:06 pm |
|
|
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
|
|
Posted: Fri Mar 09, 2012 1:22 pm |
|
|
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. |
|
|
|