Hi all,
I am facing a strange problem on a K64F interfaced to an SSD1306-based 128 x 64 OLED Display (following images); I use the FRDM-K64F and a FRDM-KL25Z with the MBED platform.
When I use the OLED display on the SPI port of the FRDM-KL25Z it works properly; when I use the same display or a twin one on the SPI0 port of the FRDM-K64F with the same code, all signals are correct except the MOSI one which is connected to the DIN line of the display: on the FRDM-K64F it appears greatly attenuated (almost with a factor of 10:1) or distorted with the shorter bits greatly attenuated and the display doesn't work at all.
I've tried also to use a different code on the FRDM-K64F sending the result of a 16-bit incrementing counter on the MOSI line and the result is the same: the signal is greatly attenuated until the MOSI line is connected to the DIN line of the display:
if I disconnect the MOSI signal from the display, it returns normal:
If I recompile and load the same code on the FRDM-KL25Z, the MOSI signal is always perfect!
NOTE: on both the previous pics the top waveform is the CS signal (used as the trigger) and the bottom signal is the MOSI one.
Here is the simple code I use to generate the previous signals:
#include "mbed.h"
#ifdef TARGET_K64F
#define SPI_SCK PTD1
#define SPI_MOSI PTD2
#define SPI_MISO PTD3
#define SPI_CS PTD0
#define I2C_SDA PTE25
#define I2C_SCL PTE24
#define displayDC PTC4
#define displayRST PTC3
#elif defined(TARGET_KL25Z)
#define SPI_SCK PTD1
#define SPI_MOSI PTD2
#define SPI_MISO PTD3
#define SPI_CS PTD0
#define I2C_SDA PTE0
#define I2C_SCL PTE1
#define displayDC PTD5
#define displayRST PTA13
#endif
DigitalOut myled(LED_GREEN);
DigitalOut spi_cs(SPI_CS);
SPI spi(SPI_MOSI, SPI_MISO, SPI_SCK);
int main() {
uint16_t k = 0;
spi_cs = 1;
spi.format(8,3);
spi.frequency(2000000);
while(1) {
myled = !myled;
spi_cs = 0;
spi.write((k & 0xff00) >> 8);
spi.write(k & 0xff);
spi_cs = 1;
k++;
wait(0.1);
}
}
From the schematic of the FRDM-K64F it seems that the MOSI line of the SPI0 peripheral (PD2) is connected directly to the Arduino-like header whitout any series resistor and the same is on the FRDM-KL25Z; no other onboard peripherals are connected to these lines on both board.
Also, from the datasheet of the SSD1306, I read that the DIN signal is a normal digital input signal; no explicit note is reported about its input impedance.
For this reasons I am unable to find the cause of the MOSI attenuation on the K64F.
Is there anyone else that has tried to interface this kind of displays to the FRDM-K64F? If yes any hint will be appreciated!
Solved! Go to Solution.
Hi Ma,
I am glad to inform you that finally I found the solution to this problem!
It was related to an undocumented configuration of the SPI port of the OLED display: on both my display samples (manufactured by WaveShare, .96inch OLED (B) | SPI I2C ) the DIN line was paralleled to some other internal signal by means of a 0R resistor (R1 in the following schematic diagram and pic):
Using a mixed signal oscilloscope I observed that the distortion of the DIN signal was limited to the initial part of the byte transferred from the FRDM-K64F to the display; carefully analyzing the circuit I found the 0R resistor and after its removal the display immediately started to work correctly!
I also verified that it is not necessary to enable the DSE bit of PORTD_PCR2.
Cheers.
Francesco
Hi,
Please try to enable the PTD2 pin internal pull up with PORTD_PCR2 register and check if with the same issue.
Wish it helps.
Have a great day,
Ma Hui
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hi Ma,
I tried to apply your hint adding the following code immediately after the declaration of the variable k in the main routine:
#ifdef TARGET_K64F | |
PORTD_PCR2 |= 0x03; | |
#endif |
Unfortunately nothing has changed: the MOSI/PTD2 signal appears in the same manner as I described in my first post.
Thank you anyway for your answer!
Francesco
Hi Francesco,
Thank you for the feedback.
I will do a test on my site and check if PTD2 pin with same issue on my site.
While, for I was engaged in a training this week and could that test next Monday.
Thank you for the patience.
Have a great day,
Ma Hui
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hi Ma,
thank you for your willingness; in the meantime I did some other tries in the attempt to solve the problem by myself:
- I soldered an external pull-up resistor to the MOSI line: NO SUCCESS
- I changed the FRDM-K64F board with a twin one: NO SUCCESS
- I changed the SPI port connecting the OLED display to the RF/WIFI connector (J6), so now SCK = PTD5, CS = PTC12, MOSI = PTD6: NO SUCCESS.
In all my tries the aspect of the MOSI signal when attached to the display is always the same.
Any other hint will be appreciated.
Have a nice day.
Francesco
EDIT: carefully reading the data sheet of the "K64 Sub-Family Reference Manual" (Rev. 2, January 2014, http://cache.freescale.com/files/microcontrollers/doc/ref_manual/K64P144M120SF5RM.pdf) at page 283-284, I saw that in the PORTD_PCR2 register there is bit 6 named DSE (Drive Strength Enable), when set to 1, configures the high drive strength on the corresponding pin (PD2 in my case), if pin is configured as a digital output.
I tried to change the optional code valid only for FRDM-K64F to:
#ifdef TARGET_K64F | |
PORTD_PCR2 |= 0x40; | |
#endif |
Compiling the code, uploading it to the FRDM-K64F and capturing the MOSI signal on PD2 with the oscilloscope, it now appears exactly the same as the one I can see on the FRDM-KL25Z, even with PD2/MOSI connected to the display!
At the moment the display doens't show any output but, now that the most difficult problem is solved, it is only a matter of time and.. patience!
I will write here the complete description of the problem when (if...) I find it.
Francesco
Hi Francesco,
From the latest updates, when you set the [Drive Strength Enable] bit in PORTD_PCR2 register, you could get the SPI_MOSI signal as expected. Right?
The high drive strength will enhance the drive capability from 2mA to 8mA.
Have a great day,
Ma Hui
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hi Ma,
I am glad to inform you that finally I found the solution to this problem!
It was related to an undocumented configuration of the SPI port of the OLED display: on both my display samples (manufactured by WaveShare, .96inch OLED (B) | SPI I2C ) the DIN line was paralleled to some other internal signal by means of a 0R resistor (R1 in the following schematic diagram and pic):
Using a mixed signal oscilloscope I observed that the distortion of the DIN signal was limited to the initial part of the byte transferred from the FRDM-K64F to the display; carefully analyzing the circuit I found the 0R resistor and after its removal the display immediately started to work correctly!
I also verified that it is not necessary to enable the DSE bit of PORTD_PCR2.
Cheers.
Francesco
Hi Francesco,
Thank you for the update to let us know the root cause.
Have a great day,
Ma Hui
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Yes, this is the actual status of the problem: now I have a correct MOSI signal (as seen on the oscilloscope), but the display doesn't not display anithing yet; however I am working to solve this problem too.
Thank you for your help.
Francesco