Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Display TFT ST7789 (OshonSoft Basic).

DogFlu66

Member
I leave the library to use ST7789 TFT display, I have translated one that is in C language. But unfortunately I have not been able to get it to work yet. I leave the files in case someone with more experience with these displays can review it.
 

Attachments

  • Main_ST7789.bas
    1.5 KB · Views: 192
  • ST7789_240X240.bas
    15 KB · Views: 171
  • _SPI_Library.bas
    6 KB · Views: 185
  • _Pic18F26K22Library.bas
    46.4 KB · Views: 174
  • _SetUpAmicus18.bas
    2.9 KB · Views: 161
Just though of something.............. I first used a pic18f4620 when I got that st7789 code working.

My lil 240x240 sst7789 is at work. so I'll bring it home and make sure it works on YOUR!! platform.

Which I must say I'm confused abut.

I thought you were using the same 4620 as I was.. BUT!! you are using the K series the pic18f46k20 to be exact.. I use the 46K22 as I need the second serial port. Now here is what I found The pic46k20 is a 3v6 max device.. Your Brown out is set to 3v So tell me! what is your power supply? I hope its 3v3 and even then the BOREN is a tad too high.
Hi I,
Yes, while on the other project, I had to change the PIC many times, as problems came up.
As I changed, I always add the PIC type into the title of my CODEs, also the OSC settings.
I forget when and why I had to change to the 'K' ones.

The Pics on the PCB both have 3.3V regulators. https://www.electro-tech-online.com/threads/display-tft-st7789-oshonsoft-basic.166219/post-1456651

I also needed a second serial port, so I was able to use the 2nd PIC on the PCB.

What should the BOREN be set at?
C.
 
I don't use brown out as I use switched power supplies, but if I did it would be A bit above the lowest voltage... On that I'm not sure as the micro can run at 1.8v but I think the screen can run as low as 2.4v so setting a brownout around 2.7v would cater for both.

This is something else you must check... How many devices are on the 3v3 rail... I would just check your noise on the power rail... Set your scope to AC and your channel volts to 200mV and set how much noise there is. I once had an issue with a 3v3 system where the canbus, SD and flash were all giving errors.
Checking the PSU showed a 200mV noise at 20Khz.. Around the speed I was using to access the SD... BUT it wasn't the SD it was the PSU. I bought a decent PSU board and bypassed the one on the PSU and it works Tickety Boo..

Pays to check hardware... For the sake of a tiny cap, you could be saved hours of hair pulling.

If you have a linear 7805 you can buy a switched one for about £3 that fits the same pins..
 
I don't use brown out as I use switched power supplies, but if I did it would be A bit above the lowest voltage... On that I'm not sure as the micro can run at 1.8v but I think the screen can run as low as 2.4v so setting a brownout around 2.7v would cater for both.

This is something else you must check... How many devices are on the 3v3 rail... I would just check your noise on the power rail... Set your scope to AC and your channel volts to 200mV and set how much noise there is. I once had an issue with a 3v3 system where the canbus, SD and flash were all giving errors.
Checking the PSU showed a 200mV noise at 20Khz.. Around the speed I was using to access the SD... BUT it wasn't the SD it was the PSU. I bought a decent PSU board and bypassed the one on the PSU and it works Tickety Boo..

Pays to check hardware... For the sake of a tiny cap, you could be saved hours of hair pulling.

If you have a linear 7805 you can buy a switched one for about £3 that fits the same pins..
Hi I,
I've lowered the BRONOUT to 2.7V and set SSPCON1 to OSC/4 = 8MHz
Early in the PCB (shown), I did have hair pulling voltage problems, so since then I use 12V batteries, which is how it would run in the field.
There is as you say a 7805 voltage regulator, feeding 2x 3.3V regulators 1x for each PIC, with plenty of caps.
The Oscilloscope shows steady voltage. I checked the switchable ones, I think they need to be 2A, but as all is fine, I'll leave well alone.
C
 
Hello, I believe the brown-out detection is set by default to the lowest voltage level, which I think is best for initial testing. Once the tests are complete and the final circuit is ready, it’s time to configure the MCU's internal protections.

One thing to keep in mind is that a reliable power supply must be used, no matter what.
 
Hello, I believe the brown-out detection is set by default to the lowest voltage level, which I think is best for initial testing. Once the tests are complete and the final circuit is ready, it’s time to configure the MCU's internal protections.

One thing to keep in mind is that a reliable power supply must be used, no matter what.
Hello D,
The fact that I've commented that set up line, tells me that I set the BOREN

As mentioned I use batteries, which are reliable, as long as I keep them charged, which over the years since using them instead of a power supply, I have let them discharge a bit too much.
C.
 
What I do not understand is the white screen followed by the mess. This, as I said, means the screen is initialised. So the "no clock" is disturbing, as your pins on Portc are the same as mine.. even with the "wrong" init it should still work in a fasion.
 
