View previous topic :: View next topic |
Author |
Message |
vinims
Joined: 31 Jan 2005 Posts: 3
|
Problem with SPI - PIC16F687 |
Posted: Wed Aug 16, 2006 6:41 am |
|
|
When I try to write a byte on SPI, the program crashes.
Here is my code:
Code: |
#include "16F687.h"
#fuses XT, NOWDT, PUT, NOMCLR, NOBROWNOUT, NOCPD, NOPROTECT, NOFCMEN, NOIESO
#use delay(clock=3686400)
#byte PORTA = 0x05
#byte PORTB = 0x06
#byte PORTC = 0x07
#byte TRISA = 0x85
#byte TRISB = 0x86
#byte TRISC = 0x87
#bit TEST = PORTC.0
void main()
{
TRISA = 0x08;
TRISB = 0x30;
TRISC = 0x00;
setup_comparator(NC_NC_NC_NC);
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_spi(SPI_MASTER|SPI_L_TO_H|SPI_CLK_DIV_4);
PORTA = 0x00;
PORTB = 0x00;
PORTC = 0x00;
while(true)
{
TEST = 1;
spi_write(0x55);
delay_us(50);
TEST = 0;
}
}
|
|
|
![](templates/subSilver/images/spacer.gif) |
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Wed Aug 16, 2006 7:39 am |
|
|
What is your compiler version?
How do you know your program crashes? You have no delay between setting TEST 0 to 1, so the output will be low for only a few clock cycles. |
|
![](templates/subSilver/images/spacer.gif) |
vinims
Joined: 31 Jan 2005 Posts: 3
|
|
Posted: Wed Aug 16, 2006 8:22 am |
|
|
ckielstra wrote: | What is your compiler version? |
3.249
ckielstra wrote: |
How do you know your program crashes? You have no delay between setting TEST 0 to 1, so the output will be low for only a few clock cycles.
|
After spi_write(0x55) code line I was trying to send a byte through rs232 and I did not get any answer from PIC.
But if I comment spi_write(0x55) code line, it works perfectly. |
|
![](templates/subSilver/images/spacer.gif) |
|