Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

ILI9341 with SW/HW SPI, 8/16 Bit parallel mode
Goto page 1, 2, 3, 4, 5, 6  Next
 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> Share your working BASCOM-AVR code here
View previous topic :: View next topic  
Author Message
Netzman

Bascom Expert



Joined: 25 Nov 2005
Posts: 113
Location: Graz

austria.gif
PostPosted: Mon Apr 20, 2015 9:19 pm    Post subject: ILI9341 with SW/HW SPI, 8/16 Bit parallel mode Reply with quote

Hi,

- SPI (Soft-/Hardware), 8/16 Bit parallel interface
- ATMega/ATXmega
- Fast assembler-optimized routines
- Backlight control (Digital IO or PWM)
- Screen rotation (4 directions), Standby, Color inversion
- Basic graphics, pictures (fast SRAM-pictures), fixed-font text

Demo video (with touch screen)

More info & download: ILI9341 Library 1.0 (Project from the video is included)

br

_________________
LCD Menu | Proportional Fonts


Last edited by Netzman on Wed Apr 22, 2015 2:08 pm; edited 1 time in total
Back to top
View user's profile Visit poster's website
Evert :-)

Bascom Expert



Joined: 18 Feb 2005
Posts: 2108

netherlands.gif
PostPosted: Mon Apr 20, 2015 10:05 pm    Post subject: Reply with quote

Cool, looks fast to me.
I'm using now ARM for those kind of projects.

_________________
www.evertdekker.com Bascom code vault
Back to top
View user's profile Visit poster's website
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5034
Location: Holland

blank.gif
PostPosted: Mon Apr 20, 2015 11:09 pm    Post subject: Reply with quote

Thank you for sharing the fruits of your hard work. And of course also thanks for the video. Watching this video made my day.
As i wrote on YT :
Quote:
Wow, what can i say : it is fantastic ! It is that i downloaded the project and has a look at the source, otherwise i would have thought you were using a special graphic chip.
I like the quick drawing and the animation seemed like a video.
The matrix drop down and the 3D are my favorites too.


I see you split up the big project in multiple projects which is always a good idea.

I just see that the animation was created with jpg files. You could have fooled me Smile

_________________
Mark
Back to top
View user's profile Visit poster's website
Netzman

Bascom Expert



Joined: 25 Nov 2005
Posts: 113
Location: Graz

austria.gif
PostPosted: Tue Apr 21, 2015 4:13 pm    Post subject: Reply with quote

Thank you Smile

Sure, ARMs are better suited for such graphical displays, to do this with AVRs is hard on the edge, but possible!

No fake, all natural Wink , although I have to admit the XMega is slightly overclocked, running at 48 MHz. But the animation still looks fine with 32 MHz / 16 Bit mode.
I've used a looped GIF animation where I extracted the frames to single files which are then drawn out of the SRAM.
Now, that you've mentioned it, I took another look at the SRAM-BIN-pic routine and found a bad mistake. Updated the download, about 10% speed increase.

br

_________________
LCD Menu | Proportional Fonts
Back to top
View user's profile Visit poster's website
aphawk

Bascom Member



Joined: 23 Jan 2010
Posts: 156
Location: Brazil

brazil.gif
PostPosted: Wed Apr 22, 2015 7:54 pm    Post subject: Reply with quote

Hi, Netzman,

Very good work !

I tried to use with an Atmega328, with none graphics image, but there is some erros when compile.

Is possible to use this library with an Atmega328 ?

Thanks a lot !

Paulo
Back to top
View user's profile
Netzman

Bascom Expert



Joined: 25 Nov 2005
Posts: 113
Location: Graz

austria.gif
PostPosted: Thu Apr 23, 2015 11:42 am    Post subject: Reply with quote

Hi,

it seems that Bascom tries to evaluate these #if statements:
Code:
#if Varptr( "Lcd_ctrl_port") = Varptr( "Portc")

which are enclosed in an #if block which evaluates to false:
Code:
#if _xmega = True


so normally the compiler should ignore these lines. I did not found this error, I've only tested if it compiles for the ATmega 128, which also has the Ports E and F, the Mega328 doesn't.

