Announcement

Collapse
No announcement yet.

Using a µSD without FAT format

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using a µSD without FAT format

    I have a µSD card where I have stored data raw as I used it in a Goldelox platform (the µOLED160) before. Now I'm about to port the functionality to the Picaso, which was a walk in the park thanks to 4dgl.

    Except for one thing.
    Whenever I try to do a media_WriteByte(0x00) i get the error 16, and from what I've understood, that's because the µSD is not FAT formatted. How do I use the µSD card to the Picaso without having to FAT format it? The µSD card is verified to work properly with the Goldelox.

  • #2


    The card does not need to be formatted when using the 'raw' services.
    Just make sure you init the card, and set to the required sector - just like Goldelox.

    You mention error 16,
    error 16 = bad PmmC number for a function, so I'm not sure how you are getting that unless you are trying to run code that has been compiled on Goldelox on a Picaso?
    Can you show the demo code that produces error 16 plz and we will try and figure it out.
    Regards,
    Dave

    Comment


    • #3


      Thanks for the fast response

      Here is the code I am trying to execute, down to where the error occurs, I've introduced long pauses in order to see where the execution throws the error. The error is thrown just before the print
      "print("First byte written");"

      HTML Code:
      #platform "uOLED-32024-P1_GFX2"
      #inherit "4DGL_16bitColours.fnc"
      #inherit "SEPS525.fnc"
      #inherit "LogFunction.inc"
      #inherit "defines.fnc"
      
      #constant IMAGE_HEADER_SECTOR_START_ADDRESS 0xC000
      #constant IMAGE_CONTENT_SECTOR_START_ADDRESS 0xC064
      #constant IMAGE_HEADER_SECTOR 0x33
      #constant IMAGE_CONTENT_SECTOR 0x34
      #constant IMAGE_HEADER_SIZE 0x05
      #constant COMRECEIVE_IMAGE 0xE2
      
      //Saves an image from serial stream to memory
      func SaveImage()
      var i, k, freeSector, c, headerBuf[10], width, height, loops, ok, lineCount;
      if (WaitForCom(IMAGE_HEADER_SIZE, 100))
      //Find a valid sector to store the image.
      gfx_MoveTo(0, 230);
      gfx_RectangleFilled(0, 230, screenWidth, 270, 0x0000);
      print("IMAGE_HEADER_SIZE received" );
      pause(2000);
      for (i := IMAGE_CONTENT_SECTOR_START_ADDRESS; i < 0xFFFF; i++)
      media_SetSector(0x0000, i);
      if (media_ReadByte() != IMAGE_CONTENT_SECTOR)
      break;
      else
      i := MAX(i + media_ReadByte(), 0xFFFF);
      endif
      next
      gfx_MoveTo(0, 245);
      print("free content sector set to 0x", [HEX] i );
      pause(2000);
      freeSector := i;
      for (i := IMAGE_HEADER_SECTOR_START_ADDRESS; i < IMAGE_CONTENT_SECTOR_START_ADDRESS; i++)
      media_SetSector(0x0000, i);
      if (media_ReadByte() != IMAGE_HEADER_SECTOR)
      break;
      endif
      next
      media_SetSector(0x0000, i);
      gfx_MoveTo(0, 260);
      print("free header sector set to 0x", [HEX] i , "WRITING");
      pause(2000);
      //media pointer set. Write!
      
      media_WriteByte(IMAGE_HEADER_SECTOR);
      gfx_MoveTo(0, 275);
      print("First byte written");
      pause(2000);
      endif
      //Much more irrelevant code here...
      endfunc
      
      
      func WaitForCom(var numberOfBytes, var timeOutMs)
      var i;
      while (com_Count() < numberOfBytes)
      pause(1);
      i++;
      if (i > timeOutMs)
      return 0;
      endif
      wend
      return 1;
      endfunc
      
      func main()
      var exit, comChar, i, validComChar;
      
      setbaud(BAUD_9600);
      com_Init(comBuf, 128, 0);
      mediaPresent :=  media_Init();
      
      repeat
      if (com_Count())
      validComChar := 0;
      comChar := serin();             
      if (comChar == COMRECEIVE_IMAGE)
      validComChar := 1;
      SaveImage();
      endif   
      endif
      until(exit == 1);
      endfunc
      The corresponding code, pasted in a Goldelox project just works fine, when issuing media_WriteByte(x). One more thing, the media_Init() returns 0x000C at goldelox, and 0x0001 at PICASO.

      Comment


      • #4


        I was unable to compile your code to try it - where is comBuf, mediaPresent and a few others defined? - and how big is comBuf?
        Regards,
        Dave

        Comment


        • #5
          Oh sorry, the code was uncomplete, merely for review. Here's a compileable code for it. I changed it so the code where the problem is runs directly. (Change the sectors addressed to avoid having something overwritten )
          Code:
          #platform "GOLDELOX-GFX2"//#platform "uOLED-32024-P1_GFX2"#inherit "4DGL_16bitColours.fnc"#inherit "SEPS525.fnc"#constant IMAGE_HEADER_SECTOR_START_ADDRESS 0xC000#constant IMAGE_CONTENT_SECTOR_START_ADDRESS 0xC064#constant IMAGE_HEADER_SECTOR 0x33#constant IMAGE_CONTENT_SECTOR 0x34#constant IMAGE_HEADER_SIZE 0x05#constant COMRECEIVE_IMAGE 0xE2#constant MEM_TEST 0xE3var comBuf[64];var mediaPresent;var screenWidth;//Saves an image from serial stream to memoryfunc SaveImage()var i, k, freeSector, c, headerBuf[10], width, height, loops, ok, lineCount;gfx_RectangleFilled(0, 0, screenWidth, 100, 0x0000);gfx_MoveTo(0, 0);print("save\r\n");if (1)//Find a valid sector to store the image.print("IMAGE_HEADER_SIZE received\r\n");pause(500);for (i := IMAGE_CONTENT_SECTOR_START_ADDRESS; i < 0xFFFF; i++)media_SetSector(0x0000, i);if (media_ReadByte() != IMAGE_CONTENT_SECTOR)break;elsei := MAX(i + media_ReadByte(), 0xFFFF);endifnextprint("free content sector set\r\n 0x", [HEX] i ,"\r\n");pause(500);freeSector := i;for (i := IMAGE_HEADER_SECTOR_START_ADDRESS; i < IMAGE_CONTENT_SECTOR_START_ADDRESS; i++)media_SetSector(0x0000, i);if (media_ReadByte() != IMAGE_HEADER_SECTOR)break;endifnextmedia_SetSector(0x0000, i);print("free header sector set\r\n 0x", [HEX] i , "WRITING\r\n");pause(500);//media pointer set. Write!media_WriteByte(IMAGE_HEADER_SECTOR);print("First byte written\r\n");pause(500);endif//Much more irrelevant code here...endfuncfunc WaitForCom(var numberOfBytes, var timeOutMs)var i;while (com_Count() < numberOfBytes)pause(1);i++;if (i > timeOutMs)return 0;endifwendreturn 1;endfuncfunc main()var exit, comChar, i, validComChar;exit := 0;setbaud(BAUD_9600);com_Init(comBuf, 128, 0);mediaPresent :=  media_Init();gfx_MoveTo(0, 0);print("mediaPresent: 0x", [HEX] mediaPresent);pause(1000);SaveImage();repeatif (com_Count())validComChar := 0;comChar := serin();if (comChar == COMRECEIVE_IMAGE)validComChar := 1;//Needs byte sequence of 6, beginning with 0xE2-01 : e.g. 0x E2-01-00-64-00-64SaveImage();endifendifuntil(exit == 1);endfunc

          Comment

          Working...
          X