MikroC for PIC32 with Riverdi Click and 7" TFT

General discussion on mikroC PRO for PIC32.
Post Reply
Author
Message
ColinI
Posts: 42
Joined: 29 Mar 2017 21:19

MikroC for PIC32 with Riverdi Click and 7" TFT

#1 Post by ColinI » 16 Nov 2018 00:46

Hi,
After learning a bit with a PIC18 on a EasyPIC Pro V7 (MikroC + Visual TFT) I have moved to an EasyPIC Fusion V7 (MikroC for PIC32 + Visual TFT) with a P32MZ2048EFH144 MCU to start actually coding for my project.
On the previous system using a Riverdi Click and 7" TFT (MIKROE-2288) the combination worked quite well. For the last 3 days I have been unable to display anything on the Fusion/Riverdi combo. It is plugged in to MikroBus 1.

The project for testing this is a simple circle drawn on the screen with VisualTFT. At the moment the Riverdi does not even flicker and remains black.

The first issue was with building a new pattern for the Riverdi and TFT. Several attempts failed at finish saying the file was corrupt. It appears if any config item is left blank or 'todo' this happens. I have since gotten it to create a new pattern based on the working settings from the FT812 pattern used with the PIC18:

I have tried FT800 through FT813, SPI1,2,3 and several frequencies/prescaler values.

These are the settings being used for the fusion similar for different FT8xx attempts :

Code: Select all

// TFT module connections
sbit FT812_RST at LATC1_bit;
sbit FT812_CS at LATC2_bit;
sbit FT812_RST_Direction at TRISC1_bit;
sbit FT812_CS_Direction at TRISC2_bit;
// End TFT module connections

const TFT812Display VTFT_FT812_CONFIG_DISPLAY =
{
  48000000,        // Frequency          = main clock frequency
  0,               // OutRenderMode      = 0 normal, 1 write, 2 read
  0,               // RenderReadScanLine = scanline for read render mode
  0,               // RenderWriteTrigger = trigger for write render mode (read only)
  1056,            // hCycle             = number if horizontal cycles for display
  46,              // hOffset            = horizontal offset from starting signal
  800,             // hSize              = width resolution
  0,               // hSync0             = hsync falls
  10,              // hSync1             = hsync rise
  525,             // vCycle             = number of vertical cycles for display
  23,              // vOffset            = vertical offset from start signal
  480,             // vSize              = height resolution
  0,               // vSync0             = vsync falls
  10,              // vSync1             = vsync rise
  0,               // Rotate             = rotate display
  0x0000,          // OutBits            = output bits resolution
  0,               // OutDither          = output number of bits
  0x0000,          // OutSwizzle         = output swizzle
  0,               // OutCSpread         = output clock spread enable
  1,               // PClockPolarity     = clock polarity: 0 - rising edge, 1 - falling edge
  2,               // PClock             = clock prescaler of FT812: - 0 means disable and >0 means 48MHz/pclock
};

The SPI initialization is as follows and is based off of the FT800 from the BoardDefs patterns:

Code: Select all

SPI1_Init_Advanced(_SPI_MASTER, _SPI_8_BIT, 8, _SPI_SS_DISABLE, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_IDLE_2_ACTIVE);
// I have tried SPI1, 2 and 3
I have tried the 2 MCU configurations provided with the software, P32MZ2048EFH_PLL_8_to_200MHz.cfgsch and P32MZ2048EFH_PLL_24_to_200MHz.cfgsch with various frequencies from 4 to 200 MHz.

In experiments with the onboard EasyTFT320x240 board set to 80Mhz it ran so slowly it took many seconds to draw a screen. Setting the MCU to 4MHz the screen redraw was less than a second. The EasyTFT is still far to slow for my purposes and I haven't seen any way of speeding it up in the forums.

Searches through the forum for Riverdi and Fusion have shown a couple topics with similar issues but none that helped so far.

Any help/advice getting this screen running is appreciated.
Thanks
Windows 7 & 10 64 bit
PIC Clicker, PIC32MX Clicker
EasyPIC Pro v7 with PIC18F87J60, PIC18F87K22
EasyPIC Fusion v7 with PIC32MZ2048EFH144, PIC32MX795F512L, P33FJ256GP710A
Flip & Click with P32MZ2048EFH100
Easy TFT, GLCD, 7" TFT
MikroC

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

Re: MikroC for PIC32 with Riverdi Click and 7" TFT

#2 Post by filip.grujcic » 16 Nov 2018 11:46

Hi,

The correct SPI module for mikroBUS1 is SPI6. You also need to use PPS to map SPI pins appropriately.
I will attach a working example project below.