To get it to work, you need to comment out the lines 234-241:
Code:
         #elseif Varptr( "Lcd_ctrl_port") = Varptr( "Porte")
            Const Lcd_spi_ctrl = Spie_ctrl
            Lcd_spi_status Alias Spie_status
            Lcd_spi_data Alias Spie_data
         #elseif Varptr( "Lcd_ctrl_port") = Varptr( "Portf")
            Const Lcd_spi_ctrl = Spif_ctrl
            Lcd_spi_status Alias Spif_status
            Lcd_spi_data Alias Spif_data


and the lines 374-385:
Code:
      #elseif Varptr( "Lcd_backlight_port") = Varptr( "Porte")
         #if Lcd_pin_backlight < 4
            Const Lcd_pwm_ctrla = Tce0_ctrla
         #else
            Const Lcd_pwm_ctrla = Tce1_ctrla
         #endif
      #elseif Varptr( "Lcd_backlight_port") = Varptr( "Portf")
         #if Lcd_pin_backlight < 4
            Const Lcd_pwm_ctrla = Tcf0_ctrla
         #else
            Const Lcd_pwm_ctrla = Tcf1_ctrla
         #endif


or you could also just delete the #if _xmega = True code parts.

br

_________________
LCD Menu | Proportional Fonts
Back to top
View user's profile Visit poster's website
aphawk

Bascom Member



Joined: 23 Jan 2010
Posts: 156
Location: Brazil

brazil.gif
PostPosted: Sat Apr 25, 2015 3:05 pm    Post subject: Reply with quote

Hi, Netzman,

I tried the suggestions, but two errors remains that I can't resolve :

Error : 12 Line : 455 Unknown CONFIG parameter [COMPARE_PWM] , in File : ILI9341.inc
Error : 46 Line : 435 Assignment error, unknown variable (DIM) [COMPARE2: 0 VALUE: 2] , in File : ILI9341.inc

There are nothing with the line numbers 455 and 435...

Maybe some problem with the $regfile ?

Thanks !

Paulo
Back to top
View user's profile
Netzman

Bascom Expert



Joined: 25 Nov 2005
Posts: 113
Location: Graz

austria.gif
PostPosted: Mon Apr 27, 2015 10:49 pm    Post subject: Reply with quote

Hi,

try modifying line 425 to:
Code:
Config Lcd_backlight_timer = Pwm , Prescale = 8 , Pwm = On , Compare_pwm = Clear_up


and line 435:
Code:
Compare2a = Value


Here I have no errors:
Code:
$regfile = "m328def.dat"
$crystal = 16000000
$hwstack = 128
$swstack = 128
$framesize = 128

Config Submode = New

Const False = 0
Const True = 1

Const Lcd_enable_backlight_pwm = True

$include "ILI9341.inc"

Lcd_init


Per default Timer2 is used as PWM timer. You can change it with:
Code:
Lcd_backlight_timer Alias Timer0   ' or Timer1

above the $include statement. Maybe you have to adjust the Config and the value settings according to the target controller.
I admit I did'nt spend very much time on the ATMega compatibility, thank you for testing and reporting this!

br

_________________
LCD Menu | Proportional Fonts
Back to top
View user's profile Visit poster's website
aphawk

Bascom Member



Joined: 23 Jan 2010
Posts: 156
Location: Brazil

brazil.gif
PostPosted: Wed Apr 29, 2015 11:33 am    Post subject: Reply with quote

Hi, Netzman,

This works, now compiles ok , thank you !!! I will make the hardware and test in this weekend.

I have yet made the change in line 435. But in line 425 I was using "Compare_a_pwm=Clear_Up" .

When I changed to "Compare_pwm=Clear_up", the error was gone .....

But I don't understand why this works.....

The Timer2 have two output pins, what is the difference betwen the commands "Compare_pwm" and "Compare_a_pwm" ?

Or this is a bug in compiler ?

Thanks again !

Paulo
Back to top
View user's profile
Netzman

Bascom Expert



Joined: 25 Nov 2005
Posts: 113
Location: Graz

austria.gif
PostPosted: Wed Apr 29, 2015 1:46 pm    Post subject: Reply with quote

Good to hear!

I was also wondering about this, it seems like a bug to me.
If it is not working, you could set the corresponding registers by hand after the config statement (Mega328 manual p. 153).
Let me know if you have success!

Br,
Matthias

_________________
LCD Menu | Proportional Fonts
Back to top
View user's profile Visit poster's website
Plons

Bascom Member



Joined: 24 May 2005
Posts: 434
Location: Hilversum - The Netherlands

