atmega328 and FatFS

Go To Last Post
12 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

please help. i don't know if is a wiring problem or software problem. i used lcd and uart for debugging. 

when i used fatFs the program stuck on "res = f_open(&Fil, "file.txt", FA_OPEN_EXISTING | FA_READ);" and sometimes stock on "f_gets(buff, 10, &fil);"

, nothing came out from lcd neither uart. i have turn off one of uart/lcd to see the program still stuck or not. and i put print to the end program before while(1) to see the program is stuck or cannot transmit the data to uart/lcd.

but when my finger touching on pin sck-cs-mosi the program run flawless. and once program can read poem.txt then i push the reset button, the program still good.
but the problem came again when i plug off the power button and plug it in again. the program stuck again.

if i add more sentence on poem.txt the program became worst although after i push the reset button, but when i hold my finger on pin sck-miso-mosi the progrom running good.

i thought this is a power failure so i add delay for vcc to catch up and cap. but still has same problem. but what make me think this is not the power failure is, once the program can read poem.txt with my finger touching pin sck-miso-mosi the program work fine although if i don't touch again with my finger and reset the micro without touching that pin again.

i disable the timer for "disk_timerproc();" using atmega328, 8mhz internal clock, using Sandisk 2GB microSD with Fat32 with 5 txt files inside that.
when the program stuck for 3-5 second and touch the pin program work again. after that, the program still work until i plug off and in again the power.	

any clue? maybe the type of microsd? or formating the fat32?

note : i found new clue. if im not plug the micro SD the program still stuck, and soon when i thouch the pin, the program transmit "initialize error" which means the program is not stuck on f_open or f_gets.

 

* Moved out of the Tutorial thread. Moderator *

 

Last Edited: Fri. Jan 29, 2016 - 11:55 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Please do not cross post. People will see it if you just post your question in one thread.

 

Also why have you changed the font in that - it makes it close to unreadable.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Im sorry, because i thought it was a FatFs problem, i don't know about the font before. was my mistake too, that was my default.

Last Edited: Fri. Jan 29, 2016 - 01:43 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ok. so do i need to disable that?  but why, if after micro can read the SD, then i push reset button, the micro just fine? only when first powering or on long idle

Last Edited: Fri. Jan 29, 2016 - 01:55 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If I am reading that right and you say you have some electronics that "kind of work" when you poke your finger at it but otherwise does not that sounds like a pretty fundamental wiring issue. It could be as simple as a bad joint that the finger just happens to help make contact but fingers and human bodies are also good at introducing some capacitance which might be "filtering" something. It's possible the finger may be helping to ground something. Either way I'd start with a check of the integrity of the wiring.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

If I am reading that right and you say you have some electronics that "kind of work" when you poke your finger at it but otherwise does not that sounds like a pretty fundamental wiring issue. It could be as simple as a bad joint that the finger just happens to help make contact but fingers and human bodies are also good at introducing some capacitance which might be "filtering" something. It's possible the finger may be helping to ground something. Either way I'd start with a check of the integrity of the wiring.

i try to poke my finger until it can read the txt inside mmc. after it can read and display to lcd i move the mmc module with antistatic stylus around else where, and the program stil work just fine, without i touching it. 

now i'll take a look to SPI or any while loop, 

so the problem its like waiting something on loop, but after i touched the program just get the condition on that loop. and when i move around without i touched again, the program still good. until the power goes off and on again or if i wait about 1-2 mnt its happened again.

i wonder is that any wrong on my mmc format? 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ops, maybe i found the problem, but not tested to my micro, i checked the program is based on ffsamp-jun22 for atmega32 i moved to atmega328 and SOCKINS and SOCKWP is still on the PB4 and PB5 which is on SPI pin on m328. cheeky

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That would explain a lot. If it's reading the pins that are floating inputs then it could well be that poking a finger in their general direction grounds them.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

That would explain a lot. If it's reading the pins that are floating inputs then it could well be that poking a finger in their general direction grounds them.

yups the problem is match...

but new mystery here. since i comment all the code inside void disk_timerproc and also turn off the timer interrupt. so basically the pin is never read by the program. and then i search for another .c or .h on fatfs folder that might using SOCKINS and/or SOCKWP but i can't found one. the only one SOCKINS and SOCKWP is uses is in disk_timerproc void on mmc.c 

any suggest?
 

Last Edited: Fri. Jan 29, 2016 - 02:22 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

still get same problem after i put #if 0 on #define SOCKINS and SOCKWP. any other pin that used on program that used pin beside SPI and sdcs? or maybe pin assignment that i have to change outside mmc.c?
 

#define SS      (1<<PB1)
#define MOSI  	(1<<PB3)
#define MISO   	(1<<PB4)
#define SCK     (1<<PB5)

#define CS_LOW()	PORTB &= ~SS			/* CS=low */
#define	CS_HIGH()	PORTB |= SS			/* CS=high */
#if 0
#define SOCKINS		1//(!(PINB & 0x10))	/* Card detected.   yes:true, no:false, default:true */
#define SOCKWP		0//(PINB & 0x20)		/* Write protected. yes:true, no:false, default:false */
#endif 
#define	FCLK_SLOW()	SPCR = 0x52		/* Set slow clock (F_CPU / 64) */
#define	FCLK_FAST()	SPCR = 0x50		/* Set fast clock (F_CPU / 2) */

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

problem solved !! after checking my connection, monitoring with oscilloscope, and digital analyzer just make me more crazy. then i changed the mmc module from this

 

 

to this


the first module is using buffer ic for level shifter, and the second module is using resistor as voltage divider. so both module can communicate with 5v SPI
and its seems the ic on first module is been using on some mmc arduino shield.

with the second module, FatFs work just fine. but with the first module i got the problem like i mention above.
but with first module i don't find any error with dharmani neither with arduino library.

idk, maybe because 3 state power_off void. 

maybe if anyone using the first module and/or arduino module like above and work fun with FatFs just tell me. so we know the problem is only on my module or FatFs that can't communicate with first module.

 

 

note : i can't find the datasheet about the ic, but its look like similar with this datasheet http://www.ti.com/lit/ds/symlink...

 

nb : with arduino shield and arduino SD lib, i can work with FAT. and with second module and FatFs i can work with FAT too. but we'll see if i get fault since FatFs only can work with FAT16 and FAT32 only

Last Edited: Fri. Jan 29, 2016 - 04:14 PM