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

Using UART and SPI at the PIC16F917 at the same time

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



Joined: 26 Jun 2006
Posts: 9

View user's profile Send private message

Using UART and SPI at the PIC16F917 at the same time
PostPosted: Thu Nov 30, 2006 9:11 am     Reply with quote

Hello,

I am trying to use the PIC16F917 to control a DAC and to communicate via RS485.
Since UART and SPI uses the same pins I need to deactivate UART when using SPI – otherwise the program crashes.

Does anyone have experiences in using UART and SPI in parallel? UART will be active in general, while SPI is needed only every 10 minutes for one cycle.

Following code is used to setup UART and SPI:

#use rs232(BAUD=9600, XMIT=PIN_C6, RCV=PIN_C7, RESTART_WDT, PARITY=E)
ENABLE_INTERRUPTS(int_rda);

SETUP_SPI(SPI_MASTER | SPI_L_TO_H | SPI_XMIT_L_TO_H | SPI_CLK_DIV_64);


Thanks for your help in advance
Ttelmah
Guest







PostPosted: Thu Nov 30, 2006 10:17 am     Reply with quote

Easiest answer really, is to look at the example files, where you will find several routines using simple 'bit banging' for a SPI master (ADS8320.C, CAN-MCP2510.C & PNI11096.C for example).
You can then use any pins that suit, and avoid missing serial data.

Best Wishes
rt_joerg



Joined: 26 Jun 2006
Posts: 9

View user's profile Send private message

PostPosted: Fri Dec 01, 2006 2:59 am     Reply with quote

Thanks for your help.

I was able to solve the problem by setting bit 7 (SPEN) in register RCSTA to 0 for the moment I need SPI.
The only problem is that no data at UART will be processed during that short time. But I think the application will work fine with that constraint.

What I still don’t know is how to set a register like RCSTA directly. “setup_uart(FALSE);” can be used to set the desired bit but is not the way I prefer setting a register.
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Fri Dec 01, 2006 8:51 am     Reply with quote

#bit SPEN=0x18.7

SPEN=0;

OR

#byte RCSTA=0x18
#bit SPEN=RCSTA.7

SPEN=0;
rt_joerg



Joined: 26 Jun 2006
Posts: 9

View user's profile Send private message

PostPosted: Tue Dec 05, 2006 4:24 am     Reply with quote

Thanks a lot! Very Happy
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