As for the configuration schemes, both set MCU clock to 200MHz, you can't just pick any frequency from 4 to 200, it has to be 200MHz.
Schemes' names refer to which oscillator is on the MCU card:
8 to 200 means 8MHz oscillator is on the card and is used as input to PLL which then sets the clock to 200MHz
24 to 200 means 24MHz oscillator is on the card.

If you have any other questions, let me know.

Kind regards,
Attachments
Riverdi7 - PIC32MZEFH144.zip
(671.08 KiB) Downloaded 157 times
Filip Grujcic

ColinI
Posts: 42
Joined: 29 Mar 2017 21:19

Re: MikroC for PIC32 with Riverdi Click and 7" TFT

#3 Post by ColinI » 16 Nov 2018 21:24

Hi Filip,
Thanks for your quick response. The project you provided works and is much appreciated.
A couple things to note...
Since your project is working well I saved the scheme and the board def to use and reference.

I tried starting a new project from scratch, selected Visual TFT Project, gave it a name, checked Open Configuration bits window, no additional files added on the next window. Selected the board def imported from the project you provided.
Both select none and select all have been tried on the library manager in the next window. If no sources was selected there's usually no errors. All sources yields large numbers of errors, usually solved by unchecking libraries until only the necessary ones are left that match your project.
Once finish is clicked the various files open and it gives an error with the following info, "Config file not found or corrupted. Failed to load config file Error occured in attempt to read file : nil" This error does not occur with any of the default board defs provided with the software.
Clicking OK brings up the configuration bits and VTFT settings where your board def is the one selected with all settings looking OK when compared to loading the file from your project mcp32 file.
To ensure the configuration bits are set properly the scheme you kindly provided is then loaded.
Draw a simple object on the screen, hit F12 and then rebuild all sources, once no errors are found - build and program.

At this point the screen remains black, not even a flicker on a power cycle. Previous experience tells me this is enough to draw a simple object onscreen if everything is correct.

One other thing to note, the issue with the easypicfusion_v7_P32MZ2048EFH144 SDK is back when creating a new project. I have posted about it before where the only available option is mikrobus_gpioInit. This is occurring on windows 7 and 10 machines originally in MikroC for PIC and now in PIC32. Loading a project where it didn't disappear brings it back. It seemed to be solved a while back but it is getting frustrating trying to solve quirks rather than learning programming.

I'll be spending the weekend attempting to figure out what's going on with this and will post a reply if there's any headway.
Any ideas or recommendations to get these various issues solved is welcome.
Thanks again.

Previous posts:
viewtopic.php?f=88&t=73534
viewtopic.php?f=88&t=73319
Windows 7 & 10 64 bit
PIC Clicker, PIC32MX Clicker
EasyPIC Pro v7 with PIC18F87J60, PIC18F87K22
EasyPIC Fusion v7 with PIC32MZ2048EFH144, PIC32MX795F512L, P33FJ256GP710A
Flip & Click with P32MZ2048EFH100
Easy TFT, GLCD, 7" TFT
MikroC

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

Re: MikroC for PIC32 with Riverdi Click and 7" TFT

#4 Post by filip.grujcic » 20 Nov 2018 10:14

Hi,

