View previous topic :: View next topic |
Author |
Message |
rt_joerg
Joined: 26 Jun 2006 Posts: 9
|
Using UART and SPI at the PIC16F917 at the same time |
Posted: Thu Nov 30, 2006 9:11 am |
|
|
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
|
|
Posted: Thu Nov 30, 2006 10:17 am |
|
|
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
|
|
Posted: Fri Dec 01, 2006 2:59 am |
|
|
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
|
|
Posted: Fri Dec 01, 2006 8:51 am |
|
|
#bit SPEN=0x18.7
SPEN=0;
OR
#byte RCSTA=0x18
#bit SPEN=RCSTA.7
SPEN=0; |
|
|
rt_joerg
Joined: 26 Jun 2006 Posts: 9
|
|
Posted: Tue Dec 05, 2006 4:24 am |
|
|
Thanks a lot! |
|
|
|