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 setup

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



Joined: 18 Aug 2014
Posts: 55
Location: Sheffield, South Yorkshire

View user's profile Send private message Send e-mail

SPI setup
PostPosted: Sat Jun 09, 2018 3:50 am     Reply with quote


    //**********************************************************/
    // HARDWARE AND COMIPLER
    // MIKROE ELEKTRONIKA CLICKER 2 BOARD
    // DEVICE 18F67K40
    // MIKROE RTC 5 CLICK BOARD IN SOCKET 1 ON CLICKER 2 BOARD
    // KS0108 128*64 GLCD
    // microSD click PID: MIKROE-924 IN SOCKET 2 ON CLICKER 2
    // MPLABX V4.15
    // MPLAB V8 DOES NOT SUPPORT ABOVE DEVICE
    // COMPILER CCS C V5.078
    //**********************************************************/


Mods made to device header file

Code:

#byte   PMD_0  =  getenv("SFR:PMD0")
//for all the pmd's
etc
#byte   SLR_CONA  =  getenv("SFR:SLRCONA")
//for all the slr's
etc
#byte   LAT_A  =  getenv("SFR:LATA")
//for all the lat regs
etc
//and the lat pins
#define LAT_A0   31682
//for all the lat pins
etc



Code:

#include "18F67K40.h"

#device PASS_STRINGS = IN_RAM
#use delay(clock=64000000)

#pin_select U1RX=PIN_C6
#pin_select U1TX=PIN_C7

#use rs232(baud=9600, UART1, errors)


#Fuses  HS,RSTOSC_EXT_PLL // 16 MHz xtal,PLL enabled for ext xtal
#Fuses  NOCLKOUT,NOCKS
#Fuses  NOFCMEN,MCLR,NOPUT,NOLPBOR,NOBROWNOUT
#Fuses  NOZCDDIS,PPS1WAY
#Fuses  DEBUG
#Fuses  NOWRT,NOWRTC,NOWRTB,NOWRTD
#Fuses  NOSCANE,NOLVP,NOPROTECT,NOCPD
#Fuses  NOEBTR,NOEBTRB,NOLVP




#define FAST_GLCD    // Try commenting this out to see the differences
const char *SD_IN_STR = "SD CARD IN";
const char *SD_OUT_STR =  "NO SD CARD";

//PPS selection for MSSP1

#pin_select SDI1=PIN_C4  //DATA COMING IN FROM SLAVE TO PIC MASTER
#pin_select SDO1=PIN_C5 //DATA FROM MASTER TO SLAVE I.E OUTGOING FROM PIC
#pin_select SCK1OUT=PIN_C3 //DATA CLOCK


#use spi(SPI1,FORCE_HW,MASTER,BITS=8, MODE=0,baud=100000)  // initial spi setup


#define debug_led LAT_D7


#define SD_INSERT PIN_A1

#include "HDM64GS12.c"
#include "graphics.c"
#include "RTC5v2.c"
#include "math.h"
#include "stdlib.h"

#include "mmcsd.c"

//FAT library.
#include "fat.c"




Hardware debugger: ICD3

Got the PIC setup and the led flashing on/off every 0.5 sec so I knew that I had the Osc setup properly with the PLL.

The I used the setup_spi() functions to get the RTC 5 click board working and display the time/date on a 128*64 GLCD.
I have now switched to the #use spi (created another RTC 5 Source file and changed all the spi_read and spi_write calls to spi_xfer) .

Simple question but just a bit unsure, have done a lot of digging around on here, am I correct that in the #use(MASTER,SPI1....
The SP1 automatically uses the hardware SPI and that I don't need to include the FORCE_HW in the #use setup.

The Program compiled and worked after changing to #use spi

This is so that I can now work with the fat.c and mmscd.c.
Sorry if a bit long winded for a simple question.
Regards Dave
temtronic



Joined: 01 Jul 2010
Posts: 9229
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Jun 09, 2018 4:50 am     Reply with quote

I can't say yes or no however when in doubt YOU should set options and fuses are YOU need them to be. Do NOT rely on the compiler as the 'defaults' were created by another human. It costs you nothing to type in the options you want AND it'll remind you that , in this case, SPI should be on the HW pins and the code very small.
Having started this gig when ASR-33s and papertape where new, I learned NOT to rely on other's ideas of 'defaults'.

Also, dump the listing, see the code, it'll quickly be obvious how SPI is being done.
Jay
diode_blade



Joined: 18 Aug 2014
Posts: 55
Location: Sheffield, South Yorkshire

View user's profile Send private message Send e-mail

PostPosted: Sat Jun 09, 2018 6:05 am     Reply with quote

temtronic wrote:
I can't say yes or no however when in doubt YOU should set options and fuses are YOU need them to be. Do NOT rely on the compiler as the 'defaults' were created by another human. It costs you nothing to type in the options you want AND it'll remind you that , in this case, SPI should be on the HW pins and the code very small.
Having started this gig when ASR-33s and papertape where new, I learned NOT to rely on other's ideas of 'defaults'.

Also, dump the listing, see the code, it'll quickly be obvious how SPI is being done.
Jay


Damn of course , Thanks Jay
my brain cell must have had a senior moment..
Regards
Dave
Smile
temtronic



Joined: 01 Jul 2010
Posts: 9229
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Jun 09, 2018 6:16 am     Reply with quote

yeah, I have LOTS of 'senior's moments' these dayze......

way too many PICs to play with today.....
diode_blade



Joined: 18 Aug 2014
Posts: 55
Location: Sheffield, South Yorkshire

View user's profile Send private message Send e-mail

PostPosted: Mon Jun 11, 2018 11:56 pm     Reply with quote

Thanks Jay did as suggested and everything is correct.
Thread closed
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