View previous topic :: View next topic |
Author |
Message |
Plons
Joined: 24 May 2005 Posts: 435 Location: Hilversum - The Netherlands
|
Posted: Thu May 14, 2015 4:26 pm Post subject: |
|
|
Lines 249 and 250 in the original ILI9341.inc
Code: | Const Lcd_spi_ctrl_init = &H0_1_0_1_0_0_00 ' No INT, Enable, MSB, Master, CPOL=0, CPHA=0, CLK/4
Const Lcd_spi_status_init = &H00_00000_1 ' CLKx2
|
One mystery less: the &H should be &B of course. I have an active Sck and Mosi now, next step .... hmm, /CS, DC are constantly high
.... working further _________________ Bascom AVR ver 2.0.8.6
Dragon-lair: http://www.aplomb.nl/TechStuff/Dragon/Dragon.html
"leef met vlag en wimpel, maar hou het simpel" |
|
Back to top |
|
|
Plons
Joined: 24 May 2005 Posts: 435 Location: Hilversum - The Netherlands
|
Posted: Thu May 14, 2015 5:20 pm Post subject: |
|
|
In line 246 of the original ILI9341.inc you declare Code: | Const Lcd_spi_ctrl = Spcr |
In the macro on line 264 you do Code: | sts Lcd_spi_ctrl, R16 | Seems odd to me since you declared it to be a constant, ..... or am I wrong ?
I am also looking into IOspace and extended IOspace, like line 264:
Code: | sts Lcd_spi_ctrl, R16 |
Shouldn't that be Code: | !OUT Lcd_spi_ctrl, R16 |
??? _________________ Bascom AVR ver 2.0.8.6
Dragon-lair: http://www.aplomb.nl/TechStuff/Dragon/Dragon.html
"leef met vlag en wimpel, maar hou het simpel" |
|
Back to top |
|
|
Netzman
Joined: 25 Nov 2005 Posts: 127 Location: Graz
|
Posted: Thu May 14, 2015 5:39 pm Post subject: |
|
|
I've also found some errors and merged them with the ones you found (test program + library in the zip).
You're right, of course it should be !out instead of sts and &B instead of &H !
Also the DDR register address was wrong, should be Port - 1 instead of Port + 1.
Br _________________ LCD Menu | Proportional Fonts |
|
Back to top |
|
|
Plons
Joined: 24 May 2005 Posts: 435 Location: Hilversum - The Netherlands
|
Posted: Thu May 14, 2015 6:23 pm Post subject: |
|
|
Thanks Matthias !
One matter is still unclear to me: line 246, the Code: | Const Lcd_spi_ctrl = Spcr |
I expected the compiler to compain about it when a few lines further this happens:
Code: | sts Lcd_spi_ctrl, R16 |
or now
Code: | !OUT Lcd_spi_ctrl, R16 |
But it doesn't complain ! I find that puzzling.
I will test your latest finest this evening.
Meanwhile: a big thanks !
Nard _________________ Bascom AVR ver 2.0.8.6
Dragon-lair: http://www.aplomb.nl/TechStuff/Dragon/Dragon.html
"leef met vlag en wimpel, maar hou het simpel" |
|
Back to top |
|
|
Plons
Joined: 24 May 2005 Posts: 435 Location: Hilversum - The Netherlands
|
Posted: Fri May 15, 2015 12:37 am Post subject: |
|
|
These displays have an on-board 3.3V regulator, so you can feed it with 5V on the Vcc pin.
The interface-signals are quite picky when it comes down to the max. voltage. Don't feed it directly from the IO-pins. I use a resistor of 470 Ohm with a 3V3 zener on each of the signals (no 4050 in stock). That 470 is too high for the 8MHz Sck in HW SPI. Will fix that tomorrow.
And because of the HW issues I didn't manage to test the latest version.
Tomorrow is another day. _________________ Bascom AVR ver 2.0.8.6
Dragon-lair: http://www.aplomb.nl/TechStuff/Dragon/Dragon.html
"leef met vlag en wimpel, maar hou het simpel" |
|
Back to top |
|
|
Plons
Joined: 24 May 2005 Posts: 435 Location: Hilversum - The Netherlands
|
Posted: Fri May 15, 2015 9:03 pm Post subject: |
|
|
Found one other problem: With an SPI-clk at Xtal/2, the display doesn't work. At forst I suspected my PMI (Poor Mans Interface ) to be the culprit. But it isn't. What happens is that the smart SPI peripheral in the AVR already signals that the job has been done, but, in reality, it's still moving out bits. So what I found with the oscilloscope was a level-change in the DC/RS line during the time that Sck was still at work. And that means TROUBLE !
@ the pictures: The scope triggers on DC/RS, blue trace, and the Clk is on the yellow trace.
Will be back with a solution ...
Nard
PS A .png with interface schematic was visible but ridiculous wide. It's now in the zip _________________ Bascom AVR ver 2.0.8.6
Dragon-lair: http://www.aplomb.nl/TechStuff/Dragon/Dragon.html
"leef met vlag en wimpel, maar hou het simpel" |
|
Back to top |
|
|
Plons
Joined: 24 May 2005 Posts: 435 Location: Hilversum - The Netherlands
|
Posted: Fri May 15, 2015 9:44 pm Post subject: |
|
|
To fix that problem: replace the lines Code: | While Lcd_spi_status = 0 : Wend | at line 275 and 287 with Code: | While Lcd_spi_status.spif = 0 : Wend |
Now the max speed can be used
.... working .... _________________ Bascom AVR ver 2.0.8.6
Dragon-lair: http://www.aplomb.nl/TechStuff/Dragon/Dragon.html
"leef met vlag en wimpel, maar hou het simpel" |
|
Back to top |
|
|
Plons
Joined: 24 May 2005 Posts: 435 Location: Hilversum - The Netherlands
|
Posted: Fri May 15, 2015 10:04 pm Post subject: |
|
|
Hi Mathias,
I fear that your latest ILI9341_M328.inc still misses the !OUT vs STS.
This is what IMO the 3 macro's should look like:
(line 273 - 304)
Code: | Macro Lcd_write_cmd
in R16, Lcd_ctrl_port ' CS, DC low
andi R16, Lcd_clear_cs_dc
!out Lcd_ctrl_port, R16
#if Lcd_use_soft_spi = False ' write byte
Lcd_spi_data = Lcd_databyte
' While Lcd_spi_status = 0 : Wend
While Lcd_spi_status.spif = 0 : Wend
in R16, Lcd_ctrl_port
#else
Lcd_spi_out_bitbang
#endif
ori R16, Lcd_set_dc ' DC high
!out Lcd_ctrl_port, R16
End Macro
Macro Lcd_write_data
#if Lcd_use_soft_spi = False ' write byte
Lcd_spi_data = Lcd_databyte
' While Lcd_spi_status = 0 : Wend
While Lcd_spi_status.spif = 0 : Wend
#else
in R16, Lcd_ctrl_port
Lcd_spi_out_bitbang
#endif
End Macro
Macro Lcd_spi_end ' CS high
in R16, Lcd_ctrl_port
ori R16, Lcd_set_cs
!out Lcd_ctrl_port, R16
End Macro |
Cheers
Nard _________________ Bascom AVR ver 2.0.8.6
Dragon-lair: http://www.aplomb.nl/TechStuff/Dragon/Dragon.html
"leef met vlag en wimpel, maar hou het simpel" |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Fri May 15, 2015 10:09 pm Post subject: |
|
|
when you use !IN and !OUT, bacom will transform to LDS/STS when required. _________________ Mark |
|
Back to top |
|
|
Plons
Joined: 24 May 2005 Posts: 435 Location: Hilversum - The Netherlands
|
Posted: Fri May 15, 2015 11:42 pm Post subject: |
|
|
You're spoiling us, Mark !
Until now, I always checked and double-checked if I did use the correct opcode for an IO-register in IO-space or extended IO-space. A luxury that I can skip those checks now.
It looks like this library is okay now. It was worth it.
Nard _________________ Bascom AVR ver 2.0.8.6
Dragon-lair: http://www.aplomb.nl/TechStuff/Dragon/Dragon.html
"leef met vlag en wimpel, maar hou het simpel" |
|
Back to top |
|
|
Netzman
Joined: 25 Nov 2005 Posts: 127 Location: Graz
|
|
Back to top |
|
|
Plons
Joined: 24 May 2005 Posts: 435 Location: Hilversum - The Netherlands
|
Posted: Sat May 16, 2015 3:49 pm Post subject: |
|
|
Thanks for your explanation on the Const Lcd_spi_ctrl = Spcr matter. Is it correct to say that it has the same effect as the use of an alias like Lcd_spi_ctrl alias Spcr ?
Quote: | But the latest changes you've posted I can't verify | I guess you'll have to trust me on that one
Kidding aside,
Look at line 251: Const Lcd_spi_status_init = &B00_00000_1 ' CLKx2
Line 260: Lcd_spi_status = Lcd_spi_status_init
And then line 275 and 287: While Lcd_spi_status = 0 : Wend
Since Lcd_spi_status is the alias of SPSR, the While Wend doesn't execute since its value is &B0000_0001 because of the SPI2X being set.
Modifying line 275 and 287 to While Lcd_spi_status.spif = 0 : Wend fixes that.
When I leave your STS and LDS in the Macro Lcd_write_cmd and Macro Lcd_write_data, my scope shows two flat lines: no activity on Sck and Mosi. Using IN and !OUT instead make it come alive.
I am pretty sure you are aware of the following (quote from datasheet M328) but I post it here for future reference for other Bascom-users:
Quote: | 2. I/O Registers within the address range 0x00 - 0x1F are directly bit-accessible using the SBI and CBI instructions. In these registers, the value of single bits can be checked by using the SBIS and SBIC instructions.
3. Some of the Status Flags are cleared by writing a logical one to them. Note that, unlike most other AVRs, the CBI and SBI instructions will only operate on the specified bit, and can therefore be used on registers containing such Status Flags. The CBI and SBI instructions work with registers 0x00 to 0x1F only.
4. When using the I/O specific commands IN and OUT, the I/O addresses 0x00 - 0x3F must be used. When addressing I/O Registers as data space using LD and ST instructions, 0x20 must be added to these addresses. The
ATmega48A/PA/88A/PA/168A/PA/328/P is a complex microcontroller with more peripheral units than can be supported
within the 64 location reserved in Opcode for the IN and OUT instructions. For the Extended I/O space from 0x60 - 0xFF in SRAM, only the ST/STS/STD and LD/LDS/LDD instructions can be used. |
I agree with you on the zeners. I chose that solution because the Arduino Vcc can var between 5.25v when running from USB power to 3.6V on an almost empty LiPo. To meet the specs on logic levels for the ILI9341 is tricky with a resistive divider. I also have an OpAmp in the analog front-end so I need all the juice there is. But as I said: I share your opinion on it. Considering all, I will run the Arduino on 3.3V, lower the Xtal to 11.0592MHz and run the OpAmp from USB power or LiPo. A direct connection of TFT is then flawless
Oh, and about the scope picture: Trigger is on the blue channel, DC/RS. The evidence lies in DC/RS changing level DURING a clock-burst of 8 clocks of Sck. That was the clue I needed to solve the problem.
Thank you for helping me out, Mathias !
Nard
PS I will post the modified ILI9341_M328.inc after having verified it all works and I need to remove a comments (which I added to keep track of what I am doing: I suffer from teflon memory ... nothing sticks) _________________ Bascom AVR ver 2.0.8.6
Dragon-lair: http://www.aplomb.nl/TechStuff/Dragon/Dragon.html
"leef met vlag en wimpel, maar hou het simpel" |
|
Back to top |
|
|
Plons
Joined: 24 May 2005 Posts: 435 Location: Hilversum - The Netherlands
|
Posted: Sat May 16, 2015 4:36 pm Post subject: |
|
|
I took the zip from your original post and added two files: M328_ILI9341_SPI_revA.bas and ILI9341_M328_revA.inc. I didn't touch any of your originals. The zipped version is attached for download.
Cheers,
Nard _________________ Bascom AVR ver 2.0.8.6
Dragon-lair: http://www.aplomb.nl/TechStuff/Dragon/Dragon.html
"leef met vlag en wimpel, maar hou het simpel" |
|
Back to top |
|
|
aphawk
Joined: 23 Jan 2010 Posts: 168 Location: Brazil
|
Posted: Sun May 17, 2015 6:38 am Post subject: |
|
|
Nard and Mathias,
Thanks for your debugged version for Atmega328. This will be very usefull for many projects based on the Arduíno Uno hardware.
Paulo |
|
Back to top |
|
|
Netzman
Joined: 25 Nov 2005 Posts: 127 Location: Graz
|
Posted: Sun May 17, 2015 3:48 pm Post subject: |
|
|
Hi Nard,
Thank you for your great effort debugging the library for the M328! I'll transfer the changes into the library for the next version release.
Plons wrote: | Look at line 251: Const Lcd_spi_status_init = &B00_00000_1 ' CLKx2
Line 260: Lcd_spi_status = Lcd_spi_status_init
And then line 275 and 287: While Lcd_spi_status = 0 : Wend
Since Lcd_spi_status is the alias of SPSR, the While Wend doesn't execute since its value is &B0000_0001 because of the SPI2X being set.
Modifying line 275 and 287 to While Lcd_spi_status.spif = 0 : Wend fixes that. |
Now I believe you, thank you for explaining this
Plons wrote: | When I leave your STS and LDS in the Macro Lcd_write_cmd and Macro Lcd_write_data, my scope shows two flat lines: no activity on Sck and Mosi. Using IN and !OUT instead make it come alive.
I am pretty sure you are aware of the following (quote from datasheet M328) but I post it here for future reference for other Bascom-users: |
Obviously, at the time I was writing these functions, I did not thought about extended IO registers (the Xmega is pretty straight forward...)
But it makes sense that it doesn't work with LDS/STS, in the reg file the extended IO register addresses already have &H20 added, so IN/!OUT will work fine as it is. For the lower IO registers, Bascom replaces IN/!OUT with LDS/STS, which then works like intended.
Plons wrote: | Oh, and about the scope picture: Trigger is on the blue channel, DC/RS. The evidence lies in DC/RS changing level DURING a clock-burst of 8 clocks of Sck. That was the clue I needed to solve the problem. |
According to the datasheet of the ILI9341 (page 35, 4-line serial interface), the D/C signal should only matter on the LSB (last transferred bit) of the data byte, however, I found out during testing (like you did), that this seems not to be true.
Plons wrote: | I chose that solution because the Arduino Vcc can var between 5.25v when running from USB power to 3.6V on an almost empty LiPo. |
Some time ago I had a similar problem, I had to interface signals that can vary between 1.8V to 5.5V to a 3.3V circuit. I found these perfectly suited devices: NTSX2102, they work up to 50 MHz. If you're designing a PCB, then I would recommend using these or a similar IC!
Br,
Matthias _________________ LCD Menu | Proportional Fonts |
|
Back to top |
|
|
|
|
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
|
|