|
|
View previous topic :: View next topic |
Author |
Message |
RoMar
Joined: 22 May 2020 Posts: 6
|
Problem with SD Card 18F2550 |
Posted: Sat May 23, 2020 6:00 am |
|
|
Quote: |
Hi,
I have some problems with printing from a file in SD Card (module SDcard with 2Gb).
To see printf() - I use
>> printf(usb_cdc_putc, " process message");
And for this, I'm using serial monitor, there is a lot in internet.
I'm using ccs (5.008 version) to program a pic18F2550. I'm using USB CDC communication,
and also, I'm using the recent files mmcsd.c and fat.c (I got this from here).
The CCS compiles everything, it is OK (some warnings, but it works). All code is here .
With this code, I can open and close a file (just for testing).
But, the big problem is, when I try to print (to see) what is inside this file - I just get trash.
I think, I'm doing right with this line (main.c):
>> printf(usb_cdc_putc, fatprintf(&myfile));
- but doesn't work...
I tried other ways to get what is in the file, but unfortunately I got always the same trash.
I don't know what is going, is there a problem with the files "mmcsd.c" and "fat.c"?
(It are the most recent files for SDcard!)
Could anyone give an help here?
Best Regards.
|
Ttelmah wrote: | How are you doing the 5v to 3.3v conversion?.
And the 3.3v back to 5v?.
Working with the 2550, means that real care is needed to get this
conversion to work at all well.... |
Hi Ttelmah,
Thanks for reply.
Do you mean I always need converte 5->3.3V and 3.3->5V, even I'm using a sd card module ?
I thought with this module I didn't need to use that converter, I was wrong.
But in this case, maybe I just need to converte 3.3 to 5V - to send data to the pic18F2550.
I was looking for that converter, do you think this integrate "74AHCT125"
is a good choice for this propose, or there is a better choice?
Best Regards, thanks for replying |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19589
|
|
Posted: Sat May 23, 2020 6:13 am |
|
|
You need _data_ about the module. A circuit ideally. Or a proper signal
description. It may well have a buffer (looks like it might), but if (for
instance) this is designed for an Arduino, the output may well not go high
enough to be correctly handled by the PIC.
The SPI input on the 5V PIC requires signals that go up to 4v. The Arduino,
only requires signals that go up to 2.4v..... |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9269 Location: Greensville,Ontario
|
|
Posted: Sat May 23, 2020 6:30 am |
|
|
Nowadays most (all ?) external peripherals are 3 volt devices. The EASIEST way to interface to a PIC, is to use an 'L' version (low voltage) of a PIC or a PIC rated for 3-5 volt operations. The PIC18F46K22 is one such device.
There is a 'sticky' at the top of this forum that has improtant information about usnig SD cards... |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19589
|
|
Posted: Sat May 23, 2020 10:33 am |
|
|
OK. It's not going to work with the PIC, unless you use software SPI
on a pin with a standard TTL input buffer. They are driving the 74HC125
off 3.3v, which means the output signal will not reach the level needed
for the PIC SPI input.
Well done PCM. Impressive searching. |
|
|
empty
Joined: 13 Jan 2018 Posts: 15
|
|
Posted: Sat May 23, 2020 4:22 pm |
|
|
It's recommended to add another 3V3 to 5V converter to the SD card module
because when working with PIC hardware SPI module the min voltage of
logic 1 level of SDI pin is 4V (as Ttelmah said)!
You may use 74LVC125, the 74AHCT125 is also a good choice.
Actually, I connected PIC with SD card using hardware SPI module where I
didn't use any 3V to 5V level shifter and every thing was working without any
problem (at least for some days), so you may try that before buying any level shifter!
Otherwise use software SPI (works well but very slow).
Also, the compiler built-in SD card and FAT libraries may not work with your
SD card (2GB), this link may give you some help:
https://simple-circuit.com/pic18f4550-sd-card-read-write-files/ |
|
|
empty
Joined: 13 Jan 2018 Posts: 15
|
|
Posted: Sat May 23, 2020 4:29 pm |
|
|
That module uses 74VHCT125 chip to convert 5v to 3v3, the SD card data
output pin (DO) is also connected to a buffer where its enable pin is
connected to CS, this allows connecting multiple devices to the same
SPI bus.
Since the 74VHCT125 is powered with 3.3V the max buffered output
voltage is 3.3V, so that module doesn't solve the problem (converting
3.3V to 5V)! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19589
|
|
Posted: Sun May 24, 2020 12:32 am |
|
|
Also, looking at the published circuits for the module, I realise it does
not show the required pull-up resistors. These are needed for card insertion
detection, and to ensure the wake up mode of the card. Without these,
it is not guaranteed that the card will wake up in the mode required for the
CCS drivers. Problem..... |
|
|
RoMar
Joined: 22 May 2020 Posts: 6
|
|
Posted: Sun May 24, 2020 5:55 am |
|
|
Hi all,
Thanks for all your replies. I was seeing all of them.
And you are very right. I did some tests with the oscilloscope and I confirmed that voltage
on SD Card output (MISO), this voltage is 3.3V. Clearly below the value for the pic.
I like the idea about the Catalex MicroSD card adapter. For this, I must to buy a new one.
The PIC18F46K22 seems to me also a good idea. But I have a pickit2, and it is not enough
for this pic. Thanks, this is a good idea, sometime later, I'm thinking to get a new one programmer.
Thus, at short time, only it left me to try look about the 74VHC125.
With the oscilloscope, I saw all pins on pic18F2550 outputs it were 5Volts, it is ok (not problem at all)
because the "SD module" can convert 5V to 3.3V, for the SDcard.
For the SD output (MISO) it is 3.3V. It seems to me, if applying here that integrate (74VHC125), I can resolve
this issue. With 74VHC125 supplied with 5Volts, it can convert 3.3 to 5Volts and maybe I will can get data on the pic.
Anyone could says me if, in this way, I'm good chances to resolve this?
Best Regards |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9269 Location: Greensville,Ontario
|
|
Posted: Sun May 24, 2020 6:53 am |
|
|
I use the PIC18F46K22 and the 'smaller' 26K22 for 99% of all projects. While it is bigger and more powerful than required, by using ONE PIC, I've been able to creat a large library of custom functions and drivers that I KNOW work.
For USB connection, I use a $2 USB<>TTL module. When yo add up the cost of connector,LEDs, reg, etc as well as R&D time, it really only adds maybe a $1 BUT saves a LOT of codespace as NO USB driver is needed.
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19589
|
|
Posted: Sun May 24, 2020 7:26 am |
|
|
The PIckit2, can program the K22 chips. You need the updated device file
found here:
<https://www.microchip.com/forums/m270347-p4.aspx#547444>
|
|
|
RoMar
Joined: 22 May 2020 Posts: 6
|
|
Posted: Wed Jun 03, 2020 7:27 pm |
|
|
Hi,
I followed your recommendation about get a pic18F26K22. And I was all the time working in this.
Thanks Ttelmah , about your suggestion to update my Pickit2, sometimes I use the old versions a time too long,
because when I do this update, I have always bad luck, but not now. This time everything worked fine.
Now, I have a super pickit2.
About that idea about 74VHC125, I think it is better do it later.
At this moment, I have a pic18F26K22, I got a module PC2102, but now I get more difficulties.
Then, I tried connect 18F2550 to PC, using this module PC2102 (USB<>TTL module). I made some changes,
and it works.
Thus, I done this changes for FUSES:
Quote: |
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
#use delay(clock = 48MHz)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) // Initialize software UART
|
With module PC2102, I don't need USB libraries (thanks Jay), but I must maintain same fuses and the same
clock = 48MHz (for USB), meanwhile I have crystal clock = 20MHz, I think this works because I put #fuse PLL5.
At the end, all this is working, it communicate via RS232 (Tx/Rx)->USB with the PC, like I need, fine.
The trouble now, nothing this is working with pic18F26K22. This doesn't work with that fuses.
I tried many times and read a lot this new datasheet, well many things are much different. I don't know
where I must begin.
I want pic18F26K22 communicates with PC, and I would like to view the printf() on Hyperterminal.
Then, there is another question when connect this PIC to SD card the communications will need 3.3V,
Will I need the #fuse NOLVP, LVP? sorry these many questions (and about my english, I think it is not quite good),
I'm lost here, if it is possible I appreciate some help.
Regards |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19589
|
|
Posted: Thu Jun 04, 2020 12:50 am |
|
|
The k22, cannot run at 48MHz from 20MHz.
Your choices are to use the internal oscillator and run at 32MHz,
or use the crystal and run at 20MHz, or fit a 12MHz crystal and run at
48MHz. |
|
|
RoMar
Joined: 22 May 2020 Posts: 6
|
|
Posted: Sat Jun 13, 2020 4:57 pm |
|
|
Hi
It works. I really appreciate all your help.
This circuit is working very well using a crystal 12MHz (4XPLL). For this pic:
Code: | #FUSES HSH, PLLEN, NOPLV.
#use delay(crystal = 12Mhz, clock = 48MHz) |
And then, I can see all information in SD files.
Everything is working pic18F26K22 + SDcard + CP2102<TTL - USB>
Thanks guys.
Regards |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19589
|
|
Posted: Sun Jun 14, 2020 1:15 am |
|
|
Well done.
Progress. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|