MMC fat init

Beta Testing discussion on mikroC PRO for PIC.
Post Reply
Author
Message
jumper
Posts: 466
Joined: 07 Mar 2007 14:36

MMC fat init

#1 Post by jumper » 20 Jan 2019 06:53

Hi,

I am testing a custom board with TFT and SD card and the PIC57K42.

Good news is that I can get the TFT to work

But I can not get the SD card to init. Fat_MMC_init() always returns 255 regardless if I have the SD card attached or not.

I have other PCB using other 18F variants and they connect to the SD card in the same way on SPI1.

Connections:

Code: Select all

Pin nr           Function on PIC               Function on SD card
41                CLK                                SPI CLK
47                SDO                               SI  data in
46                SDI                                SO data out

28                LATE.B1                          CS




I can toggle all pins manually and measure high and low levels on the SD card pins so they are connected.

Does anybody spot any mistake or have a code that doesn't return 255 from init ... or I have to bring out the logical analyzer to see what is happening?


Code: Select all


char slask[20];
unsigned char test=0;


// TFT module connections
char TFT_16bit_DataPort_Lo at LATA;
char TFT_16bit_DataPort_Hi at LATD;
sbit TFT_16bit_RST at LATF.B2;
sbit TFT_16bit_BLED at LATC.B2;
sbit TFT_16bit_RS at LATC.B1;
sbit TFT_16bit_CS at LATE.B0;
sbit TFT_16bit_RD at LATF.B3;
sbit TFT_16bit_WR at LATE.B2;
char TFT_16bit_DataPort_Lo_Direction at TRISA;
char TFT_16bit_DataPort_Hi_Direction at TRISD;
sbit TFT_16bit_RST_Direction at TRISF.B2;
sbit TFT_16bit_BLED_Direction at TRISC.B2;
sbit TFT_16bit_RS_Direction at TRISC.B1;
sbit TFT_16bit_CS_Direction at TRISE.B0;
sbit TFT_16bit_RD_Direction at TRISF.B3;
sbit TFT_16bit_WR_Direction at TRISE.B2;
// End TFT module connections

// MMC/SD Connections
sbit Mmc_Chip_Select at LATE1_bit;
sbit Mmc_Chip_Select_Direction at TRISE1_bit;
// end of MMC/SD