Could you please zip and attach the newly created project here? (the one that doesn't work).
Try reinstalling your compiler as well (as administrator). I'm really not aware of this issue.

Kind regards,
Filip Grujcic

ColinI
Posts: 42
Joined: 29 Mar 2017 21:19

Re: MikroC for PIC32 with Riverdi Click and 7" TFT

#5 Post by ColinI » 20 Nov 2018 23:32

Hi Filip,
While trying to figure these issues out it's hard to even guess as to how many re-installs have been done of both the PIC and PIC32 MikroC software. Currently only PIC32 software is installed. It's not functioning flawlessly but at least the issues have work-arounds. If you would like to remote control to have a look we can arrange something.

After doing a file compare on a newly created project AAAA_driver.c and your _driver.c file from the zip there were some differences. It looks as though the import/export of defs isn't working correctly.
Just going to highlight the important differences:

Code: Select all

//Newly created project, this is with the board def that was detected upon loading your project
//TFT module connections
sbit FT812_RST at LATB3_bit;
sbit FT812_CS at LATC2_bit;
sbit FT812_RST_Direction at TRISB3_bit;
sbit FT812_CS_Direction at TRISC2_bit;
// End TFT module connections

void Init_MCU() {
   JTAGEN_bit = 0;
   ANSELB = 0;
   ANSELC = 0;
   FT812_RST_Direction = 0;
   FT812_CS_Direction = 0;

   Unlock_IOLOCK();
   PPS_Mapping_NoLock( _RPC1, _OUTPUT, _SDO2 );
   PPS_Mapping_NoLock( _RPC4, _INPUT, _SDI2 );
   Lock_IOLOCK();

   SPI2_Init_Advanced(  _SPI_MASTER,
                                        _SPI_8_BIT,
                                        100,
                                        _SPI_SS_DISABLE,
                                        _SPI_DATA_SAMPLE_MIDDLE,
                                        _SPI_CLK_IDLE_LOW,
                                        _SPI_IDLE_2_ACTIVE );
}
Where your working file has them slightly different:

Code: Select all

//working project
// TFT module connections
sbit FT812_RST at LATC1_bit;
sbit FT812_CS at LATC2_bit;
sbit FT812_RST_Direction at TRISC1_bit;
sbit FT812_CS_Direction at TRISC2_bit;
// End TFT module connections

void Init_MCU() {
   JTAGEN_bit = 0;
   ANSELB = 0;
   ANSELC = 0;
   FT812_RST_Direction = 0;
   FT812_CS_Direction = 0;

   Unlock_IOLOCK();
   PPS_Mapping_NoLock( _RPF8, _OUTPUT, _SDO6 );
   PPS_Mapping_NoLock( _RPF2, _INPUT, _SDI6 );
   Lock_IOLOCK();

   SPI6_Init_Advanced(  _SPI_MASTER,
                                        _SPI_8_BIT,
                                        100,
                                        _SPI_SS_DISABLE,
                                        _SPI_DATA_SAMPLE_MIDDLE,
                                        _SPI_CLK_IDLE_LOW,
                                        _SPI_IDLE_2_ACTIVE );
}
After modifying the newly created file with your settings it works.
Trying to create a board def from scratch still fails with that error, the attempt is attached in case you wish to compare it to a standard.
The question no longer seems to be what's wrong with the project file it's what's wrong with the creation/loading of board defs?
Btw, if run as admin is unchecked then loading a scheme also gives an error. I have checked permissions for the folders, they are full for admins and my user so should not be the problem.
Any idea as to where to go from here?

Lastly, is there a reference that shows the mikrobus 1 & 2 settings with regards to the MZ0248EFH144? It's not exactly clear in the data sheet, would never have figured out SPI6 from there at my current level/lack of expertise.
Thanks
Attachments
Riverdi_7_FT812.zip
(1.26 KiB) Downloaded 119 times
Windows 7 & 10 64 bit
PIC Clicker, PIC32MX Clicker
EasyPIC Pro v7 with PIC18F87J60, PIC18F87K22
EasyPIC Fusion v7 with PIC32MZ2048EFH144, PIC32MX795F512L, P33FJ256GP710A
Flip & Click with P32MZ2048EFH100
Easy TFT, GLCD, 7" TFT
MikroC

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

Re: MikroC for PIC32 with Riverdi Click and 7" TFT

#6 Post by filip.grujcic » 21 Nov 2018 12:51

Hi,

The project I sent you was originally written for Clicker 2 for PIC32MZ which has the same but slightly different MCU, and all I did was change the code manually to adapt it for Fusion board, so that's why board def stayed the same, and every time you create a new project with it it will load the old board def (for Clicker 2).
I suggest you just create a new pattern from scratch and fill in the fields accordingly and then save it.

The problem with loading schemes usually happens if the MCU name in the scheme doesn't match the one that's selected in the compiler (you can open these config schemes with any text editor and change the MCU name at the top), however, one thing to note is that names of config schemes shouldn't have space in them or else the compiler might generate an error when you try to load them.

As for the reference where you can see which SPI module is used on mikroBUS1, it's a little bit tricky.
You need to open the schematic for Fusion board, and the schematic for MZ2048EFH144 MCU card.
From this you can see that MISO and MOSI pins are RF8 and RF2.
Now you have to open the datasheet for PIC32MZ family, find the section for PPS and see which SPI module can be mapped to RF8 and RF2 pins.
Take a look at the two screenshots below - it should make things clearer.

If you happen to have any other questions, let me know.

Kind regards,
Attachments
Screenshot_4.jpg
Screenshot_4.jpg (216.13 KiB) Viewed 3183 times
Screenshot_3.jpg
Screenshot_3.jpg (160.27 KiB) Viewed 3183 times
Filip Grujcic

ColinI
Posts: 42
Joined: 29 Mar 2017 21:19

Re: MikroC for PIC32 with Riverdi Click and 7" TFT

#7 Post by ColinI » 22 Nov 2018 19:30

Hi Filip,
It is slowly becoming more clear, thank you for your explanations and help. There's a lot more to learn about this new PIC compared to the old PIC18.
I have tried several times to build a new board def for the screen/click board, it always fails with the previously mentioned error. It does seem to work, even with the error, so for now it's not stopping progress. The SDK issue has even settled down a bit, now that I know to look for those 3 missing files and always add all PLD and includes before checking the SDK in the library manager.

While trying to understand more behind the scenes by going through the SDK includes, definitions, etc one thing that became obvious is the SDK is already correct for the EFH.
From __epf_32MZ2048EFH144_GPIO.c:

Code: Select all

static uint8_t _getSCK_1 ()                         { return RD15_bit;    }
static uint8_t _getMISO_1()                         { return RF2_bit ;    }
static uint8_t _getMOSI_1()                         { return RF8_bit ;    }
Currently the SPI bus for the screen is setup without the SDK, which brings a couple questions to mind.
Can that work alongside the SDK needed to use the MRAM click board?
How difficult is setting up the Riverdi click & screen to work with the SDK, are there steps that could be followed?

So far I haven't been able to communicate with the MRAM at all with this PIC, even the example doesn't work. It appears there's no EMCL file for the EFH series and MRAM.
That seems like it might be the problem, does one exist or is it something I can create?

You did say to let you know if there are more questions... :)

