Please may I ask for assistance? I need a reliable method of interfacing an SPI SD/MMC card to a dsPIC. At the moment I'm using a 1k8/3k3 voltage divider on the 5v ----> 3.3v signals, and connecting the 3.3v ----> 5v signals straight to port.
It's working ok upto about 3-5Mhz, with anything above 7.5Mhz causing misread bits. Here's the actual signals;
dsPIC --------------- SD/MMC CLOCK (5v) ----> CLOCK (3.3v) SPI OUT (5v) ----> DATA IN (3.3v) CHIPSEL (5v) ----> CS (3.3v) SPI IN (5v)
Didn't find your answer? Ask the community — no account required.
P
PeteS
x-posted to s.e.d. where you are likely to get answers.
The divider you have should work fine at those speeds, with the caveat of track length and signal capacitance. Have you looked at the signals with a scope (using a 10x probe)?
If you use buffering, simply get 3.3V devices with 5V tolerant inputs (all the usual suspects make them) or use transmission gates for the path from the processor to the MMC/SD card. I am using some TI devices in an SDIO implementation but that's because I have bidirectional data lines.
As to the Card -> processor lines, and without looking at the DSPic datasheet, what is the Vih spec for the DSPic inputs? If they are true CMOS, then 3.3V is at the lowest Vih (2/3 Vcc). If they _are_ CMOS, then you'll need to translate those as well - use a 5V device with TTL level inputs.
Cheers
PeteS
A
Alison
Hi Pete, thanks for your reply
I'll try to get the scope back this weekend. I've been using a logic analyser for almost everything in this project.
Nods
The ports are ST: Schmitt Trigger input with CMOS levels. ViH is... 0.8v
So it should be fine. But.. I have a 100 Ohm resistor on the 3.3v DATA OUT line which connects in series to the dsPIC input port. If I do not do this then communication becomes even more unreliable. Most of the diagrams on the net do not have any kind of buffering on this line. I added it as a guess.
My plan of action today is to build a piggyback board to go inbetween the dsPIC and main breadboard. The purpose of this is to reduce the uncertainty as much as possible. The SD card will be within about 1cm of the dsPIC rather than about 10cm away as at present on the end of solid signal wire.
Does that sound like a likely culprit? Breadboards have always been fine here for low Mhz kit prior to getting them onto PCBs, and this is the first time I've really pushed passed about 5Mhz in a design. The SD card has to be as close as directly possible to the dsPIC to maintain reliability at high Mhz?
no, thank you.
J
Joe G (Home)
Level shifters may do the trick
formatting link
formatting link
formatting link
formatting link
P
PeteS
Inline
The limits of analysers is that they don't detect actual voltage levels, of course, beyond what they have been set up for as a switching threshold.
0.8V would be ViL (max), not ViH(min).
Which indicates ringing on the line without the resistor.
10cm on breadboard might be ok if the wires are routed appropriately. As I note above, you seem to have ringing on the line. Try a 22 ohm series resistor - that's what I have apart from the 4k7 (mostly) pullups. A 10 - 22pF loading cap might help too, although you should not need it on a properly laid out PCB.
Once on a circuit board, 10cm is not a long way at 25MHz, but you should probably set the line impedance controlled and terminate at each end. Without looking at the datasheets I can't give any direct assistance (and as I have to make dinner shortly I don't have the time ;)
Cheers
PeteS
A
Alison
Nods. I need to pickup the scope. Normally I wouldn't be doing electronics, my understanding is basic. I'm the developer :-) The electronics engineer is going through a mid-life-crisis and doesn't want to do electronics as it's not making him happy :-)
This is where the that 0.8v ViH figure came from;
formatting link
That's a page from the dsPIC4013 manual. 70138D.pdf
That answers that then. That sounds good.
I'll look into that. I'm making a piggy back board to go straight under the chip at the moment, so that the card is connected with solid copper.
I'm preparing myself to go for a buffer.
It'll go onto it's prototype pcb once I've cleared up some of this.
Hope you enjoyed it. We made turkey vegetable things on scewers. ;)
A
Alison
Thanks Joe, will read up shortly. :-)
R
rickman
You might be better off finding someone else who is qualified. Although this does not sound like a complex design, even simple logic level interfacing is not hard to do wrong.
Yes, notice that the table says 0.8 Vdd, not 0.8 volts. That means the input thresholds are relative to the magnatude of the Vdd supply. In your case it would be 4.0 volts. No 3.3 volt logic will supply this high an output signal. If you want to meet the spec, you will need a dual supply level shifter on the DATA OUT signal from the SD Card. Or you can just use a transistor. A simple NPN transistor with two resistors will do the job as well if not better than a buffer. If you can't handle the inversion in software, you will need two transistors and three resistors.
"Indicates" and "is" are two different things. Diagnose ringing with a scope. I seriously doubt that you have enough ringing to cause a problem. Even if you had some ringing on the DATA OUT line, unless it were very severe, it would only delay the settling time. At the rates you are working at it is not likely that this truely is the cause of your problem. I suspect it is more likely that the ViH vs. VoH are what is hurting you. But the scope and/or volt meter will tell you better. When the output rises, the initial slope is fairly rapid, but it slows as it approaches Vdd. So if the clock is slow enough the VoH has risen to the full Vdd. With a faster clock the data is sampled on the still rising edge and may not have made it to the actual threshold voltage of the PIC input.
Make sure it is powered by 5 volts and the output rises fully to Vdd. Also make sure the input is compatible with 3.3 volt logic. I am pretty confident you can live a rich full life on this signal without a series resistor once you get the voltage levels correct.
A
Alison
That's not an option. My main job is as an adult escort and I've recently come back from Dubai for £3k. Nose through my /pub directory. There is no one else. No ones going to work on a project for 20y.o. Atari computers. This is out of enjoyment to achieve something other than wandering around shops buying underwear all day. ;-) I have a Computer Science degree which is useless, I did it because I enjoyed working with computers and simplicity, not jumping through corporate hoops for Directors who can just about type with one finger.
This is just enjoyment and achievement for me to do something more.
I have no control over the interface. It's a hardware implemented SPI port. The closest I come is to the transmit and receive registers.
You're not going to like how I did it though......
The voltage dividers I've replaced with 5k 18-turn pots. They're set to kick out about 4.2v at the moment having checked on the meter, that's the CHIP SELECT, DATA IN, and, CLOCK lines. The 100ohm resister has been removed from the DATA OUT line.
It's running reliably at 15Mhz. I just kept on adjusting the pots until the data became stable. The input lines are about 4v. Mmmmmm. Maybe... The DATA OUT is being driven higher now... The DO is being driven higher, about
4.2v
What does that tell you about the signals?
I have lots of transistors here, bags of different sorts from a workshop clearance a few years ago BC547C ??
Thanks,
Alison
A
Alison
Hi Rickman... ;-)
Could you elaborate on this? I can do this now but I'm not sure what goes where in terms of; R1 R2 R3 T1 T2
Roughly what values? and where do things go, BCE?
I'm fully stocked on resistors, and have quite alot of different PNPs and NPNs.
Alison
R
rickman
Interesting. I checked out every file including the logs. I can't say I feel your pain, but I get the idea.
If it's a paying job they will!
ch
Tell me about it. I am at a point where I could retire if I wanted to. I have found that jobs provide little satisfaction and I am about fed up with it. Too bad I'm too old to do what you do!
Well, you may not like what I am going to tell you.
rt.
That is the point of interface where you can invert the data if you want. But it is 6 of one and half dozen of the other. You can get a dual buffer in a package as small as a transitor if I can remember which one we use a lot. It is tolerant of up to +-7 volts on the input, but what you need is for it to be 5 volt powered and I don't recall if it is.
Here is a dual N-FET which does not need the input resistor. EM6K1 is in stock at digikey. Or if that package is too small for you to solder, the FDC6305N is a bit larger and should work too. Just connect one FET input to the DATA OUT signal (a light pulldown will keep it from floating when the SD card is not inserted) with a pullup resistor to 5 volts. Connect the other FET to the first drain in the same manner with the second drain to the PIC input. This will give you a clean 5 volt transistion and your problems should be solved.
the
out
No, I don't like how you did it. And you won't like why it works. By driving the SD card inputs to 4.2 volts you are forward biasing the protection diodes in the SD card. This pulls the Vdd on the card up higher so that the output voltage is higher. This is *very* bad. Don't expect your card to live a rich full life if you continue to do this.
Much better would be to use a buffer on the DO output or to use the transistors. The BC547C should work just fine. The package is a bit large, but I guess that is not an issue. Connect two of them in the same manner as above, but with a 1 Kohm resistor in series with the base of the first. Use 1 Kohms for the two pullups and you can ignore the series resistor on the second.
It is hard to describe well, so I made a drawing.
formatting link
R
rickman
The drawing from my other post did not inititially include the BCE markings, so I added them. You can check the data sheet for the part to see where each function is on the package. This will be very non-critical in terms of transistor selected or resistor value. Just make sure you use an NPN or N-channel device.
A
Alison
Hi Rickman,
thanks :-)
I've since tried a 7407 out of my junk box which I've found out why it was in there, it's a dud.
A level shifter is another option? I've seen mention of a zener and two resisters, yet have as yet to get past companies wanting to sell me examples and datasheets..
The 4.2v has been dropped back down to 3.3v but in my mind it makes me believe that the SD DATA OUT was the problem, in that the dsPIC wasn't registering a '1'. I was getting impatient, and had enough cards to risk blowing one or two.
It will reliably register a '1' at low Mhz
Y
Yuriy K.
If your want a working solution, use level translation IC. They will work up to 30+MHz and easily available from catalog suppliers like Digikey and Mouser.
SN74LVC04A @ 3.3Vcc Use two inverters in series as a 5V tolerant non-inverting buffer.
SN74LVC3G34 @ 3.3Vcc - three non-inverting buffer.
A
Alison
tnx :-)
The reason why I believed that a 3.3v '1' would register as a '1' on a CMOS dsPIC port is that there are quite a few examples on the net that say it works... That was my mistake, believing what I read on the Internet.
"It will work, but isn't within spec' so it's unreliable. It's reliable at a few Mhz at very most, when the parts are designed to go upto about 30Mhz."
"dsPIC parts CANNOT be directly interfaced to 3.3v devices!"
Alison
A
Alison
Hi Yuriy,
..
thanks :-) apologies for missing you out.
All of this I'm logging.
Alison
R
rickman
The DO to SPI IN will only work the buffer is powered from 5 volts or the output can be pulled up to 5 volts with a resistor. The signals in the other direction don't need buffers at all, the resistors should work just fine.
Alison, you have the transistors in your bin, right? They should do the job fine. Go ahead and try them. If they don't work, then something else is wrong.
A
Alison
Hi Rickman,
Here's the outcome. With the circuit it fails at 7.5Mhz. If the circuit is bypassed, it fails when switching to 15Mhz.
I've tried it with; two BC547C, two BC548, and two 2N3904.
Checking the circuit on the meter all is fine, it chucks out 5v. It just seems to be passing out at higher speeds when the circuit is used.
What does that tell us? If the board fails at 15Mhz without the circuit, and the board fails at 7.5Mhz with the circuit?
The transistors here are good for 100Mhz. They are only 100mA though?
This R&S CP/M logic analyser with a 'storage' scope add-in board thing that I have here, I'll try to use it tomorrow if I can figure out how to trigger it, as I don't think I can use an external trigger which I would otherwise set in software on another pin when switching Mhz to capture what's going on.
Just wondering why I'm getting faster speeds without the circuit. Oh don't worry (I'm sure you're not) I'm not criticising at all, very grateful for the help tbh :-) It should be more reliable with.
Alison
R
rickman
I am starting to think the voltage issue is a red herring. Where did you get your code to configure and operate the SPI port on the PIC? The basic operation of the SPI port has four possible configurations which differ in the polarity of the clock and the edge that is used to clock in the data. There actually is no spec on the SPI bus. It was invented by Motorola (now Freescale but that may have changed again) when they came out with one of their many MCUs, perhaps the HC11.
If your code was from scratch, then I would suggest that you work on making sure this is right. If the code is from a reliable source that has verified the correct configuration in this chip, then I still say verify it yourself! I'll try a couple of ascii drawings.
Sel ___|--------------------------------- Clk ______|---|___|---|___|---|___|---|__ Data __X=======X=======X=======X=======X=
Sel ___|--------------------------------- Clk __|---|___|---|___|---|___|---|___|-- Data __X=======X=======X=======X=======X=
This will look right if you view it in a fixed width font. You may need to copy it to a text editor and view it in a font like "Terminal" in Notepad. The first configuration has data changing on the falling edge of Clk. The second configuraton is using the rising edge of the clock to shift the data out. In each case, the data should be read into the PIC on the opposite edge. This gives you the most setup and hold time. If you try to sample it on the same edge that shifts out the data, you will be reading it when it is changing.
The clock can also be inverted in polarity, but that also changes the edge the data is shifted on so it will be the same problem. You can try changing the two configuration parameters in the software and see which ones work best. Then you should verify all this with the scope when you get it.
So maybe you don't need the voltage buffers anyway. But it would be a good idea to keep them in as the voltage problem can get worse if the temperature of the circuit gets extreme one way or the other. Voltage thresholds are very sensitive to temperature.
Y
Yuriy K.
Check datasheet for the HCT/AHCT series. Strangely enough, VinH >= 2.0V, VinL The signals in
Yeah, right. Especially at 10+ MHz.
If the goal is to solve the problem, use an appropriate components. In this particular case use IC with voltage translation capability.
If the goal is to entertain yourself, try different combinations of discrete components. Some of them might even work.
Which way to choose depends on what the *real* goal is.
WBR, Yuriy.
"Resistance is futile"
Join the Discussion
Have something to add? Share your thoughts — no account required.
Didn't find your answer?
Ask the community — no account required
Report Content
You are reporting this content to the moderators. They will look at it
ASAP.