|
|
View previous topic :: View next topic |
Author |
Message |
BluePUNK Guest
|
SPI output problem |
Posted: Wed Apr 12, 2006 10:15 am |
|
|
Hi!
I want to write data received from RS232 over SPI. There isnīt coming anything out from the SPI. This is my code:
Code: | #include <18f2331.h>
#include <STDLIB.H>
#use delay (clock = 40000000) //clock = 40MHz
#use rs232(baud=115200, rcv=PIN_B0, parity=N)
#fuses NOPROTECT, NOPUT, NOWDT, HS
//SET VARS
char data1;
void main()
{
setup_spi (SPI_MASTER | SPI_H_TO_L | SPI_CLK_DIV_64 | SPI_XMIT_L_TO_H);
do
{
data1=getc();
spi_write(data1);
output_high(PIN_C3);
output_low(PIN_C3);
}while(1);
} |
Can anybody help me please? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Apr 12, 2006 12:23 pm |
|
|
There are several problems with your program.
1. You have the #use delay() statement set for 40 MHz, but your
oscillator fuse is set for HS. That's not correct. 40 MHz operation
can be done by using and external oscillator with the EC or EC_IO
fuse. Or, it can be done with a 10 MHz crystal and the H4 fuse.
2. You don't have the NOLVP fuse. You should add it.
3. You're using a software UART receiver at a high baud rate.
Is this really necessary ? I would use the hardware UART, which
is on pins C6 and C7, and use a lower baud rate such as 9600.
Also, because of the problems listed in item #1 above, it's very
likely that your soft UART doesn't work at all.
4. I noticed that on your PIC, the hardware UART pins are multiplexed
with the hardware SPI pins. So that's probably why you're using
a soft UART. My opinion: Change to a different PIC. Most normal
PIC's don't mux the UART and SPI pins. Choose a PIC that's easy
to use. |
|
|
|
|
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
|