Thanks again
Windows 7 & 10 64 bit
PIC Clicker, PIC32MX Clicker
EasyPIC Pro v7 with PIC18F87J60, PIC18F87K22
EasyPIC Fusion v7 with PIC32MZ2048EFH144, PIC32MX795F512L, P33FJ256GP710A
Flip & Click with P32MZ2048EFH100
Easy TFT, GLCD, 7" TFT
MikroC

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

Re: MikroC for PIC32 with Riverdi Click and 7" TFT

#8 Post by filip.grujcic » 23 Nov 2018 16:03

Hi Colin,

That's alright, we are here to help.
Indeed PIC32MZ family is a lot more complex than PIC18.

Onto your questions:
VTFT code and mikroSDK should be able to work together, however, I would say it's rather difficult making it work. :)
I tried MRAM Click example and it indeed didn't work on PIC32MZ, due to incorrectly written board def for this MZ apparently. I will notify our developers so they will address this.

Fear not, for there is a workaround!
I have modified those files and I will attach them below - the entire folder, actually.
Extract it and place those files in:
C:\Users\Public\Documents\Mikroelektronika\mikroC PRO for PIC32\Packages\mikroBUS Board Definition API\Uses

Another file I attached is the modified main .c file of the MRAM example - so, either replace yours or just copy/paste the code.
Try the example after these changes and let me know if it works - do not forget about the configuration scheme and a PPS config bit which has to be set to "allow multiple reconfigurations".

In the end, the path of least resistance would be for me to send you the source code of MRAM Click example, so that you don't have to use mikroSDK in your Visual TFT code, but rather just the bare functions for communicating with the click board.

Let me know how you wish to proceed.

Kind regards,
Attachments
Uses.zip
(172.87 KiB) Downloaded 119 times
Click_MRAM_PIC32.zip
(1.09 KiB) Downloaded 112 times
Filip Grujcic

ColinI
Posts: 42
Joined: 29 Mar 2017 21:19

Re: MikroC for PIC32 with Riverdi Click and 7" TFT

#9 Post by ColinI » 27 Nov 2018 22:35

Hi Filip,
I have had a few days to play with the files you sent and they have allowed considerable progress to be made. The SDK and Riverdi seem to work together decently enough though there are some inexplicable artifacts appearing during screen redraws but they seem to be only once timer1 is activated or if a buffer is the wrong size.
There's myriad other things to learn but that's to be expected starting PIC and C from scratch.
In a previous post the MikroC for PIC version of the MRAM source was made available for download. Having the PIC32 source would be useful, especially once the actual project gets underway and my skills improve.
Well, on to learning all about structures, timers and interrupts.
Thank you very much for the assistance, there will be many more questions no doubt. :D
Windows 7 & 10 64 bit
PIC Clicker, PIC32MX Clicker
EasyPIC Pro v7 with PIC18F87J60, PIC18F87K22
EasyPIC Fusion v7 with PIC32MZ2048EFH144, PIC32MX795F512L, P33FJ256GP710A
Flip & Click with P32MZ2048EFH100
Easy TFT, GLCD, 7" TFT
MikroC

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

Re: MikroC for PIC32 with Riverdi Click and 7" TFT

#10 Post by filip.grujcic » 28 Nov 2018 09:42

Hi,

In that case you already have the source code, it's the same for PIC32 as it's written using mikroSDK, so they share the same library.
The only thing that might be different is the main .c file which in this case isn't, if I remember correctly, but even if it is, it's publicly available regardless.

Kind regards,
Filip Grujcic

Post Reply

Return to “mikroC PRO for PIC32 General”