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

[SOLVED] Software SPI with PIC18F65K80

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



Joined: 13 Aug 2004
Posts: 58
Location: Turkey

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

[SOLVED] Software SPI with PIC18F65K80
PostPosted: Fri Nov 10, 2017 7:52 am     Reply with quote

I have a problem with software spi.
I am using PIC18K65K80
CCS compiler version 5.062

here is my code
Code:

#include <18F65K80.h>
#device adc=8

#FUSES PLLEN,VREGSLEEP,SOSC_DIG,NOXINST,INTRC_IO,NOFCMEN,NOIESO //1
#FUSES PUT,NOBROWNOUT,WDT1024,NOWDT //2
#FUSES CANE,MSSPMSK7,NOMCLR //3
#FUSES NOSTVREN,BBSIZ2K,NODEBUG //4
#FUSES PROTECT,NOCPB,NOCPD //5
#FUSES NOWRT,NOWRTC,NOWRTB,NOWRTD,  //6
#FUSES NOEBTR,NOEBTRB //7


#use delay(clock=64Mhz)

#use spi(MASTER,FORCE_SW,MODE=0,BAUD=100000,DO=PIN_E0,CLK=PIN_E1, ENABLE=PIN_E2, BITS=16,STREAM=myspi)


#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
#use fast_io(D)           
#use fast_io(E)
#use fast_io(F)
#use fast_io(G)
#define INPUT_    1
#define OUTPUT_ 0
#define portA 0
#define portB 1
#define portC 2
#define portD 3
#define portE 4
#define portF 5
#define portG 6
union {
           unsigned int8 tris[9];
struct IO_RX{
           BOOLEAN iChiprefreshLED;    //A0
           BOOLEAN modulepowerNRF;     //A1
           BOOLEAN buzzer;          //A2
           BOOLEAN modulerefreshLED;  //A3
           BOOLEAN pinA4;               //A4
           BOOLEAN emergencyLED;        //A5
           BOOLEAN cpuLED;              //A6
           BOOLEAN commLED;             //A7
           //---------
           BOOLEAN moduleDR1;          //B0
           BOOLEAN moduleDR2;          //B1
           BOOLEAN startrelayfeedback1;  //B2
           BOOLEAN startrelayfeedback2;  //B3 
           BOOLEAN IRLED;              //B4
           BOOLEAN errorLED;           //B5
           BOOLEAN PICkitCLK;            //B6
           BOOLEAN PICkitDATA;           //B7
           //-----------
           BOOLEAN dipSW0;              //C0
           BOOLEAN iChipplugged;         //C1
           BOOLEAN pinC2;               //C2
           BOOLEAN i2cSCL;              //C3
           BOOLEAN i2cSDA;              //C4
           BOOLEAN eepromWP;            //C5
           BOOLEAN testpin;             //C6
           BOOLEAN modulepowerPA;       //C7
           //----------
           BOOLEAN moduleCSD;          //D0
           BOOLEAN moduleCPS;          //D1
           BOOLEAN moduleCTX;          //D2       
           BOOLEAN modulePWRUP;        //D3   
           BOOLEAN moduleCE;           //D4       
           BOOLEAN moduleCS;           //D5
           BOOLEAN moduleCLK1;         //D6
           BOOLEAN moduleDATA;         //D7
           //----------           
           BOOLEAN DIN;          //E0
           BOOLEAN CLK;          //E1
           BOOLEAN CS;           //E2
           BOOLEAN MCLR;               //E3
           BOOLEAN CANRX2;             //E4
           BOOLEAN CANTX2;             //E5
           BOOLEAN START1;              //E6
           BOOLEAN START2;              //E7
           //----------           
           BOOLEAN pinF0;              //F0
           BOOLEAN pinF1;        //F1
           BOOLEAN pinF2;                 //F2
           BOOLEAN relaysenable;              //F3
           BOOLEAN dipSW2;              //F4
           BOOLEAN dipSW3;            //F5
           BOOLEAN Rx2Txteachbutton;             //F6
           BOOLEAN Tx2Rxteachbutton;             //F7
           //--------           
           BOOLEAN rs232RX;                //G0     
           BOOLEAN dipSW4;              //G1     
           BOOLEAN dipSW5;                //G2   
           BOOLEAN rs232TX;              //G3                       
           BOOLEAN dipSW6;      //G4   
           BOOLEAN pinG5;               //G5
           BOOLEAN pinG6;              //G6
           BOOLEAN pinG7;              //G7
}bit;
} trisval;


void set_tris_(void)
{
   set_tris_a(trisval.tris[portA]);
   set_tris_b(trisval.tris[portB]);
   set_tris_c(trisval.tris[portC]);
   set_tris_d(trisval.tris[portD]);
   set_tris_e(trisval.tris[portE]);
   set_tris_f(trisval.tris[portF]);
   set_tris_g(trisval.tris[portG]);
}

   
void set_trisvalue(void)
{
        trisval.bit.iChiprefreshLED=OUTPUT_;    //A0       
        trisval.bit.modulepowerNRF=OUTPUT_;     //A1     
        trisval.bit.buzzer=OUTPUT_;             //A2     
        trisval.bit.modulerefreshLED=OUTPUT_;   //A3
        trisval.bit.pinA4=OUTPUT_;              //A4   
        trisval.bit.emergencyLED=OUTPUT_;       //A5     
        trisval.bit.cpuLED=OUTPUT_;             //A6     
        trisval.bit.commLED=OUTPUT_;            //A7     

        trisval.bit.moduleDR1=INPUT_;            //B0   
        trisval.bit.moduleDR2=OUTPUT_;           //B1   
        trisval.bit.startrelayfeedback1=INPUT_;  //B2
        trisval.bit.startrelayfeedback2=INPUT_;  //B3   
        trisval.bit.IRLED=OUTPUT_;               //B4   
        trisval.bit.errorLED=OUTPUT_;            //B5
        trisval.bit.PICkitCLK=INPUT_;            //B6   
        trisval.bit.PICkitDATA=INPUT_;           //B7   

        trisval.bit.dipsw0=INPUT_;              //C0
        trisval.bit.iChipplugged=INPUT_;        //C1     
        trisval.bit.pinC2=OUTPUT_;              //C2     
        trisval.bit.i2cSCL=INPUT_;              //C3     
        trisval.bit.i2cSDA=INPUT_;              //C4     
        trisval.bit.eepromWP=OUTPUT_;           //C5     
        trisval.bit.testpin=OUTPUT_;            //C6
        trisval.bit.modulepowerPA=OUTPUT_;      //C7
       
        trisval.bit.moduleCSD=OUTPUT_;          //D0
        trisval.bit.moduleCPS=OUTPUT_;          //D1     
        trisval.bit.moduleCTX=OUTPUT_;          //D2     
        trisval.bit.modulePWRUP=OUTPUT_;        //D3     
        trisval.bit.moduleCE=OUTPUT_;           //D4     
        trisval.bit.moduleCS=OUTPUT_;           //D5     
        trisval.bit.moduleCLK1=OUTPUT_;         //D6     
        trisval.bit.moduleDATA=INPUT_;          //D7     
       
        trisval.bit.DIN=OUTPUT_;          //E0     
        trisval.bit.CLK=OUTPUT_;          //E1     
        trisval.bit.CS=OUTPUT_;           //E2     
        trisval.bit.MCLR=OUTPUT_;               //E3
        trisval.bit.CANRX2=INPUT_;              //E4     
        trisval.bit.CANTX2=OUTPUT_;             //E5     
        trisval.bit.start1=OUTPUT_;             //E6     
        trisval.bit.start2=OUTPUT_;             //E7     
           
        trisval.bit.pinF0=OUTPUT_;              //F0     
        trisval.bit.pinF1=OUTPUT_;              //F1     
        trisval.bit.pinF2=OUTPUT_;              //F2     
        trisval.bit.relaysenable=OUTPUT_;       //F3     
        trisval.bit.dipSW2=INPUT_;              //F4
        trisval.bit.dipSW3=INPUT_;              //F5     
        trisval.bit.Rx2Txteachbutton=INPUT_;    //F6     
        trisval.bit.Tx2Rxteachbutton=INPUT_;    //F7

        trisval.bit.rs232Rx=INPUT_;            //G0     
        trisval.bit.dipSW4=INPUT_;             //G1     
        trisval.bit.dipSW5=INPUT_;             //G2     
        trisval.bit.rs232Tx=OUTPUT_;           //G3                     
        trisval.bit.dipSW6=INPUT_;             //G4     
        trisval.bit.pinG5=OUTPUT_;       //G5     
        trisval.bit.pinG6=OUTPUT_;       //G6     
        trisval.bit.pinG7=OUTPUT_;       //G7
  }