What I do not understand is the white screen followed by the mess. This, as I said, means the screen is initialised. So the "no clock" is disturbing, as your pins on Portc are the same as mine.. even with the "wrong" init it should still work in a fasion.
Hi I,
I have
Symbol TFT_LED = PORTD.2
TFT_LED = 1 'Switch screen LED on
which may solve that mystery.

I've tried a digital analyser, which shows the SPI-CLK and all of the other SPI's The CLK wasn't regular with my set up.

I'll order the ILI9341-2.4TFT screens so we only have to go through this once. I'd prefer to be patient.
C.
 
I'm trying to find an ST7789 with full SPI interface.. I'm beginning to think they are all SCK SDI only.
But I will buy one of the others for clarity.

The lil ST7789 here on my bench also works very well.
 
Hi I,
I have
Symbol TFT_LED = PORTD.2
TFT_LED = 1 'Switch screen LED on
which may solve that mystery.

I've tried a digital analyser, which shows the SPI-CLK and all of the other SPI's The CLK wasn't regular with my set up.

I'll order the ILI9341-2.4TFT screens so we only have to go through this once. I'd prefer to be patient.
C.
Hi, in the 18F series, to use a pin or port as output, the "PORTx" register is not used, the "LATx" register is used, and when it is used as an input or inputs, "PORTx" is used. It may seem to work, but in the long run it will give you problems.

AllDigital
TRISD.2 = 0
Symbol TFT_LED = LATD.2
 
If you are referring to the use of PORTx and LATx in my code, I seem to remember that I made a reminder in a previous message that I had made a mistake, and in case of using the code it should be taken into account.
 
Hi, in the 18F series, to use a pin or port as output, the "PORTx" register is not used, the "LATx" register is used, and when it is used as an input or inputs, "PORTx" is used. It may seem to work, but in the long run it will give you problems.

AllDigital
TRISD.2 = 0
Symbol TFT_LED = LATD.2
Hi D,
Once upon a time, I knew the difference, that memory faded.
Well spotted, this could be the sort of thing that has bugged me in the past, where I would spend weeks, daily looking for them.
C
 
This has already been discussed previously:

In PIC18 microcontrollers, the effect that occurs when writing to the PORTx registers instead of the LATx registers while using them as outputs is called the "Read-Modify-Write" effect.

Explanation of the Read-Modify-Write Effect:​

  • Read-Modify-Write Effect: When writing directly to an output pin using the PORTx register, the microcontroller first reads the current state of the port, then modifies the desired bit, and finally writes the value back to the PORTx register.
  • Problem: This process can cause errors if any pin on the port changes state during the read-modify-write operation (e.g., due to loads connected to the pin or interference). This can result in an unexpected value being written, as the current state of the port pins is read before modification.
  • Solution with LATx:
    • The LATx registers are designed to avoid this issue. When writing to LATx, the microcontroller does not perform a read-modify-write operation; instead, it writes directly to the output pins without reading their previous state. This eliminates the risk of unintended changes on the pins during the write operation.
For this reason, it is recommended to use the LATx registers to write to pins configured as outputs instead of PORTx, in order to avoid the read-modify-write effect and ensure stable control of the pins.
 
This has already been discussed previously:

In PIC18 microcontrollers, the effect that occurs when writing to the PORTx registers instead of the LATx registers while using them as outputs is called the "Read-Modify-Write" effect.

Explanation of the Read-Modify-Write Effect:​

  • Read-Modify-Write Effect: When writing directly to an output pin using the PORTx register, the microcontroller first reads the current state of the port, then modifies the desired bit, and finally writes the value back to the PORTx register.
  • Problem: This process can cause errors if any pin on the port changes state during the read-modify-write operation (e.g., due to loads connected to the pin or interference). This can result in an unexpected value being written, as the current state of the port pins is read before modification.
  • Solution with LATx:
    • The LATx registers are designed to avoid this issue. When writing to LATx, the microcontroller does not perform a read-modify-write operation; instead, it writes directly to the output pins without reading their previous state. This eliminates the risk of unintended changes on the pins during the write operation.
For this reason, it is recommended to use the LATx registers to write to pins configured as outputs instead of PORTx, in order to avoid the read-modify-write effect and ensure stable control of the pins.
Hi D,
I remember reading and understanding this, but I'm afraid with my programming skills, this goes in one ear and I'm afraid out of the other.
I hope you don't mind monitorig and correcting poor programmers like me.
Thanks.
C.
 
Out of curiosity I was testing the RMW effect and at speeds up to 8Mhz or lower (Pic18F46K22) it did not occur. Starting at 16Mhz it did occur and it got worse as the MHz increased.
 

Latest threads

New Articles From Microcontroller Tips

Back
Top