netherlands.gif
PostPosted: Wed May 13, 2015 10:16 pm    Post subject: Reply with quote

@Paulo, would you please be so kind to post your code for the Mega328 ?? I spent the whole day trying, and I just want to move on with the rest of the project.

@Matthias: compliments for the well structured SW you developed for this display. I especially like the way you translate a bitnumber to a mask: 2^lcd_pin_cs etc. First time I saw that.

Thanks guys

Nard

_________________
Bascom AVR ver 2.0.8.1
ProtectedParallelPortProgrammingDongle: http://www.aplomb.nl/TechStuff/PPPD/PPPD%20English.html
Dragon-lair: http://www.aplomb.nl/TechStuff/Dragon/Dragon.html
"leef met vlag en wimpel, maar hou het simpel"
Back to top
View user's profile
Netzman

Bascom Expert



Joined: 25 Nov 2005
Posts: 113
Location: Graz

austria.gif
PostPosted: Thu May 14, 2015 1:04 am    Post subject: Reply with quote

Thanks Smile
This way of declaring masks is very common in C!

Here you have the modified library for the M328, it compiles using the short test program from above.
Please let me know if you get it to work in hardware.

Br,
Matthias

_________________
LCD Menu | Proportional Fonts
Back to top
View user's profile Visit poster's website
Plons

Bascom Member



Joined: 24 May 2005
Posts: 434
Location: Hilversum - The Netherlands

netherlands.gif
PostPosted: Thu May 14, 2015 1:43 am    Post subject: Reply with quote

Thank you, Matthias. Much appreciated.
I will let you know how it turns out.

Nard

_________________
Bascom AVR ver 2.0.8.1
ProtectedParallelPortProgrammingDongle: http://www.aplomb.nl/TechStuff/PPPD/PPPD%20English.html
Dragon-lair: http://www.aplomb.nl/TechStuff/Dragon/Dragon.html
"leef met vlag en wimpel, maar hou het simpel"
Back to top
View user's profile
Plons

Bascom Member



Joined: 24 May 2005
Posts: 434
Location: Hilversum - The Netherlands

netherlands.gif
PostPosted: Thu May 14, 2015 3:29 pm    Post subject: Reply with quote

After a good night of sleep: I forgot to mention that my display has an SPI interface, so I need either hard- or soft-SPI.
In ILI9341_M328.inc (added _M328 to the name to prevent confusion)
I modified line 12 - 20:
Code:
' Enables the SPI- instead of the 8-Bit paralell interface
#if Not Varexist( "Lcd_enable_spi")
   Const Lcd_enable_spi = True
#endif

' Use software SPI
#if Not Varexist( "Lcd_use_soft_spi") And Lcd_enable_spi = True
   Const Lcd_use_soft_spi = False                           'True
#endif
 


For the pinning (Lcd_ctrl_port = Portb) I modified line 80 - 111 to
Code:
#if Lcd_enable_spi = True
   ' SPI mode pin assignments
   #if Not Varexist( "Lcd_pin_dc")
      #if _xmega = True
         Const Lcd_pin_dc = 1
      #else
         Const Lcd_pin_dc = 1
      #endif
   #endif
   ' (HW: fixed, SW: select any)
   #if Not Varexist( "Lcd_pin_cs")
      #if _xmega = True
         Const Lcd_pin_cs = 4
      #else
         Const Lcd_pin_cs = 2
      #endif
   #endif
   #if Not Varexist( "Lcd_pin_sdo")
      #if _xmega = True
         Const Lcd_pin_sdo = 5
      #else
         Const Lcd_pin_sdo = 3
      #endif
   #endif
   #if Not Varexist( "Lcd_pin_clk")
      #if _xmega = True
         Const Lcd_pin_clk = 7
      #else
         Const Lcd_pin_clk = 5
      #endif
   #endif
   Const Lcd_pin_sdi = 4


and for the backlight
Code:
' Port of the backlight control signal
#if Not Varexist( "Lcd_backlight_port") And(lcd_enable_backlight = True Or Lcd_enable_backlight_pwm = True)
   Const Lcd_backlight_port = Portd
#endif

' Pin of the backlight control signal
#if Not Varexist( "Lcd_pin_backlight" ) And(lcd_enable_backlight = True Or Lcd_enable_backlight_pwm = True)
   #if _xmega = True
      Const Lcd_pin_backlight = 0
   #else
      Const Lcd_pin_backlight = 3
   #endif
