• AVR Freaks

Hot!SPI Pin Remapping PROBLEM

Author
_kristian_
New Member
  • Total Posts : 3
  • Reward points : 0
  • Joined: 2018/02/10 06:54:46
  • Location: 0
  • Status: offline
2019/06/21 05:10:01 (permalink)
0

SPI Pin Remapping PROBLEM

Hi,
I'm using PIC 16LF1705 e I notice a strange behaviour regarding the PPS module routing SPI functions to any pin of the microcontroller.
In a first board I have the following connections:
SDO -> RC1
SDI -> RC2
SCK -> RC0
SS -> RA2
Here, both a transmission and receive operation succeed. In a second board I have swapped SCK with SS so now we have:
SDO -> RC1
SDI -> RC2
SCK -> RA2
SS -> RC0

Transmission operation works but receive operation failed, cause I always get 0. Using the oscilloscope I can see the data at the SDI pin so it's not hardware problem. I have tried to route SS pin, that is a normal digital output, independent from the SPI, to any other pin such as RA5 and RA0 with no success. It seems SCK functions must be on RC0 or on the same port as SDO and SDI, but I can't find anything like this on the datasheet. According to that, there are no specific requests about SPI and PPS, so each pin can be connected with input/output SPI functions. Hence, why I can't read data from my slave device if SCK is not on RC0?
Another note is that even when I can't read data from the slave, SCK signal is present and all write operations always work fine.
Of course, I'm using SPI in master mode and of course RC2 is always set as input, with analog function disabled! I'll post my very simple routine used to read data from the device:
char MySPI_READ(char address)
{
char data_read;

SS_MASTER = 0;

SSP1BUF = address + (1<<6); //reading operation
while(!BF_bit);
SSP1BUF = 0;
while(!BF_bit);
data_read = SSP1BUF ;

SS_MASTER = 1;

return data_read;

}

#1

4 Replies Related Threads

    coffee critic
    Super Member
    • Total Posts : 366
    • Reward points : 0
    • Status: offline
    Re: SPI Pin Remapping PROBLEM 2019/06/21 09:30:37 (permalink)
    0
    Show us your PPS routine.

    n_*$
    #2
    P Lameijn
    Super Member
    • Total Posts : 1963
    • Reward points : 0
    • Joined: 2004/01/22 18:30:23
    • Location: The Netherlands
    • Status: offline
    Re: SPI Pin Remapping PROBLEM 2019/06/21 12:06:29 (permalink)
    +1 (1)
    The SS pin of the controller is an input only pin for the SPI slave mode only.
    Not used in master mode.

    Regards,
    Peter
    #3
    ric
    Super Member
    • Total Posts : 22758
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: SPI Pin Remapping PROBLEM 2019/06/21 15:51:39 (permalink)
    +1 (1)
    As above, SS is not controlled by the peripheral in Master mode.
    Your code driving SS low is:
    SS_MASTER = 0;

    so somewhere in your source you have #defined "SS_MASTER" to access RC0.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #4
    _kristian_
    New Member
    • Total Posts : 3
    • Reward points : 0
    • Joined: 2018/02/10 06:54:46
    • Location: 0
    • Status: offline
    Re: SPI Pin Remapping PROBLEM 2019/06/25 05:07:22 (permalink)
    0
    Hi,
    thanks for the replies but I found the solution by myself. I just missed a point in the datasheet:
    In Master mode the clock signal output to the SCK pin is also the clock signal input to the peripheral. The pin selected for output with the RxyPPS register must also be selected as the peripheral input with the SSPCLKPPS register.
     
    I just thought that in master mode I needed to select only the output pin from which the clock must be sent out, as SPI was in Master Mode, using RxyPPS register and never changed SSPCLKPPS. In the first case (RC0 selected as CLK) everything was working because SSPCLKPPS is connected after POR condition just to RC0! So, changing this register I was able to read too from my slave device.
    Thanks for the support anyway.
     
     
    #5
    Jump to:
    © 2019 APG vNext Commercial Version 4.5