View previous topic :: View next topic |
Author |
Message |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed May 05, 2010 11:26 am |
|
|
Try this simple program. You should see output on the SCK and SDO pins.
If you don't see output, it probably means there is something wrong with
your hardware. (Assuming you are using hardware, and not Proteus).
Code: |
#include <16F874A.h>
#fuses HS,NOWDT,NOPROTECT,BROWNOUT,PUT,NOLVP
#use delay(clock=20000000)
#define SPI_MODE_0 (SPI_L_TO_H | SPI_XMIT_L_TO_H)
#define SPI_MODE_1 (SPI_L_TO_H)
#define SPI_MODE_2 (SPI_H_TO_L)
#define SPI_MODE_3 (SPI_H_TO_L | SPI_XMIT_L_TO_H)
//===============================
main(void)
{
setup_spi(SPI_MASTER | SPI_MODE_0 | SPI_CLK_DIV_16);
while(1)
{
spi_write(0x55);
delay_us(100);
}
} |
|
|
|
davidshang
Joined: 30 Apr 2010 Posts: 7
|
SDO and SDI |
Posted: Wed May 05, 2010 4:52 pm |
|
|
By theory, I can get a serial signal 0x55 from RC5/SDO pin, and clock on RC3/SCK pin.
Do I need to connect SDO (RC5) to SDI (RC4) to form a loop.
I modified and can not get serial signal from SDO.
Code: |
#include "16F874A.H"
#use delay(clock=4000000)
#use spi(DI=PIN_C4, DO=PIN_C5, CLK=PIN_C3, ENABLE=PIN_A2, BITS=16)
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#define SPI_MODE_0 (SPI_L_TO_H | SPI_XMIT_L_TO_H)
#define SPI_MODE_1 (SPI_L_TO_H)
#define SPI_MODE_2 (SPI_H_TO_L)
#define SPI_MODE_3 (SPI_H_TO_L | SPI_XMIT_L_TO_H)
//===============================
void main()
{
setup_spi(SPI_MASTER | SPI_MODE_0 | SPI_CLK_DIV_4);
while(1)
{
spi_write(0xff);
delay_ms(300);
}
}
|
Thanks. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Thu May 06, 2010 2:46 am |
|
|
Quote: | By theory, I can get a serial signal 0x55 from RC5/SDO pin, and clock on RC3/SCK pin. | By theory???
You are testing, right? So do you have a signal or not?
Are you testing with real hardware or in a simulator like Proteus?
Quote: | Do I need to connect SDO (RC5) to SDI (RC4) to form a loop. | Yes.
Quote: | I modified and can not get serial signal from SDO. | First of all you have to know that in the v4 compiler CCS introduced a new SPI software module. The new module has a lot of features but we suspect it to have a few bugs left in.
The new module is configured with the line '#use spi'. The old hardware SPI configuration is still present too, and is configured with setup_spi().
Only use one method. DON'T use both two lines in your program!!
I recommend you remove the '#use spi' line.
Always post your compiler version number. |
|
|
davidshang
Joined: 30 Apr 2010 Posts: 7
|
PIC Simulator |
Posted: Tue May 11, 2010 4:18 pm |
|
|
I am using MPLAB IDE 5.20, CCS C Compiler 4.104, Oshonsoft PIC Simulator IDE 6.33, still not signal from SDO when run under PIC simulator.
What simulator do you run your .hex file?
Thanks. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue May 11, 2010 4:35 pm |
|
|
I use hardware: PicDem2-Plus board and an oscilloscope. |
|
|
davidshang
Joined: 30 Apr 2010 Posts: 7
|
a |
Posted: Wed May 12, 2010 9:07 am |
|
|
To PCM Programmer:
Could you do me a favor, could you compile your code for me (use MPLAB IDE with CCS)
Code: |
#include <16F874A.h>
#fuses HS,NOWDT,NOPROTECT,BROWNOUT,PUT,NOLVP
#use delay(clock=20000000)
#define SPI_MODE_0 (SPI_L_TO_H | SPI_XMIT_L_TO_H)
#define SPI_MODE_1 (SPI_L_TO_H)
#define SPI_MODE_2 (SPI_H_TO_L)
#define SPI_MODE_3 (SPI_H_TO_L | SPI_XMIT_L_TO_H)
//===============================
main(void)
{
setup_spi(SPI_MASTER | SPI_MODE_0 | SPI_CLK_DIV_16);
while(1)
{
spi_write(0x55);
delay_us(100);
}
} |
I want to know is my MPLAB IDE / CCS or Oshonsoft PIC Simulator IDE problem.
Thank you very much.
davidshang@hotmail.com |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed May 12, 2010 11:05 am |
|
|
I don't want to do that. I don't want to email things to other people.
I only want to participate in the forum. |
|
|
davidshang
Joined: 30 Apr 2010 Posts: 7
|
Thanks. |
Posted: Wed May 12, 2010 1:04 pm |
|
|
Thanks. |
|
|
|