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

SPI output problem

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







SPI output problem
PostPosted: Wed Apr 12, 2006 10:15 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Apr 12, 2006 12:23 pm     Reply with quote

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.
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