Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 15:54 10 Nov 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Color problem - ILI9481 driver for MM2

Author Message
erbp
Senior Member

Joined: 03/05/2016
Location: Australia
Posts: 195
Posted: 11:44am 21 Nov 2017
Copy link to clipboard 
Print this post

Hopefully this is something Matherp can comment on.

I have one of the 4" 320 x 480 IPS ILI9481 screens on an E28 Micromite using the loadable driver for MM2 provided by Peter in this thread. I am getting weird results with the colors being displayed on the screen, sometimes the color displayed is nothing like what it should have been - e.g. bright green instead of a light tan! I only have one of these screens so can't try another to see if maybe the screen is defective, but it does seem to do everything else correctly.

I have created a small test program that displays samples of various colors (which illustrates the problem) and I have run this program on a 7" SSD1963 connected to an E64 and the colors displayed are as I expected them to be - see example screen images below for comparison.

Below is the ILI9481 screen image:



And the next one is for the 7" SSD1963 screen:


Some of the colors change a bit from what they looked like on the screens to the naked eye, but not so much that tan turns to green or copper turns to black (4th row across, top image)

Below is the code for the program producing these images - maybe if someone else has one of these screens working they could try the program and advise if they get the same results as I did or if the result is more like the second image above (i.e. correct).

CLS RGB(Black)

Box 4, 6, 72, 72, 0, 0, RGB(63,0,0)
Text 40, 78, "(63,0,0)", "CT", 1, 1, RGB(White), RGB(Black)

Box 84, 6, 72, 72, 0, 0, RGB(127,0,0)
Text 120, 78, "(127,0,0)", "CT", 1, 1, RGB(White), RGB(Black)

Box 164, 6, 72, 72, 0, 0, RGB(191,0,0)
Text 200, 78, "(191,0,0)", "CT", 1, 1, RGB(White), RGB(Black)

Box 244, 6, 72, 72, 0, 0, RGB(255,0,0)
Text 280, 78, "(255,0,0)", "CT", 1, 1, RGB(WHite), RGB(Black)


Box 4, 102, 72, 72, 0, 0, RGB(0,63,0)
Text 40, 174, "(0,63,0)", "CT", 1, 1, RGB(White), RGB(Black)

Box 84, 102, 72, 72, 0, 0, RGB(0,127,0)
Text 120, 174, "(0,127,0)", "CT", 1, 1, RGB(White), RGB(Black)

Box 164, 102, 72, 72, 0, 0, RGB(0,191,0)
Text 200, 174, "(0,191,0)", "CT", 1, 1, RGB(White), RGB(Black)

Box 244, 102, 72, 72, 0, 0, RGB(0,255,0)
Text 280, 174, "(0,255,0)", "CT", 1, 1, RGB(WHite), RGB(Black)


Box 4, 198, 72, 72, 0, 0, RGB(0,0,63)
Text 40, 270, "(0,0,63)", "CT", 1, 1, RGB(White), RGB(Black)

Box 84, 198, 72, 72, 0, 0, RGB(0,0,127)
Text 120, 270, "(0,0,127)", "CT", 1, 1, RGB(White), RGB(Black)

Box 164, 198, 72, 72, 0, 0, RGB(0,0,191)
Text 200, 270, "(0,0,191)", "CT", 1, 1, RGB(White), RGB(Black)

Box 244, 198, 72, 72, 0, 0, RGB(0,0,255)
Text 280, 270, "(0,0,255)", "CT", 1, 1, RGB(WHite), RGB(Black)


Box 44, 294, 72, 72, 0, 0, RGB(184,115,51)
Text 80, 366, "(184,115,51)", "CT", 1, 1, RGB(White), RGB(Black)

Box 204, 294, 72, 72, 0, 0, RGB(138,51,36)
Text 240, 366, "(138,51,36)", "CT", 1, 1, RGB(White), RGB(Black)


Box 4, 390, 72, 72, 0, 0, RGB(255,0,0)
Text 40, 426, "255,0,0", "CM", 1, 1, RGB(Black), RGB(255,0,0)

