Problem with SPI/SDCARD PR scale and 64Mhz operation

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Post Reply
Mathy
Posts: 333
Joined: Mon Oct 05, 2009 2:39 pm
Has thanked: 30 times
Been thanked: 33 times

Problem with SPI/SDCARD PR scale and 64Mhz operation

Post by Mathy »

Hello,

I have a little problem with the SDCARD component when my MCU running at 64 Mhz.

I use the SDCARD define section and this line to setup the SPI PR scale :

#define MX_SPI_PR_SCALE_2 4

This works very well at 16 or 32 Mhz, I can set 4, 16 or 64 and see the clock speed change on my scope.
The SDCARD works well, I can write data.

But, when running my MCU at 64 Mhz, my SDCARD don't work.
I thought that it was due to the too high speed of the spi line so I set the PR scale from 4 to 16 and 64 but without any result.
On my scope, I see that there are no difference between the pr scale value. The clock speed seems to be the same.

The oscillator is well configured because of my LED blinking at the right speed and my RS232 terminal understand what my MCU send to him.

Can you have a look at this ?

Thank you.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Problem with SPI/SDCARD PR scale and 64Mhz operation

Post by Benj »

Hello,

There are two speeds of operation with the v5.5 FAT component. The initialisation cannot be more then 400KHz. The actual run time speed can go up to around 20MHz.

The component begins with a 1:16 prescaler by using these lines of code in the definitions.

#define MX_SPI_PR_SCALE_1 16
#define MX_SPI_PR_SCALE_2 16
#define MX_SPI_PR_SCALE_3 16
#define MX_SPI_PR_SCALE_4 16

Once the card has been initialised the SPI operation speed is automatically ramped up to full speed 1:4.

You could try reducing the initial speed to 1:64 by changing the definition lines like this.

#define MX_SPI_PR_SCALE_1 64
#define MX_SPI_PR_SCALE_2 64
#define MX_SPI_PR_SCALE_3 64
#define MX_SPI_PR_SCALE_4 64

If you don't edit all four instances then you cannot be sure that your edits will have gone into the component if you are using more then one SPI channel reference in your program.

Mathy
Posts: 333
Joined: Mon Oct 05, 2009 2:39 pm
Has thanked: 30 times
Been thanked: 33 times

Re: Problem with SPI/SDCARD PR scale and 64Mhz operation

Post by Mathy »

Hello,

Ok !
I understand now why I had two different speed when starting the program.

I don't know why but it is impossible to make it work at 64 Mhz.
I tried with all the possible value ( 4, 16 or 64 ).

At 64 Mhz with a prescaler of 1/16 or 1/64 it don't work.
At 32 Mhz, I can use 1/4 that it is faster than 1/16 or 1/64 at 64Mhz

But it is not very important. I tried to increase speed to write much faster on the sdcard but it is not the best idea.
As you can see in my other topic, I tried with the example you give me but without any result.

Mathy
Posts: 333
Joined: Mon Oct 05, 2009 2:39 pm
Has thanked: 30 times
Been thanked: 33 times

Re: Problem with SPI/SDCARD PR scale and 64Mhz operation

Post by Mathy »

Hello,

I tested deeply and I think I made a mistake yesterday.
I said that changing the prescaler value in the customization code impact the spi clock frequency :

#define MX_SPI_PR_SCALE_1 ( 4, 16 or 64 )

But no, I'm looking the clock when the macro tried to initialise the SDCARD ( but with no SDCARD into the slot ), and the clock frequency is exactly the same with 4, 16 or 64 prescaler value.
When I insert the SDCARD into the slot, I can see the clock frequency increase.
I think the prescaler parameter during the init macro is defined in your INIT_FAT macro and not in the defines.

The initialize frequency may be too high at 64 Mhz for the SDCARD.
So I started my program at 32 Mhz to initialize the sdcard and then, I set up the internal oscillator at 64 Mhz and It works....BUT :

The clock frequency is too high for my board at 64 Mhz with a prescaler of 4.
The clock signal is not clean. I don't know if it is due to the layout or the components on my board ( my famous accelerometer and the sdcard ).

As I said in my previous post, it is not very important, It was just for your information.

Have a nice weekend.

Post Reply