void main() {
 delay_ms(50);

    TRISF.B0=0;                                                       // set STATUS LED PIN AS OUTPUT
    TRISC.B2=0;                                                       // FORCE BACKLIGHT ON
    LATC.B2=1;                                                        //
    
  TFT_Init_ILI9481(320, 480);
  delay_ms(10);

  
  
  TFT_16bit_Fill_Screen(CL_YELLOW_16bit);
  delay_ms(1000);
  TFT_16bit_Write_Text("TFT 16-bit Library DEMO, WELCOME !", 0, 0);
  delay_ms(1000);
  
  Unlock_IOLOCK();
  PPS_Mapping_NoLock(41, _OUTPUT, _SCK1);
  PPS_Mapping_NoLock(47, _OUTPUT, _SDO1);
  PPS_Mapping_NoLock(46, _INPUT, _SDI1);

  Lock_IOLOCK();
  
  SPI1_Remappable_Init_Advanced(_SPI_REMAPPABLE_MASTER_OSC_DIV64, _SPI_REMAPPABLE_DATA_SAMPLE_MIDDLE, _SPI_REMAPPABLE_CLK_IDLE_LOW, _SPI_REMAPPABLE_LOW_2_HIGH);
  Delay_ms(10);

  test=Mmc_Fat_Init();
  delay_ms(1000);
  bytetostr(test,slask);
  delay_ms(1000);
  TFT_16bit_Write_Text(slask, 0, 100);
  delay_ms(1000);
  
  
  //Start_TP();
     
     while(1){
          STAT_LED=~STAT_LED;
          delay_ms(1000);
     
     }


janni
Posts: 5373
Joined: 18 Feb 2006 13:17
Contact:

Re: MMC fat init

#2 Post by janni » 20 Jan 2019 13:46

Hi,

Which library do you use for SD card? I'm asking because the linker does not remap SFRs in libraries precompiled for older processors, which means that any library has to be specifically compiled for K42 (or K83) processors. Mmc_FAT16 library, like practically all libs coming with the compiler has a version for new processors, but if you use another precompiled library then you cannot do much about it.

jumper
Posts: 466
Joined: 07 Mar 2007 14:36

Re: MMC fat init

#3 Post by jumper » 20 Jan 2019 16:13

Hi

I use the library that is included in the 7.30 beta. I was hoping by selecting
Pic18f57k42 in the project settings and tick the box for mmc in the library tree it should
Work.. That is how i have done before

How can i know which library is actually loaded and if it is compiled for that pic?

Or it could be pps problems

Or spi problems

Maybe i have to solder some lines and see if there is any traffic at all.

janni
Posts: 5373
Joined: 18 Feb 2006 13:17
Contact:

Re: MMC fat init

#4 Post by janni » 20 Jan 2019 16:36

jumper wrote:I use the library that is included in the 7.30 beta. I was hoping by selecting
Pic18f57k42 in the project settings and tick the box for mmc in the library tree it should
Work..
It should, at least libraries listed in Library Manager have versions precompiled for K42 processors.
How can i know which library is actually loaded and if it is compiled for that pic?
They're listed in processor *.mlk definition file.
Or it could be pps problems

Or spi problems
These libraries also have versions precompiled for K42 processors. Which does not mean they're perfect. Hopefully any problems will be detected in beta version.

janni
Posts: 5373
Joined: 18 Feb 2006 13:17
Contact:

Re: MMC fat init

#5 Post by janni » 20 Jan 2019 18:02

jumper wrote:Or it could be pps problems
Yeah, that seems to be it. PPS_Mapping_NoLock is not working properly for this chip. Try setting the PPS registers manually (and save ca. 2k of code memory :wink: ).

Code: Select all

  Unlock_IOLOCK();
  RC3PPS=0x1E;           // SCK1 on RC3
  RC5PPS=0x1F;           // SDO1 on RC5
  SPI1SDIPPS=0x14;       // SDI1 on RC4 (default)
  Lock_IOLOCK();
Using predefined constants:

Code: Select all

  Unlock_IOLOCK();
  RC3PPS=_SCK1;          // SCK1 on RC3
  RC5PPS=_SDO1;          // SDO1 on RC5
  SPI1SDIPPS=_RC4;       // SDI1 on RC4 (default)
  Lock_IOLOCK();

jumper
Posts: 466
Joined: 07 Mar 2007 14:36

Re: MMC fat init

#6 Post by jumper » 21 Jan 2019 07:42

Hi,

Tested both versions and still 255 as return value from the MMC fat init.

Maybe I have time to look for SPI traffic later this week

User avatar
filip.grujcic
Posts: 822
Joined: 14 May 2018 08:34

Re: MMC fat init

#7 Post by filip.grujcic » 21 Jan 2019 10:26

Hello,

Could you please zip and attach your project here for inspection?

Kind regards,
Filip Grujcic

jumper
Posts: 466
Joined: 07 Mar 2007 14:36

Re: MMC fat init

#8 Post by jumper » 22 Jan 2019 06:47

Hi Filip,

If you tell me your email address I am happy to send you the zipped project, I'd rather not upload it here since it is used for a customer's product.


@Janni, if you want to see the project please PM me your email address and I will send it to you.

User avatar
filip.grujcic
Posts: 822
Joined: 14 May 2018 08:34

Re: MMC fat init

#9 Post by filip.grujcic » 22 Jan 2019 10:36

Hello,

You can send it to filip.grujcic@mikroe.com or submit a support ticket on our helpdesk.

@janni
Could you please elaborate on the issue with PPS_Mapping_NoLock function?
I've tested it multiple times, and have never had any problems with it.

Kind regards,
Filip Grujcic

jumper
Posts: 466
Joined: 07 Mar 2007 14:36

Re: MMC fat init

#10 Post by jumper » 23 Jan 2019 03:31

Answer from ME team:

Hi,
The error is in your PPS_Mapping functions. The first parameter, which is the pin number, has a range from 0 to 42.
You, however, have put 46 and 47 which are out of range and simply cause the PPS_Mapping function to exit with a 0.
Use the predefined constants for appropriate pins, for example:
PPS_Mapping_NoLock( _RC3, _OUTPUT, _SCK1 );
PPS_Mapping_NoLock( _RC4, _INPUT, _SDI1 );
PPS_Mapping_NoLock( _RC5, _OUTPUT, _SDO1 );
Correct this in your code and it should work then.

So obviously "pin number" in that sentence was not referring to the package pin but instead the name of pin in question such as RC3.

Anyway now the MMC init returns 0 so that part is working.

And maybe update the help file so other people don't make the same mistake since the example doesn't use predefined constants ;-)

Code: Select all


PPS_Mapping
Prototype char PPS_Mapping(char rp_num, char input_output, char funct_name);
 
Returns 0 - if peripheral pin mapping wasn't successful. 
255 - if peripheral pin mapping was successful. 
 
Description Sets desired internal MCU module to be mapped with the requested pins.

Parameters : 

rp_num: Remappable pin number. Consult the appropriate datasheet for adequate values. 
input_output: Sets requested pin to be used as an input or output. 
funct_name: Selects internal MCU module for usage. 

 
Requires Nothing.
 
Example PPS_Mapping(15, _INPUT, _RX2_DT2);   // Sets pin 15 to be Input, and maps RX2/DT2 Input to it
PPS_Mapping(5, _OUTPUT, _TX2_CK2);   // Sets pin 5 to be Output, and maps EUSART2 Asynchronous Transmit/Synchronous Clock Output to it

 

Thank you!

janni
Posts: 5373
Joined: 18 Feb 2006 13:17
Contact:

Re: MMC fat init

#11 Post by janni » 23 Jan 2019 13:23

jumper wrote:And maybe update the help file so other people don't make the same mistake since the example doesn't use predefined constants ;-)
Yeah, the description in Help is highly confusing. This 'pin number', one is supposed to find in datasheet, apparently refers to 'PPS Input Selection' code. How is one supposed to infer from 'Remappable pin number' that input pin code should be used for output pin selection :roll: ?

Why not simply write
rp_num: pin code according to datasheet 'PPS Input Selection' definition
:?: Mentioning that pin codes are already predefined in library certainly wouldn't hurt.

Post Reply

Return to “mikroC PRO for PIC Beta Testing”