Box 84, 390, 72, 72, 0, 0, RGB(0,255,0)
Text 120, 426, "0,255,0", "CM", 1, 1, RGB(Black), RGB(0,255,0)

Box 164, 390, 72, 72, 0, 0, RGB(0,0,255)
Text 200, 426, "0,0,255", "CM", 1, 1, RGB(Black), RGB(0,0,255)



Also notice in the righthand row of the first image, there is text overlaying the 3 color boxes. The text is specified with the same color as the box was filled with, yet it displays as a different shade to the background of the box. This is more noticeable with the Blue in the image, but in reality the Green one was particularly noticeable (that seems to have got lost somewhere in the photo taking / transferring process). In the second image there is no discernible difference between the box background and the text background, as it should be.

At present I'm not sure if it is just my screen or whether there is a problem with the MM2 version of the driver.

Phil.
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10565
Posted: 01:11pm 21 Nov 2017
Copy link to clipboard 
Print this post

Hi Phil

It is working for me but it is sensitive to wiring as the SPI is running very fast (I'm testing on a MM2 HAT stand) . You can try setting the CPU speed to 20 to see if that changes things. Also the attached version has an optional speed setting parameter

ILI9481 CDpin, RESETpin, CHIPSELECTpin, orientation, speed


The speed parameter changes the SPI clock divider. Without the parameter the SPI bus runs at the CPU speed / 2

Setting a value changes the SPI speed as follows "SPI speed=CPU speed / 2 /(speed+1)"

CSub ILI9481
00000275
'spi_write_data
27BDFFE0 AFBF001C AFB10018 AFB00014 309100FF 3C109D00 8E030090 8E02001C
8064002C 0040F809 24050006 8E030090 8E02001C 8064002D 0040F809 24050005
3C02BF80 AC515820 3C03BF80 8C625810 30420080 1040FFFD 3C02BF80 8C425820
3C029D00 8C430090 8C42001C 8064002D 0040F809 24050006 8FBF001C 8FB10018
8FB00014 03E00008 27BD0020
'spi_write_command
27BDFFE0 AFBF001C AFB10018 AFB00014 309100FF 3C109D00 8E030090 8E02001C
8064002C 0040F809 24050005 8E030090 8E02001C 8064002D 0040F809 24050005
3C02BF80 AC515820 3C03BF80 8C625810 30420080 1040FFFD 3C02BF80 8C425820
3C029D00 8C430090 8C42001C 8064002D 0040F809 24050006 8FBF001C 8FB10018
8FB00014 03E00008 27BD0020
'spi_write_cd
27BDFFD8 AFBF0024 AFB10020 AFB0001C AFA60030 AFA70034 00A08821 27A20030
AFA20010 308400FF 0411FFD2 00000000 1A20000A 00008021 8FA20010 24430004
AFA30010 90440000 0411FFA7 00000000 26100001 1611FFF9 8FA20010 8FBF0024
8FB10020 8FB0001C 03E00008 27BD0028
'DefineRegion
27BDFFD8 AFBF0024 AFB40020 AFB3001C AFB20018 AFB10014 AFB00010 00808821
00A09821 00C09021 00E0A021 3C109D00 8E030090 8E02001C 8064002C 0040F809
24050005 8E030090 8E02001C 8064002D 0040F809 24050005 2403002A 3C02BF80
AC435820 3C03BF80 8C625810 30420080 1040FFFD 3C10BF80 8E025820 3C029D00
8C430090 8C42001C 8064002C 0040F809 24050006 00111203 AE025820 3C03BF80
8C625810 30420080 1040FFFD 3C02BF80 8C435820 AC515820 3C03BF80 8C625810
30420080 1040FFFD 3C02BF80 8C435820 00121A03 AC435820 3C03BF80 8C625810
30420080 1040FFFD 3C02BF80 8C435820 AC525820 3C03BF80 8C625810 30420080
1040FFFD 3C10BF80 8E025820 3C029D00 8C430090 8C42001C 8064002C 0040F809
24050005 2402002B AE025820 3C03BF80 8C625810 30420080 1040FFFD 3C10BF80
8E025820 3C029D00 8C430090 8C42001C 8064002C 0040F809 24050006 00131203
AE025820 3C03BF80 8C625810 30420080 1040FFFD 3C02BF80 8C435820 AC535820
3C03BF80 8C625810 30420080 1040FFFD 3C02BF80 8C435820 00141A03 AC435820
3C03BF80 8C625810 30420080 1040FFFD 3C02BF80 8C435820 AC545820 3C03BF80
8C625810 30420080 1040FFFD 3C10BF80 8E025820 3C029D00 8C430090 8C42001C
8064002C 0040F809 24050005 2402002C AE025820 3C03BF80 8C625810 30420080
1040FFFD 3C02BF80 8C425820 3C029D00 8C430090 8C42001C 8064002D 0040F809
24050006 8FBF0024 8FB40020 8FB3001C 8FB20018 8FB10014 8FB00010 03E00008
27BD0028
'DrawBitmapSPI
27BDFFB8 AFBF0044 AFBE0040 AFB7003C AFB60038 AFB50034 AFB40030 AFB3002C
AFB20028 AFB10024 AFB00020 0080A821 00A0B821 00C09021 00E0B021 8FBE0058
8FA6005C 8FA30060 8FB30064 28A50000 00001021 02E5100A 00402821 3C02BF80
8C475830 AFA70010 8C475800 AFA70014 8C475840 AFA70018 AC405800 3C149D00
8E870090 80E7003C AC475830 3C070001 34E78520 AC475800 24070C00 AC475840
7CD01340 00061403 2407FFF8 00471024 02028025 321000FF 00108200 7CC820C0
00063143 2402FFE0 00C23024 01063025 30C600FF 02068025 7C711340 00033403
00C73824 02278825 323100FF 00118A00 7C6620C0 00031943 00621024 00C21025
304200FF 02228825 2486FFFF 24A7FFFF 73D21002 00463021 73D61002 00473821
0411FF26 00000000 8E830090 8E82001C 8064002C 0040F809 24050006 8E830090
8E82001C 8064002D 0040F809 24050005 0012C823 72D27802 25EFFFFF 0240C021
00005821 0000A021 03C06821 3C069D00 240C0001 10000043 3C03BF80 26F70001
26E2FFFF 0440003A 00000000 8CC20098 8C420000 0057102B 1440005C 8FBF0044
1E400023 01E04821 10000031 00000000 24420001 2444FFFF 04800016 00000000
8CC40094 8C840000 0082202B 14800011 00000000 91040000 00872024 10800008
00000000 8C645810 30840002 1480FFFD 00000000 AC705820 10000006 00000000
8C645810 30840002 1480FFFD 00000000 AC715820 5445FFE7 24420001 254A0001
15520005 2529FFFF 10000011 00000000 02A01021 00005021 014B2021 24850007
28880000 00A8200B 000440C3 02684021 000927C3 00042742 01243821 30E70007
00E43823 00EC3804 1000FFD1 004D2821 56EEFFC3 26F70001 26940001 01F97821
01785821 0296102A 10400005 3C02BF80 1FC0FFBA 02FE7021 1000FFF8 26940001
8C435810 30630080 1060FFFD 00000000 10000002 3C02BF80 8C435820 8C435810
30630020 1060FFFC 3C10BF80 24020040 AE025814 3C029D00 8C430090 8C42001C
8064002D 0040F809 24050006 AE005800 8FA20010 AE025830 8FA70014 AE075800
8FA20018 AE025840 8FBF0044 8FBE0040 8FB7003C 8FB60038 8FB50034 8FB40030
8FB3002C 8FB20028 8FB10024 8FB00020 03E00008 27BD0048
'DrawRectangleSPI
27BDFFC8 AFBF0034 AFBE0030 AFB7002C AFB60028 AFB50024 AFB40020 AFB3001C
AFB20018 AFB10014 AFB00010 8FA30048 3C02BF80 8C565830 8C575800 8C5E5840
AC405800 3C089D00 8D080090 8108003C AC485830 3C080001 35088520 AC485800
24080C00 AC485840 0086102A 14400005 00A7102A 00801021 00C02021 00403021
00A7102A 14400004 28920000 00A01021 00E02821 00403821 0012200B 00809021
3C029D00 8C420094 8C420000 0082402B 2444FFFF 0088900A 28D30000 0013300B
00C09821 00C2202B 2442FFFF 0044980A 28B40000 0014280B 00A0A021 3C029D00
8C420098 8C420000 00A2282B 2444FFFF 0085A00A 28F50000 0015380B 00E0A821
00E2202B 2442FFFF 0044A80A 7C701340 00032403 2402FFF8 00821024 02028025
321000FF 00108200 7C6220C0 00031943 2404FFE0 00641824 00431025 304200FF
02028025 02402021 02802821 02603021 02A03821 0411FE4B 00000000 3C119D00
8E230090 8E22001C 8064002C 0040F809 24050006 8E230090 8E22001C 8064002D
0040F809 24050005 24020001 00529023 02539821 00542023 00952021 70932002
10800009 2484FFFF 3C03BF80 8C625810 30420002 1440FFFD 00000000 AC705820
1480FFFA 2484FFFF 3C03BF80 8C625810 30420080 1040FFFD 3C02BF80 8C425810
30420020 14400006 3C02BF80 8C435820 8C435810 30630020 1060FFFC 00000000
3C10BF80 24020040 AE025814 3C029D00 8C430090 8C42001C 8064002D 0040F809
24050006 AE005800 AE165830 AE175800 AE1E5840 8FBF0034 8FBE0030 8FB7002C
8FB60028 8FB50024 8FB40020 8FB3001C 8FB20018 8FB10014 8FB00010 03E00008
27BD0038
'getFPC
27BDFFF8 AFBF0004 00852023 03E42021 ACC40000 8FBF0004 03E00008 27BD0008
'pstring
27BDFFE0 AFBF001C AFB00018 00808021 00002021 3C059D00 24A509B0 27A60010
0411FFEF 00000000 8FA40010 3C029D00 8C42002C 0040F809 02042021 8FBF001C
8FB00018 03E00008 27BD0020
'main
27BDFF88 AFBF0074 AFB70070 AFB6006C AFB50068 AFB40064 AFB30060 AFB2005C
AFB10058 AFB00054 00808821 00A08021 00C09021 00E09821 8FB40088 00002021
3C059D00 24A50A28 27A60048 0411FFD1 00000000 3C029D00 8C430090 8E040000
A064002E 8C430090 8E240000 A064002C 8C430090 8E440000 A064002D 8C420090
8E630000 12800006 A0430015 3C029D00 8C420090 8E830000 10000004 A043003C
3C029D00 8C420090 A040003C 3C109D00 8E030090 8E020010 8064002E 24050008
0040F809 00003021 8E030090 8E020010 8064002E 24050065 0040F809 00003021
8E030090 8E02001C 8064002E 0040F809 24050006 8E030090 8E020010 8064002C
24050008 0040F809 00003021 8E030090 8E020010 8064002C 24050065 0040F809
00003021 8E030090 8E02001C 8064002C 0040F809 24050006 8E030090 8E020010
8064002D 24050008 0040F809 00003021 8E030090 8E020010 8064002D 24050065
0040F809 00003021 8E030090 8E02001C 8064002D 0040F809 24050006 3C02BF81
8C44F220 7C84D800 3C020661 3442A053 1082000B 24030050 3C02BF81 8C43F220
7C63D800 3C020660 3442A053 00621826 24020050 2404000C 0083100B 00401821
3C029D00 8C420088 00621821 8C640000 24030064 54830007 0000B821 3C03BF80
8C735830 8C765800 8C775840 10000004 3C03BF81 00009821 0000B021 3C03BF81
8C65F220 7CA5D800 3C040661 3484A053 10A4000B 24030050 3C03BF81 8C64F220
7C84D800 3C030660 3463A053 00831826 24040050 2405000C 00A3200B 00801821
00621021 8C430000 24020065 1062002C 3C03BF81 3C029D00 8C420010 8C65F220
7CA5D800 3C030661 3463A053 10A3000B 24040014 3C03BF81 8C64F220 7C84D800
3C030660 3463A053 00832026 24030014 24050003 00A4180B 00602021 24050008
0040F809 00003021 3C029D00 8C420010 3C03BF81 8C65F220 7CA5D800 3C030661
3463A053 10A3000B 24040014 3C03BF81 8C64F220 7C84D800 3C030660 3463A053
00832026 24030014 24050003 00A4180B 00602021 24050065 0040F809 00003021
3C02BF81 8C44F220 7C84D800 3C030661 3463A053 1083000B 240200A4 3C02BF81
8C43F220 7C63D800 3C020660 3442A053 00621026 240300A4 24040038 0082180B
00601021 3C039D00 8C630088 00431021 8C430000 24020065 1062002C 3C03BF81
3C029D00 8C420010 8C65F220 7CA5D800 3C030661 3463A053 10A3000B 24040029
3C03BF81 8C64F220 7C84D800 3C030660 3463A053 00832026 24030029 2405000E
00A4180B 00602021 24050002 0040F809 00003021 3C029D00 8C420010 3C03BF81
8C65F220 7CA5D800 3C030661 3463A053 10A3000B 24040029 3C03BF81 8C64F220
7C84D800 3C030660 3463A053 00832026 24030029 2405000E 00A4180B 00602021
24050065 0040F809 00003021 3C02BF81 8C44F220 7C84D800 3C030661 3463A053
1083000B 24020038 3C02BF81 8C43F220 7C63D800 3C020660 3442A053 00621026
24030038 24040064 0082180B 00601021 3C039D00 8C630088 00431021 8C430000
24020065 1062002C 3C029D00 8C420010 3C03BF81 8C65F220 7CA5D800 3C030661
3463A053 10A3000B 2404000E 3C03BF81 8C64F220 7C84D800 3C030660 3463A053
00832026 2403000E 24050019 00A4180B 00602021 24050008 0040F809 00003021
3C029D00 8C420010 3C03BF81 8C65F220 7CA5D800 3C030661 3463A053 10A3000B
2404000E 3C03BF81 8C64F220 7C84D800 3C030660 3463A053 00832026 2403000E
24050019 00A4180B 00602021 24050065 0040F809 00003021 3C02BF81 8C43FA84
24040001 7C831804 AC43FA84 3C02BF81 8C43FB04 24040003 7C831804 AC43FB04
3C02BF80 3C030001 34638520 AC435800 3C039D00 8C630090 8063003C AC435830
24030C00 AC435840 16600005 3C109D00 8C535830 8C565800 8C575840 3C109D00
8E030090 8E02001C 8064002E 0040F809 24050006 8E020004 0040F809 24042710
8E030090 8E02001C 8064002E 0040F809 24050005 8E020004 0040F809 24042710
8E030090 8E02001C 8064002E 0040F809 24050006 8E020004 0040F809 24042710
24040011 0411FC34 00000000 8E020004 0040F809 24044E20 24020018 AFA20010
240400D0 24050003 24060007 24070042 0411FC4C 00000000 24120010 AFB20010
240400D1 24050003 00003021 24070007 0411FC44 00000000 240400D2 24050002
24060001 24070002 0411FC3E 00000000 AFA00010 24020002 AFA20014 24020011
AFA20018 240400C0 24050005 24060010 2407003B 0411FC33 00000000 240400C5
24050001 24060003 0411FC2E 00000000 AFA00010 AFB20014 240400B3 24050004
00003021 00003821 0411FC26 00000000 24020036 AFA20010 24020045 AFA20014
24140006 AFB40018 24020016 AFA2001C 24020037 AFA20020 24020075 AFA20024
24150077 AFB50028 24020054 AFA2002C 2402000C AFA20030 AFA00034 240400C8
2405000C 00003021 24070032 0411FC0D 00000000 2402001C AFA20010 2402000A
AFA20014 2411000F AFB10018 24020008 AFA2001C 24020043 AFA20020 24020088
AFA20024 24020003 AFA20028 AFB1002C AFB20030 AFB40034 AFB10038 24140007
AFB4003C AFA00040 240400E0 2405000F 2406000F 24070024 0411FBF2 00000000
24020030 AFA20010 24020009 AFA20014 AFB10018 AFB1001C 2402004E AFA20020
AFB50024 2402003C AFA20028 AFB4002C AFB20030 24020005 AFA20034 24020023
AFA20038 2402001B AFA2003C AFA00040 240400E1 2405000F 2406000F 24070038
0411FBD8 00000000 24040036 2405000A 0411FBD4 00000000 2404003A 24050001
24060055 0411FBCF 00000000 24110001 AFB10010 2402003F AFA20014 2404002A
24050004 00003021 00003821 0411FBC5 00000000 AFB10010 240200E0 AFA20014
2404002B 24050004 00003021 00003821 0411FBBC 00000000 8E020004 3C040001
0040F809 3484D4C0 24040029 0411FB92 00000000 8E020090 80420015 14510007
3C029D00 24040036 24050001 24060028 0411FBAC 00000000 3C029D00 8C420090
80430015 24020002 14620007 3C029D00 24040036 24050001 24060048 0411FBA1
00000000 3C029D00 8C420090 80430015 24020003 14620007 3C029D00 24040036
24050001 240600E8 0411FB96 00000000 3C029D00 8C420090 80430015 24020004
14620007 3C029D00 24040036 24050001 24060088 0411FB8B 00000000 3C029D00
8C420090 90420015 30420001 10400008 3C029D00 8C430094 240401E0 AC640000
8C420098 24030140 10000007 AC430000 8C430098 240401E0 AC640000 8C420094
24030140 AC430000 8FA50048 3C029D00 8C430048 3C049D00 24840704 00852021
AC640000 8FA50048 8C43004C 3C049D00 248403CC 00852021 AC640000 8C430048
8C440094 8C860000 8C420098 8C470000 AFA00010 8C620000 00002021 00002821
24C6FFFF 0040F809 24E7FFFF 3C02BF80 AC535830 AC565800 AC575840 3C049D00
248413EC 0411FD73 00000000 8FBF0074 8FB70070 8FB6006C 8FB50068 8FB40064
8FB30060 8FB2005C 8FB10058 8FB00054 03E00008 27BD0078
'.rodata
'startup
39494C49 20313834 76697264 6C207265 6564616F 000A0D64
End CSub
 
erbp
Senior Member

Joined: 03/05/2016
Location: Australia
Posts: 195
Posted: 07:31am 22 Nov 2017
Copy link to clipboard 
Print this post

@Matherp - Thanks, I found my problem. Your description about SPI speed vs CPU speed reminded me that I had the CPU set at 48MHz. This was done in the MM.Startup file and because it happens automatically every time the chip initialized, I had forgotten about it. Dropping the CPU back to the default 40MHz causes the colors to display correctly.

One question about the modified version of the ILI9481 driver that you posted - would it be possible to modify the way the speed parameter works to "SPI speed = CPU speed / (2 + speed)". This would allow finer control over the SPI clock divider i.e. speed parameter = 0 or not specified gives CPU speed/2, speed parameter = 1 gives CPU speed/3, speed parameter = 2 gives CPU speed/4, speed parameter = 3 gives CPU speed/5, etc. (you probably wouldn't want to go past /5 anyway) Would this be viable?

Regards,
Phil.
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10565
Posted: 08:32am 22 Nov 2017
Copy link to clipboard 
Print this post

  Quote  would it be possible to modify the way the speed parameter works


No sorry - this is a limitation of the PIC clock hardware
 
erbp
Senior Member

Joined: 03/05/2016
Location: Australia
Posts: 195
Posted: 10:18am 22 Nov 2017
Copy link to clipboard 
Print this post

  Quote  No sorry - this is a limitation of the PIC clock hardware

Somehow that is what I thought the answer might be. Still worth asking. Thanks anyway!
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025