• AVR Freaks

Hot!PIC16LF18344 SPI SDI not in SSP1BUF after read

Page: < 12 Showing page 2 of 2
Author
du00000001
Just Some Member
  • Total Posts : 3943
  • Reward points : 0
  • Joined: 2016/05/03 13:52:42
  • Location: Germany
  • Status: offline
Re: PIC16LF18344 SPI SDI not in SSP1BUF after read 2020/07/05 13:21:49 (permalink)
+2 (2)
Hi Rob,
 
as somebody happily consumed a lot of my time, I couldn't yet find the time to heck your project.,,
As you write that MCC spits out about the same configuration as what you have (and whatever I checked until now looks fine), another suspicion ever so slowly surfaced: are you absolutely sure that the uc's solder joint on RA2 is ok?
To check this, you could just use the debugger to
  1. halt the software
  2. check that GYRO-CSn is not asserted (thus H). So SPI-SDI should be floating.
  3. Now inject 3.3 V resp. 0V via TP10 and use the debugger to check for the value of Bit 2 on Port A (which is expected to toggle even when RA2 is asserted to SSPI1DAT.

PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
#21
JustRob
Super Member
  • Total Posts : 609
  • Reward points : 0
  • Joined: 2008/09/04 12:49:27
  • Location: Hudson Massachusetts United States
  • Status: offline
Re: PIC16LF18344 SPI SDI not in SSP1BUF after read 2020/07/05 13:30:52 (permalink)
0
Have you tried just looping back SDO to SDI (with the slave disconnected) to see if you see your own data?

No, and I don't have the option to do that now but when I write or read different gyro module registers I get different values on SDI.  I'll have to wait to try your suggestion.

Sometimes the obstacles in our path ARE our path!
 
https://abateandempower.com/
#22
davekw7x
Entropy++
  • Total Posts : 1888
  • Reward points : 0
  • Joined: 2012/01/16 12:01:07
  • Location: Second star on the right, straight on till morning
  • Status: offline
Re: PIC16LF18344 SPI SDI not in SSP1BUF after read 2020/07/05 16:25:34 (permalink)
+2 (2)
JustRob
I'm fairly certain my problem is in the pps assignments:
    RC0PPS = SPI_SCK_PPS;
    RC1PPS = SPI_SDO_PPS;
    SSP1DATPPS = SPI_SDI_PPS; // SPI SDI peripheral select pin and SPI_SDI_PPS is defined as 0b00010
 


You are missing the one that assigns your SCK pin to the SPICLK input function.
 
Here are my assignments that make my PIC16F18346 work with your pins (Same SPI peripheral as your chip):
    RC1PPS = 0x19;     // SPI1DAT output to RC1
    RC0PPS = 0x18;     // SPI1CLK output to RC0
    SSP1CLKPPS = 0x10; // RC0 to SPI1CLK input function <--- You need this!
    SSP1DATPPS = 0x02; // RA2 to SPI1DAT input function



Yes: as is the case for lots of PICs these days for Master mode, SPI CLK input must be assigned to the same pin as its output pin.
 
Regards,
Dave
post edited by davekw7x - 2020/07/05 16:37:47

Sometimes I just can't help myself...
#23
du00000001
Just Some Member
  • Total Posts : 3943
  • Reward points : 0
  • Joined: 2016/05/03 13:52:42
  • Location: Germany
  • Status: offline
Re: PIC16LF18344 SPI SDI not in SSP1BUF after read 2020/07/05 17:10:38 (permalink)
0
@ davekw7x
Are you sure that this one is really one of the PICs requiring an SCLK input for reception in master mode?
I originally suspected that much but couldn't find the slightest indication that this might be the case. Neither in the datasheet (showing a single shift register for RX and TX), nor in the errata. And SSP1CLKPPS is only mentioned in the context of the slave mode.

PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
#24
davekw7x
Entropy++
  • Total Posts : 1888
  • Reward points : 0
  • Joined: 2012/01/16 12:01:07
  • Location: Second star on the right, straight on till morning
  • Status: offline
Re: PIC16LF18344 SPI SDI not in SSP1BUF after read 2020/07/05 17:45:54 (permalink)
+3 (3)
du00000001
@ davekw7x
Are you sure that this one is really one of the PICs requiring an SCLK input for reception in master mode?

Yes, I am quite sure (at least for my PIC16F18346)  I do test these things, you know, before I post specific suggestions.  If it's not in the data sheet, someone should post a request for clarification in the errata.
 
Bottom line: when I comment out the SCK input PPS assignment, it reads all zeros.  When I make the assignment it works as it should.
 
Test setup: PIC16F18346 plugged into Curiosity board.
MPLABX version 5.40, XC8 version 2.20, Windows 10
 
Here's how I tested:

// Master mode SPI configuration.  SS is a separate I/O pin that
// is initialized and manipulated separately.
void init_spi()
{
    SSP1CON1bits.SSPEN = 0;     // Disable SPI module while configuring
    RC1PPS = 0x19;              // SPI1  SDO output to RC1
    RC0PPS = 0x18;              // SPI1  SCK output to RC0
    SSP1CLKPPS = 0x10;          // RC0 to SPI1 SCK input function <--- NOTE!
    SSP1DATPPS = 0x02;          // RA2 to SPI1 SDO input function

    SSP1CONbits.CKP = 1;        // SI clock idle state is high
    SSP1CONbits.SSPM = 0b0001;  // SPI Master, clk = Fosc/16 (2MHz)
    
    SSP1STATbits.SMP = 0;       // SPI input data sampled at the middle of data output time
    SSP1STATbits.CKE = 0;       // SPI transmit occurs on low to high clock
    TRISCbits.TRISC1 = 0;       // Make SDO pin an Output
    TRISCbits.TRISC0 = 0;       // Make SCK pin an Output
    ANSELAbits.ANSA2 = 0;       // Set Digital mode for SDI Input pin
    ANSELCbits.ANSC0 = 0;       // Set Digital mode for SCK Input function <--- NOTE!

    SSP1CON1bits.SSPEN = 1;     // Enable the SPI module
}

void init_spi(void);
void init_system(void);
uint8_t SPI_read_write(uint8_t);

// Test by looping SDO to SDI (Pin RC1 to RA2)
// If you don't have UART connection or for some reason can't use printf,
// You can see LED2 toggle as the LSB of the received byte changes every
// second
void main(void)
{
    // Initialize UART, LEDs, etc. --- Everything but spi
    init_system();
    init_spi();

    // I'll declare them volatile so that, if you can't use printf they
    // won't get optimized away by the compiler, and you should be able
    // to see their values with a debugger.
    //
    volatile uint8_t ch_out = 0x12;
    volatile uint8_t ch_in;
    
    while (1) { // Main loop
        LED1_Toggle();
        ch_in = SPI_read_write(ch_out); // <--- From Forum post
        LED2_LAT = ch_in & 1;
        printf("0x%02X : 0x%02X\r\n", ch_out, ch_in);
        __delay_ms(1000);
        ++ch_out; // <--- suggest a breakpoint here
    } // End of Main loop
} // End of  main()



 
Output
Compiled on Jul  5 2020 at 17:43:22 by XC8 version 2200 (c99)
0x12 : 0x12
0x13 : 0x13
0x14 : 0x14
0x15 : 0x15
0x16 : 0x16
.
.
.
 
 
[Edit]
Forgot to mention in my previous post that in addition to assigning the PPS pin to SCK input, you also have to make sure its ANSEL bit is clear.  I had to do both things to get it to work with the OP's SPI register initialization and pin assignment.
 
Regards,

Dave
 
post edited by davekw7x - 2020/07/06 07:34:38

Sometimes I just can't help myself...
#25
ric
Super Member
  • Total Posts : 28361
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: PIC16LF18344 SPI SDI not in SSP1BUF after read 2020/07/05 17:58:28 (permalink)
0
Needing both had crossed my mind, but like du00000001 I could find no mention of it in the text of the datasheet.
(It certainly is mentioned in many other datasheets)
 
I find Figure 30-1 a bit confusing.
It does show the SCK connection going via the output pin, but shows paths from before and after the TRIS buffer, supposedly selected by the CKP & CKE bits.
I think that diagram adds confusion, not clarity...
 

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!
#26
du00000001
Just Some Member
  • Total Posts : 3943
  • Reward points : 0
  • Joined: 2016/05/03 13:52:42
  • Location: Germany
  • Status: offline
Re: PIC16LF18344 SPI SDI not in SSP1BUF after read 2020/07/05 18:53:46 (permalink)
0
ric
Needing both had crossed my mind, but like du00000001 I could find no mention of it in the text of the datasheet.
(It certainly is mentioned in many other datasheets)
 
I find Figure 30-1 a bit confusing.
It does show the SCK connection going via the output pin, but shows paths from before and after the TRIS buffer, supposedly selected by the CKP & CKE bits.
I think that diagram adds confusion, not clarity...



Fig. 30-1 is not that bad.
But considering what we seem to know now, it's not showing the whole story (showing a sinle shift register with 1 clock input while there seem to be 2 SRs with differing clocks). The docs of neither chip ('344 resp. 346) give any indication about this pitfall. And microchipdeveloper still lacks information about the MSSP peripheral.

PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
#27
JustRob
Super Member
  • Total Posts : 609
  • Reward points : 0
  • Joined: 2008/09/04 12:49:27
  • Location: Hudson Massachusetts United States
  • Status: offline
Re: PIC16LF18344 SPI SDI not in SSP1BUF after read 2020/07/06 05:28:30 (permalink)
0
@du00000001
are you absolutely sure that the uc's solder joint on RA2 is ok?

Yesterday I had that very thought so I am having my tech come to verify that it is connected.  Logically a disconnect would explain my symptoms.
@davekw7x
You are missing the one that assigns your SCK pin to the SPICLK input function.

I do have that in now but my SCK has always been there but it was set to 0x18 and not 0x10.

#define SPI_SDI_PPS 0b00010 // SPI SDI RA2
#define SPI_GYRO_CS_PPS RC6PPS // SPI CS peripheral select pin
#define SPI_SCK_PPS 0b11000 // SPI SCK RC0
#define SPI_SDO_PPS 0b11001 // SPI SDO RC1

// assign peripheral pins per register 13-2
    SSP1CLKPPS = 0x10; // SPI SCK peripheral select pin
    RC0PPS = SPI_SCK_PPS;
    RC1PPS = SPI_SDO_PPS;
    SSP1DATPPS = SPI_SDI_PPS; // SPI SDI peripheral select pin
    

 
~~~ THIS WORKED ~~~
I have 0x69 on SDI
 
Note: I would think in master mode the pic would realize SCK is the same for data out and data in!
 
Thanks everybody!

Sometimes the obstacles in our path ARE our path!
 
https://abateandempower.com/
#28
du00000001
Just Some Member
  • Total Posts : 3943
  • Reward points : 0
  • Joined: 2016/05/03 13:52:42
  • Location: Germany
  • Status: offline
Re: PIC16LF18344 SPI SDI not in SSP1BUF after read 2020/07/06 06:35:24 (permalink)
0
JustRob
Note: I would think in master mode the pic would realize SCK is the same for data out and data in!

 
That's what ric and I thought as well. Fortunately Dave knew better.

PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
#29
Page: < 12 Showing page 2 of 2
Jump to:
© 2020 APG vNext Commercial Version 4.5