PIC18F67K40 – new Pic Clicker II SPI initialization problem

General discussion on mikroC PRO for PIC.
Post Reply
Author
Message
feuerwolf
Posts: 95
Joined: 09 Nov 2012 16:00
Location: Switzerland

PIC18F67K40 – new Pic Clicker II SPI initialization problem

#1 Post by feuerwolf » 21 Jun 2017 15:35

Hi,
i am trying to use the new Pic Clicker II with the PIC18F67K40 with a micro SD Card Click, but initialization of SPI makes trouble. As I See it, SPI1 must be Mapped using “Peripheral Pin Select Library“ the Problem is, that the new PIC18F67K40 pin mapping parameters don’t fit to the microcontrollers Reference manual. So my problem is, that I can’t name Miso, Mosi and SCK in the PPS_Mapping routine because I don^t know where to look it up. PIC Help library description is not up to date for that uController and Code assistant shows anything, but its not clear, which descriptor does suit Dou, Din and SCK.
Could anyone provide me with a simple SPI init code for this PIC18F67K40 ???
Please find attached my Example Code.

Code: Select all

  PPS_Mapping(_RC4,  _INPUT,  _SSP1DAT);         // SPI - MISO  - data in  le
  PPS_Mapping(_RC5,  _OUTPUT, _SDO1_SDA1);   // SPI - MOSI  - data out  ->   sda means input?
  PPS_Mapping(_RC3,  _OUTPUT, _SCK1_SCL1);    // SPI - SCK   

/*
  PPS_Mapping(_RC4,  _INPUT,  _SDO1_SDA1);   // SPI - MISO - data in   -> input mapping not possible
  PPS_Mapping(_RC5,  _OUTPUT, _SSP1DAT);     // SPI - MOSI - data out
  PPS_Mapping(_RC3,  _OUTPUT, _SCK1_SCL1);   // SPI - SCK  - sck
*/

  SPI1_Remappable_Init_Advanced(_SPI_REMAPPABLE_MASTER_OSC_DIV4, _SPI_REMAPPABLE_DATA_SAMPLE_MIDDLE, _SPI_REMAPPABLE_CLK_IDLE_LOW, _SPI_REMAPPABLE_LOW_2_HIGH);
  SPI_Set_Active(&SPI1_Remappable_Read, &SPI1_Remappable_Write);
Attachments
uCtest SPI.zip
(175.16 KiB) Downloaded 114 times

User avatar
darko.ilijevski
Posts: 581
Joined: 21 Mar 2017 16:57

Re: PIC18F67K40 – new Pic Clicker II SPI initialization prob

#2 Post by darko.ilijevski » 22 Jun 2017 12:39

Hello,

I have used mapping like this and it was working for my example - I have used 8x8 LED CLICK to test the SPI.

Code: Select all

void SPI_PPS(){
  PPS_Mapping(_RC3, _OUTPUT, _SCK1_SCL1);
  PPS_Mapping(_RC4, _INPUT, _SSP1DAT);
  PPS_Mapping(_RC5, _OUTPUT, _SDO1_SDA1);
}
I see it's the same as in your code, so I see why your code doesn't work... Maybe something else is interfering with the SPI ? Wrong settings for the advanced init function / not good for the peripheral you are trying to communicate with ? I see also that you have cleared the 'one way lock' bit, that's what I did too, it's required to do so if you use multiple PPS_Mapping functions (since it internally invokes lock/unlock, unlike the PPS_Mapping_NoLock).

Best regards
BR,
Darko

feuerwolf
Posts: 95
Joined: 09 Nov 2012 16:00
Location: Switzerland

Re: PIC18F67K40 – new Pic Clicker II SPI initialization prob

#3 Post by feuerwolf » 26 Jun 2017 13:45

Thanks, it works now.
Mapping was correct, the issue was, that I did not set “_SPI_REMAPPABLE_MASTER_OSC_DIV64” correctly due to the CPU Clock.

