Fatfs on Atmega1284

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

Hi,

I would like to use fatfs library on Atmega1284 to read and maybe write data from SD card. I have used the files from this example:

https://github.com/noushar-najee...

 

I am using this test code and the SD card is mounted successfully, I get correct values for total and free space but always I get error 12 (FR_NOT_ENABLED) for f_open, no matter if I try to open for reading or writing. 

        fresult=f_mount(&fs,"1:",1);
	if(fresult!=FR_OK)
	{
		glcd_fillRectangle(0, 0, 319, 20, bgcolor);
		sprintf(tmp, "Error mounting SD card #%d", fresult);
		WriteString12(2, 2, tmp, red);
	}
	else
	{
		glcd_fillRectangle(0, 0, 319, 20, bgcolor);
		WriteString12(2, 2, "SD card mounted successfully", green);

		f_getfree("1:",&fre_clust,&pfs);
		total=(uint32_t)((pfs-> n_fatent-2) * pfs->csize * 0.5);
		sprintf(buffer,"Total:%lu KB",total);
		WriteString12(2, 22, buffer, yellow);
		free_space=(uint32_t)(fre_clust * pfs->csize * 0.5);
		sprintf(buffer,"Free :%lu KB",free_space);
		WriteString12(2, 42, buffer, yellow);
		_delay_ms(1000);

		fresult = f_open(&fil, "log.txt", FA_OPEN_ALWAYS|FA_WRITE);
		if (fresult == FR_OK)
		{
			glcd_fillRectangle(0, 0, 319, 20, bgcolor);
			WriteString12(2, 2, "File created", green);
			//WriteString12(2, 2, "File opened", green);
			glcd_fillRectangle(2, 62, 30, 20, bgcolor);
		}
		else
		{
			glcd_fillRectangle(0, 0, 319, 20, bgcolor);
			sprintf(tmp, "Error creating file #%d ", fresult);
			WriteString12(2, 2, tmp, red);
			//WriteString12(2, 2, "Error reading file", red);
		}
	}

 

Using another library (https://github.com/nandra/AVR/bl...) I can read text files and display bitmap images on a chinese 3.2 inch lcd connected to Atmega1284.

 

I hope somebody can provide some advise. If this is important, I am using Atmel Studio 7. Let me know if I have to provide other details. Thank you!

This topic has a solution.
Last Edited: Wed. Apr 15, 2020 - 02:09 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

VIO47 wrote:
write data from (sic?) SD card

"write" usually means to the card ?

 

VIO47 wrote:
I get error 12 (FR_NOT_ENABLED)

So have you looked-up what that error means?

 

Documentation is here:  http://elm-chan.org/fsw/ff/00index_e.html - Note the 'Resources' at the bottom of that page

 

There are also FatFs tutorials - and plenty of previous discussions - right here on this forum.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Wed. Apr 15, 2020 - 12:10 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi awneil, please accept the correction " ... read and maybe write data from/to SD card..." smiley

 

I have read the information on the elm-chan website before but seems that I have missed something, "log.txt" vs. "1:log.txt":

 

f_open(&fil, "1:log.txt", FA_WRITE | FA_CREATE_ALWAYS);

 

Now it works. Thank you for the reply. 

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

VIO47 wrote:
Now it works. 

Jolly good! Now please mark the solution.

 

See Tip #5 in my signature

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi awneil, I have tested the reading function too and it works, now I can continue my COVID-19 quarantine project :)

 

All the best and stay safe! The attached picture as proof.

 

Attachment(s):