void main(void)
{
  set_trisvalue();
  set_tris_();
setup_adc_ports(NO_ANALOGS|VSS_VDD);
    setup_adc(ADC_OFF);
    setup_psp(PSP_DISABLED);     
    setup_timer_0(RTCC_INTERNAL|RTCC_DIV_4);// TIMER0 8.1ms rsesolution
    setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
    setup_timer_2(T2_DISABLED,0,1);
    setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
    setup_comparator(NC_NC_NC_NC);                                           
    setup_vref(FALSE);
    setup_low_volt_detect(FALSE);             
    setup_oscillator(OSC_16MHZ|OSC_PLL_ON);

    EXT_INT_EDGE(0,L_TO_H);
    enable_interrupts(INT_EXT);
    enable_interrupts(INT_TIMER0);
    disable_interrupts(INT_TIMER1);
    disable_interrupts(GLOBAL);


loop:
       
        spi_xfer(myspi,0xAAAA,16);
delay_ms(200);
goto loop;
}

I see nothing on PIN_E0, PIN_E1,PIN_E2 on my scope, any suggestion ?
_________________
Dr Suleyman CANAN
R&D Electronic Engineer
https://suleymancanan.wordpress.com

Do whatever you do with amateur spirit -
But always feel professional.


Last edited by scanan on Tue Nov 14, 2017 6:08 am; edited 7 times in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Nov 10, 2017 8:17 am     Reply with quote

Quote:
void main(void)
{
set_trisvalue();
set_tris_();

Post the code for the lines shown in bold.
scanan



Joined: 13 Aug 2004
Posts: 58
Location: Turkey

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

PostPosted: Mon Nov 13, 2017 3:06 am     Reply with quote

PCM programmer wrote:
Quote:
void main(void)
{
set_trisvalue();
set_tris_();

Post the code for the lines shown in bold.


the functions are added..
_________________
Dr Suleyman CANAN
R&D Electronic Engineer
https://suleymancanan.wordpress.com

Do whatever you do with amateur spirit -
But always feel professional.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Nov 13, 2017 4:10 pm     Reply with quote

You might not see it on your scope because you're using a slow repetition
rate in your while() loop. Try this program which has a much faster loop
speed:
Code:

#include <18F65K80.h>
#device adc=8

#FUSES PLLEN,VREGSLEEP,SOSC_DIG,NOXINST,INTRC_IO,NOFCMEN,NOIESO //1
#FUSES PUT,NOBROWNOUT,WDT1024,NOWDT //2
#FUSES CANE,MSSPMSK7,NOMCLR //3
#FUSES NOSTVREN,BBSIZ2K,NODEBUG //4
#FUSES PROTECT,NOCPB,NOCPD //5
#FUSES NOWRT,NOWRTC,NOWRTB,NOWRTD,  //6
#FUSES NOEBTR,NOEBTRB //7

#use delay(clock=64Mhz)

#use spi(MASTER,FORCE_SW,MODE=0,BAUD=100000,DO=PIN_E0,CLK=PIN_E1, ENABLE=PIN_E2, BITS=16,STREAM=myspi)


void main(void)
{

while(TRUE)
  {
   spi_xfer(myspi, 0x5555, 16);
   delay_us(200);
  }


}
scanan



Joined: 13 Aug 2004
Posts: 58
Location: Turkey

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

PostPosted: Tue Nov 14, 2017 1:41 am     Reply with quote

PCM programmer wrote:
You might not see it on your scope because you're using a slow repetition
rate in your while() loop. Try this program which has a much faster loop
speed:


You're right my loop was too slow,
Many Thanks, problem solved.
_________________
Dr Suleyman CANAN
R&D Electronic Engineer
https://suleymancanan.wordpress.com

Do whatever you do with amateur spirit -
But always feel professional.
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