User avatar
darko.ilijevski
Posts: 581
Joined: 21 Mar 2017 16:57

Re: PIC18F67K40 – new Pic Clicker II SPI initialization prob

#4 Post by darko.ilijevski » 29 Jun 2017 00:10

Hi,
I am glad you were able to solve it out. You're welcome.
You might also want to try clearing the SLRCONx registers, it might allow you for better clock speeds (lower SPI clock divider value)...

Best regards
BR,
Darko

muratkok
Posts: 2
Joined: 29 Dec 2021 14:48

Re: PIC18F67K40 – new Pic Clicker II SPI initialization problem

#5 Post by muratkok » 29 Dec 2021 15:05

Hello Sir,
I am facing the initialization problem. Here is the part of the init.

Code: Select all

  OSCCON1 = 0b01100000 ;     // Internal oscillator  HFINTOSC select as  sysem clock
  OSCCON2 = 0b01010000 ;     // Internal oscillator  HFINTOSC select
  OSCCON3 = 0x00 ;           // CSWHOLD may proceed; SOSCPWR Low power;
  OSCEN = 0x00 ;             // MFOEN disabled; LFOEN disabled; ADOEN disabled; SOSCEN disabled; EXTOEN disabled; HFOEN disabled;
  OSCFRQ = 0x08 ;            // HFFRQ 64_MHz;
  OSCTUNE = 0x00 ;           // TUN 0;*/
  ANSELA = 0;         // configure all PORTC pins as digital
  ANSELD = 0;         // configure all PORTD pins as digital
  //SLRCONC = 1;
  delay_ms(1000);     // wait a second
  UART1_Init(115200);  

    PPS_Mapping(_RC3,  _OUTPUT, _SCK1_SCL1);    // SPI - SCK
    PPS_Mapping(_RC4,  _INPUT,  _SSP1DAT);         // SPI - MISO  - data in  le
    PPS_Mapping(_RC5,  _OUTPUT, _SDO1_SDA1);   // SPI - MOSI  - data out  ->   sda means input?
  // initialize SPI1 module at lowest speed
  SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV64, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);
  //SPI1_Init();
  //delay_ms(2000);
  SPI_Set_Active(&SPI1_Remappable_Read, &SPI1_Remappable_Write);
I don't understand what the wrong is. Could you please help me?
Attachments
SD_CARD_18f67k40.rar
(257.19 KiB) Downloaded 28 times

muratkok
Posts: 2
Joined: 29 Dec 2021 14:48

PWM PPS MAPPING PROBLEM pic18f67k40

#6 Post by muratkok » 13 Jan 2022 13:06

Hello,


I try to use PPS_Mapping(_RC1, _OUTPUT, _CCP2), but it is not working. The default port of the PWM2 is RE5. However, I can't use the E port for PWM. That's why, I have to choose another available port(PORTC). When we look at the PPS_Mapping(_RC5, _OUTPUT, _SDO1_SDA1); this function, can be worked on the SPI init. I wonder how we can use the PPS_Mapping(_RC1, _OUTPUT, _CCP2) for PWM1. I suppose there should be PPS output table for pic18f67k40 in microc. However, I can't find out the table.Here at the PPS library for 18F2xJ11, 18F4xJ11, 18F2xJ50 and 18F4xJ50.

https://download.mikroe.com/documents/c ... ibrary.htm

Code: Select all

 PPS_Mapping(_RC1, _OUTPUT, _CCP2);    // PWM1  Peripheral Pin => RC1
    PWM2_Init(5000);
    PWM2_Start();
    PWM2_set_duty(255);

    while(1)
    {
     pwm2_set_duty(150);
     delay_ms( 500 );
     pwm2_set_duty(0);
     delay_ms( 500 );
    }
Attachments
PIC18F67K40.rar
(78.16 KiB) Downloaded 26 times

Post Reply

Return to “mikroC PRO for PIC General”