SPI little problem

General discussion on mikroC PRO for dsPIC30/33 and PIC24.
Post Reply
Author
Message
HyperUniverse
Posts: 282
Joined: 17 Jun 2009 10:42

SPI little problem

#1 Post by HyperUniverse » 29 Jan 2021 13:45

Hi,

I can't figure out why I've got this weird behaviour.

dsPIC33 misreads data from SPI after each power up
but it reads the correct data from the same SPI device after a MCLR reset

Anybody got a suggestion?

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: SPI little problem

#2 Post by filip » 01 Feb 2021 08:29

Hi,

Which development board are you using ?
Can you attach the schematics of your connections ?
Can you add a little delay at the start-up ?

Regards,
Filip.

HyperUniverse
Posts: 282
Joined: 17 Jun 2009 10:42

Re: SPI little problem

#3 Post by HyperUniverse » 01 Feb 2021 13:28

Hi,

I thought that mikroe library is taking care of pins when remapping them, but it looks like I was wrong again.

Although this is the right mapping of my pins:

Code: Select all

  PPS_Mapping_NoLock(25, _INPUT, _SDI2) ;       // SPI2 Data Input
  PPS_Mapping_NoLock(20, _OUTPUT, _SDO2) ;      // SPI2 Data Output
  PPS_Mapping_NoLock(48, _INPUT,  _SCK2IN) ;    // SPI2 Clock Input      /* Choose an RP pin
  PPS_Mapping_NoLock(48, _OUTPUT, _SCK2OUT) ;   // SPI2 Clock Output        capable of In/Out for the Clock  */
I had to correctly set the individual pins manually, otherwise it wasn't working, like I've said in the first post.

So the correct settings for the pins in TRIS and PORT and LAT for these particular pins is:

Code: Select all

Out High for SPI_SCK
In High for SPI_SDI
Out High for SPI_SDO
My mistake was previously I left

Code: Select all

Out Low for SPI_SCK
In Low for SPI_SDI
Out High for SPI_SDO
Now it works fine.

Thanks mikroe for not letting us know the importance of manually setting these pins the right way.
Why did you ever invent the remappable library when I could have done it myself as:

Code: Select all

  RPINR22bits.SCK2R = 0b0110000 ; // RP48 ;      // SCK2   SPI2 Clock Input        SCK2IN    RC0   = Out High for SPI_SCK;
  RPINR22bits.SDI2R = 0b0011001 ; // RP25 ;      // SDI2   SPI2 Data Input         SDI2      RA9   = In High for SPI_SDI;
  RPOR5bits.RP48R   = 0b001001  ; // RP48 ;      // RPn tied to SPI2 Clock Output  SCK2OUT   RC0   = Out High for SPI_SCK;
  RPOR0bits.RP20R   = 0b001000  ; // RP20 ;      // RPn tied to SPI2 Data Output   SDO2      RA4   = Out High for SPI_SDO;
  RPOR3bits.RP40R   = 0b001010  ; // RP40 ;      // RPn tied to SPI2 Slave Select  SS2       RB8   = Out Low pt SPI_Disabled;
I mean if you didn't bother setting the pins the right way in your remappable library, then why bother at all?
Or you could have warned us:
pay attention brothers and sisters, I'm only giving you part of the code, you have to figure out the missing part for yourself
And thanks for asking me the wrong questions; like schematic or board development got anything to do with a piece of code not working at power up, but working after MCLR reset.

Funny thing is someone else had a similar problem with remappable pins, 7 years ago:
viewtopic.php?t=61661

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: SPI little problem

#4 Post by filip » 02 Feb 2021 13:49

Hi,

First of all, I apologize for the issue with the PPS library, we will see what is going on there.
And thanks for asking me the wrong questions; like schematic or board development got anything to do with a piece of code not working at power up, but working after MCLR reset.
You didn't specify anything related to your project/MCU/hardware/compiler version so I had to start somewhere - ask some of the question that may shed some light onto this matter.

Next time, please add as much information you can in order to get the best possible support.

Regards,
Filip.

Post Reply

Return to “mikroC PRO for dsPIC30/33 and PIC24 General”