-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
about SD-card initialization #4
Comments
Thank you for your tips! I will check it out soon! |
Is it correct if I add a line |
In the library |
At first glance this is the correct thing to do, however looking at the code https://github.com/raspiduino/arv32-opt/blob/f831c56cb7dc86fe63289bde70ce3d3ea5242d68/spi.c#L20C1-L21C36 there is a binary OR made instead of a plain write to SPCR and SPSR. This could make a mess depending on the constants as bits that may need to be cleared won't be cleared. You have to check carefully or change this code i think. |
I have tried this, and it actually worked! I increased the clock to 8 MHz, and the average speed got up to 1100Hz. But the emulator will hang if I connect pin 9 to GND (to check speed), for some reason. If I just leave it there and don't check the speed, it will work. At start: Peak speed(?): |
Did you release pin 9 again? There is a loop in your code that will wait until pin 9 is high again: https://github.com/raspiduino/arv32-opt/blob/f9d3f5ff05c057cd85f6ce3f32edb875d328cb75/main.c#L301C13-L301C44 |
Yes, I released it. That's weird. I think maybe because my SD card is damaged, sometime it also unreadable. I will try switching to another SD card. |
There is a related issue #5 which also occurs when the SPI clock is 8MHz. Changed it back to 1MHz solved the problem, but I don't know why it will hang at 8MHz |
I am afraid your commit a3a42ad did not change the SPI frequency to 8MHz (Fosc/2) but only to 250kHz (Fosc/64). This is because as i said you are doing an binary OR instead of a plain write to SPCR and SPSR.
However i am not sure this explains the instability/problems you are encountering. :( But in any case i would suggest fixing sdcard.c (by removing the OR) and try again with max speed. If this does not work maybe you have some electrical issue (signal integrity, ...)? Can you check with a scope? |
But if that's true, then I don't understand why the effective emulated speed is even higher than the speed when I run with 1MHz SPI clock.
Stupid me. I should have changed it to I'm not really good at plain AVR C registers tho, sorry for that. |
Yes, exactly. For the speed issue i am not sure, i think you should fix sdcard.c and then test again. And if possible check the real clock speed of the SPI-bus with an oscilloscope or logic analyzer. |
I just do that and the SD read failed 10 times in a row. I will try again later, probably my SD card problem. |
I will see if i have a SD card somewhere and try myself if time allows. |
Line 17 in 3c6f041
That's not correct! If you want a pullup (which shouldn't be needed btw) you must write a '1' to EDIT: correction :( |
Ok, so SPI2X does not work. I guess SD in SPI-mode have a maximum clock frequency <=4MHz? Does anybody know? This is weird... However with 4MHz (XTAL/4) it works fine with my own SD-card routines. I used those because i am obviously more familiar with them. You can find them on my github but please note that they are AGPLv3+, so probably not compatible with your project. Of course you can look at them to see how they work anway, but you probably can't copy them to your project (you should specify a licence!). My remark about the wrong register for Pullup also applies to the pin for dumping the emulator state. Should i make another PR to fix this? EDIT: Speed is just above 2kHz for my test, Linux has started it's internal stuff, currently "devtmpfs: initialized". I will stop here to not write to much to the SD card. |
Wait, so it should be
Line 250 in a493989
Wait, this code actually writes to PORTB , to enable pullup. I also didn't write anything to that pin's DDRB bit, so it should be 0 (input), right? So I don't really understand why the pullup code for pin 9 has wrong register used.
Thank you for testing. 2KHz is way much better than the normal 700Hz! |
I apologize, i got confused. :( For the pullup it is indeed PORTx. It is not DDRx however, writing a '1' there will set the pin to output. |
Thanks for the great project! sdcard.c Next up I plan to port the code to an Atmega1280 so I can increase the number of cache buffers with the extra RAM. |
Thank you! I will definitely try that soon! I would be happy to accept if you make a PR |
I will close this as changes are merged to main. Feel free to reopen or create a new issue report if you want. Thank you! |
Hi,
just a note about this:
If i remember correctly the standard says that for initialization the speed should be <400kHz, but you can switch much higher once the initialization is done. Don't forget the SPI2X-bit for even more speed!
Maybe this helps...
The text was updated successfully, but these errors were encountered: