• AVR Freaks

Hot!18F46k40 MSSP SPI Modes and SD-cards

Author
AndersG
Super Member
  • Total Posts : 207
  • Reward points : 0
  • Joined: 2008/08/05 04:51:24
  • Location: 0
  • Status: offline
2020/06/22 23:37:20 (permalink)
0

18F46k40 MSSP SPI Modes and SD-cards

Hi!
I am debugging an issue where I use FATFs to access an SD card and it works nicely with simple resistive dividers and a FET to go from 5V to 3.3V, but not when I use a TXB0104 level shifter.
Does anyone else find the various SPI modes confusing? :)
 
From ElmChans docs:
Thus the SPI mode 0 (CPHA=0, CPOL=0) is the proper setting to control MMC/SDC, but mode 3 (CPHA=1, CPOL=1) also works as well in most case. A pull-up on the DO cannot be omited, or some cards will fail initialization process.
So, exactly how should the bits be set on a 18f46k40 to get spi mode 0? Right now do I have:
CKP=0
CKE=1
SMP=0
 
What I see now, strangely is that when I do the initial send to the card:
 
 Set DI and CS high and apply 74 or more clock pulses to SCLK.
In the PIC18 version this is:
 
 sd_init();
 for (n = 10; n; n--) sd_rx(); /* 80 dummy clocks */

 
I see DI, ie data out from SPI go low, briefly on the last clock of every rx and I suspect that is why the card fails initialisation.
#1

5 Replies Related Threads

    AndersG
    Super Member
    • Total Posts : 207
    • Reward points : 0
    • Joined: 2008/08/05 04:51:24
    • Location: 0
    • Status: offline
    Re: 18F46k40 MSSP SPI Modes and SD-cards 2020/06/23 23:27:43 (permalink)
    0
    OK. This is an existing design. I have two identical boards with the same FW, but prototyping this on existing boards is difficult, so I am breadboarding up just the processor, buffer and SD-socket to be able to test properly.
     
    What I saw was really weird, ie comparing the board with the resistive divider/fet and the one with TXB0104. When you init the SD card, you keep CS low and feed in 74 or more clock pulses. At that point the SD card should output data to show it is there, but the TXB0104 variant does not. I tried different SD cards and checked all other signals...
     
    I will post back when I have the breadboard circuit up and can test further.
    #2
    AndersG
    Super Member
    • Total Posts : 207
    • Reward points : 0
    • Joined: 2008/08/05 04:51:24
    • Location: 0
    • Status: offline
    Re: 18F46k40 MSSP SPI Modes and SD-cards 2020/07/03 02:15:40 (permalink)
    0
    OK. The breadboard prototoype works with a clock up to 4MHz, but not 16, but that is probably due to the breadboard (capacitance, crosstalk). Time to create a revised PCB with the TXB0104 I guess..
     
    And go through the motions of renewing those $€{ license files manually as you absolutely have to have the PC turned on the day the license renews... :(
    #3
    RISC
    Super Member
    • Total Posts : 5776
    • Reward points : 0
    • Status: offline
    Re: 18F46k40 MSSP SPI Modes and SD-cards 2020/07/03 16:11:39 (permalink)
    +1 (1)
    Hi,
    You should really avoid breadboards..as you said there have very significant capacitance and some fake issues show up as signals frequency gets higher....especially with SPI...
    Regards

    For support make sure to check first here : http://microchipdeveloper.com
    There are hundreds of PIC, AVR, SAM...which one do YOU use ?
    #4
    AndersG
    Super Member
    • Total Posts : 207
    • Reward points : 0
    • Joined: 2008/08/05 04:51:24
    • Location: 0
    • Status: offline
    Re: 18F46k40 MSSP SPI Modes and SD-cards 2020/07/08 05:50:09 (permalink)
    -1 (1)
    I agree on principle, but it is easier said than done when prototyping. So I use them, but keep an eye out for the issues I know they cause. Creating a new PCB for every iteration of a design is simply not practical.
    #5
    upand_at_them
    Super Member
    • Total Posts : 585
    • Reward points : 0
    • Joined: 2005/05/16 07:02:38
    • Location: Pennsylvania
    • Status: offline
    Re: 18F46k40 MSSP SPI Modes and SD-cards 2020/07/08 07:01:44 (permalink)
    0
    AndersGOK. The breadboard prototoype works with a clock up to 4MHz, but not 16, but that is probably due to the breadboard (capacitance, crosstalk).

     
    Is that the MCU clock, or the SPI clock?  I have several PIC/SD projects on breadboards and have had no issues.  And I'm running the PIC's at 32MHz.
    #6
    Jump to:
    © 2020 APG vNext Commercial Version 4.5