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 support@ccsinfo.com

PIC18F8722 SPI Port using Timer2

 
Post new topic   Reply to topic    CCS Forum Index -> Code Library
View previous topic :: View next topic  
Author Message
Coffee



Joined: 10 Feb 2015
Posts: 9

View user's profile Send private message

PIC18F8722 SPI Port using Timer2
PostPosted: Tue Feb 10, 2015 3:31 pm     Reply with quote

I'm posting this little test program because I couldn't find anything that dealt with my situation specifically. I found a couple of erratas that concerned me about using Timer2 for a SPI port clock. I also found a couple of postings that indicated there were some problems using Timer2 for the a SPI port clock on certain PIC controllers. With a little research I determined that those postings didn't really apply to my specific application.
Anyway, while this demo is trivial, it does work. It shows that Timer2 can be used with PIC18F8722 SPI1 using the PICC compiler as documented.
This has a SPI clock rate of 1.6 msecs which is as slow as I could get using a 20 MHz processor clock.

Code:

#include <main.h>

/************************************************************
Quick test program for the PIC18F8722 controller SPI1 port.
SPI1 using hardware MASTER
Mode 0
Using Timer2 for spi_clk
CCS:  PCWH Compiler  Version 5.040
Hardware: CCS PIC18F8722 development board
************************************************************/

// SPI modes borrowed from CCSinfo.com forum posts
#define SPI_MODE_0  (SPI_L_TO_H | SPI_XMIT_L_TO_H)
#define SPI_MODE_1  (SPI_L_TO_H)
#define SPI_MODE_2  (SPI_H_TO_L)
#define SPI_MODE_3  (SPI_H_TO_L | SPI_XMIT_L_TO_H)

void main()
{
   // initialize
   setup_timer_2(T2_DIV_BY_16,0xff,1);
   setup_spi(SPI_MASTER | SPI_MODE_0 | SPI_CLK_T2);
   output_LOW(PIN_A1);  // my SPI_LOAD Pin
   
   // run test
   while(TRUE)
   {
      spi_write(0xA3); // something to write
     
      //SPI_LOAD assert
      output_high(PIN_A1);
      delay_ms(1);
      output_low(PIN_A1);
   }
}


Many thanks to this forum for all the useful postings.
_________________
Thank you,
Bill
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> Code Library 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