#endif


OC2A is not available (in use by MOSI), so Backlight moved to Timer2 OC2B
Code:
      Macro Lcd_pwm_init
         #if Varptr( "Lcd_backlight_timer" ) = Varptr( "TIMER0")
            Config Lcd_backlight_timer = Pwm , Prescale = 8 , Pwm = On , Compare_pwm = Clear_up
         #elseif Varptr( "Lcd_backlight_timer" ) = Varptr( "TIMER1")
            Config Lcd_backlight_timer = Pwm , Prescale = 8 , Pwm = 8 , Compare_a_pwm = Clear_up
         #elseif Varptr( "Lcd_backlight_timer" ) = Varptr( "TIMER2")
            Config Lcd_backlight_timer = Pwm , Prescale = 8 , Pwm = On , Compare_b_pwm = Clear_up
         #endif
      End Macro

      Sub Lcd_set_pwm(byval Value As Byte)
         #if Varptr( "Lcd_backlight_timer" ) = Varptr( "TIMER0")
            Compare0a = Value
         #elseif Varptr( "Lcd_backlight_timer" ) = Varptr( "TIMER1")
            Compare1a = Value
         #elseif Varptr( "Lcd_backlight_timer" ) = Varptr( "TIMER2")
            Compare2b = Value
         #endif
      End Sub


The code compiles fine for HW SPI (Lcd_use_soft_spi = False in line 19) and SW SPI

In order to see signals on the oscilloscope, the main program was extended to:
Code:
$regfile = "m328pdef.dat"
$crystal = 16000000
$hwstack = 128
$swstack = 128
$framesize = 128

Config Submode = New

Const False = 0
Const True = 1

Const Lcd_enable_backlight_pwm = True

$include "ILI9341_M328.inc"

Sub Random_color()
   R = Rnd(255)
   G = Rnd(255)
   B = Rnd(255)
   Color = Color24to16(r , G , B)
End Sub

Dim Pixels As Word
Dim R As Byte , G As Byte , B As Byte
Dim X As Word , Y As Word , Color As Word
Dim X2 As Word , Y2 As Word , Radius As Word
Dim Statustext As String * 30

Restore Color8x8
Lcd_loadfont

Lcd_init

Do

   ' =========== Fixed Font Text ============
   For Pixels = 1 To 1000
      Random_color
      X = Rnd(220)
      Y = Rnd(310)
      Lcd_text "Text" , X , Y , Color , Color_black
   Next
   Waitms 10
'   Waitms 3000
   Lcd_clear &H0000

Loop

End

$include "data\color8x8.font"


Sck should be toggling fast (after the initial level-changes during the setup) but it's not. HW SPI keeps it low, with SW SPI it stays high.
..... some time later:
HW SPI: SPI pins SCK and MOSI are not set to outputs
That is okay btw with SW SPI
But in both instances there is no activity on SCK and MOSI

And to report at least ONE working bit: backlight behaves nicely with the timer2PWM: neat Smile

I need a coffeebreak .... but
I'll be back

Nard

_________________
Bascom AVR ver 2.0.8.1
ProtectedParallelPortProgrammingDongle: http://www.aplomb.nl/TechStuff/PPPD/PPPD%20English.html
Dragon-lair: http://www.aplomb.nl/TechStuff/Dragon/Dragon.html
"leef met vlag en wimpel, maar hou het simpel"
Back to top
View user's profile
Plons

Bascom Member



Joined: 24 May 2005
Posts: 434
Location: Hilversum - The Netherlands

netherlands.gif
PostPosted: Thu May 14, 2015 3:57 pm    Post subject: Reply with quote

Coffee helps !

I have a working configuration now by adding a line
Code:
Ddrb = &B00101111
in the main program, right after the
Code:
 $include "ILI9341_M328.inc"
and using soft SPI
I'll investigate further ....

_________________
Bascom AVR ver 2.0.8.1
ProtectedParallelPortProgrammingDongle: http://www.aplomb.nl/TechStuff/PPPD/PPPD%20English.html
Dragon-lair: http://www.aplomb.nl/TechStuff/Dragon/Dragon.html
"leef met vlag en wimpel, maar hou het simpel"
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> Share your working BASCOM-AVR code here All times are GMT + 1 Hour
Goto page 1, 2, 3, 4, 5, 6  Next
Page 1 of 6

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum