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