Hello everyone,
I use an oled display
NHD-0420CW-AY320. Datasheet:
https://www.newhavendisplay.com/spec...0420CW-AY3.pdfcommon driver
US2066. Datasheet:
http://www.newhavendisplay.com/app_notes/US2066.pdfThe microcontroller I use in my code is a
STM32F107RC. Datasheet:
http://www.st.com/content/ccc/resour...CD00220364.pdfThis display is connected to the I²C bus of the microcontroller.
I do not have to use arduino.Below the diagram of my display:
we can see that in relation to the datasheet the configuration in i2c mode is correct.
Then I retrieve and adapt a code to run my display, oledDisplay.c:
Code: [Select]
/* The circuit:
*
* OLED pin 1 (Vss) pin ground
* OLED pin 2 (VDD) pin 3.3V
* OLED pin 3 (REGVDD) to Vss ground
* OLED pin 4 (SA0) to Vss ground (to assign I2C address 0x3D, connect to VDD 3.3V)
* OLED pin 5 and 6 to Vss ground
* OLED pin 7 (SCL) pin SCL (7=D0)
* OLED pin 8 and 9 (SDAin,SDAout) pin SDA (9=D2; 8=D1)
* OLED pin 10 to 15 to Vss ground (14=D7; 13=D6; 12=D5; 11=D4; 10=D3)
* OLED pin 16 (/RES) pin Reset or VDD 3.3V
* OLED pin 17 (BS0) to Vss ground
* OLED pin 18 (BS1) to VDD 5V
* OLED pin 19 (BS2) to Vss ground
* OLED pin 20 (Vss) to Vss ground
*/
/**********************/
/****** includes ******/
/**********************/
#include "oledDisplay.h"
/*********************/
/****** globals ******/
/*********************/
/** @brief Number of display rows */
const uint8_t ROW_N = 4;
/** @brief Number of display columns */
const uint8_t COLUMN_N = 20;
/** @brief pin assigned to the Reset line (optional, can be always high) */
const uint8_t RES = 16;
/** @brief Display I2C Slave address, in 7-bit form: 0x3C if SA0=LOW, 0x3D if SA0=HIGH */
const uint8_t SLAVE2W = 0x3C;
/** @brief Strings to be displayed */
const uint8_t TEXT[4][21] = {"1-Newhaven Display--",
"2-------Test--------",
"3-16/20-Characters--",
"4!@#$%^&*()_+{}[]<>?"};
/** @brief DDRAM address for each line of the display */
uint8_t new_line[4] = {0x80, 0xA0, 0xC0, 0xE0};
/** @brief Display mode: 1/3 lines or 2/4 lines; default 2/4 (0x08) */
uint8_t rows = 0x08;
/** @brief Packet to be transmitted (max 20 bytes) */
uint8_t tx_packet[MAXPACKET]={0};
//uint8_t tx_packet[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
/*********************************/
/****** Function definition ******/
/*********************************/
/**
* @brief subroutine: prepares the transmission of a command
*
* @param[in] commandByte The command to be executed by the display
*/
void command(uint8_t commandByte)
{
i2cBuffer[0] = DATABYTE_COMMAND; // Control Byte; C0_bit=0, D/C_bit=0 -> following Data Byte contains command
i2cBuffer[1] = commandByte;
send_packet(2, i2cBuffer); // Transmits the two bytes
}
/**
* @brief subroutine: prepares the transmission of a byte of data
*
* @param[in] dataByte The character to be displayed
*/
void data(uint8_t dataByte)
{
i2cBuffer[0] = DATABYTE_DATA; // Control Byte; C0_bit=0, D/C_bit=1 -> following Data Byte contains data
i2cBuffer[1] = dataByte;
send_packet(2, i2cBuffer); // Transmits the two bytes
}
/**
* @brief subroutine: send to the display the number of bytes stored in tx_packet
*
* @param[in] byteStored Command or bytes of data stored
* @param[in] *tx_pack Packet to be transmitted
*/
void send_packet(uint8_t byteStored, uint8_t *tx_pack)
{
/* Wire.beginTransmission(SLAVE2W); */ // Begin the transmission via I2C to the display with the given address
/*send start condition and slave address, then send the data and stop condition */
i2cmWrite(SLAVE2W, byteStored, tx_pack);
/* Wire.write(tx_packet[index]); */ // queue bytes for transmission
/* Wire.endTransmission(); */ // Transmits the bytes that were queued
}
/**
* @brief subroutine: displays the four strings, then the same in reverse order
*/
void output(void)
{
uint8_t row = 0; // Row index
uint8_t column = 0; // Column index
command(CLEARDISPLAY); // Clears display (and cursor home)
softDelay(2); // After a clear display, a minimum pause of 1-2 ms is required
for (row=0; row<ROW_N; row++) // One row at a time
{
command(new_line[row]); // moves the cursor to the first column of that line
for (column=0; column<COLUMN_N; column++) // One character at a time
{
data(TEXT[row][column]); // displays the corresponding string
}
}
softDelay(200); // Waits, only for visual effect purpose
for (row=0; row<ROW_N; row++) // One row at a time
{
command(new_line[row]); // moves the cursor to the first column of that line
for (column=0; column<COLUMN_N; column++) // One character at a time
{
data(TEXT[3-row][column]); // displays the correspondig string (in reverse order)
}
}
}
/**
* @brief subroutine: fills the entire display with the character "block"
*/
void blocks(void)
{
uint8_t row = 0; // Row index
uint8_t column = 0; // Column index
command(CLEARDISPLAY); // Clear display (and cursor home)
softDelay(2); // After a clear display, a minimum pause of 1-2 ms is required
for (row=0; row<ROW_N; row++) // One row at a time
{
command(new_line[row]); // moves the cursor to the first column of that line
for (column=0; column<COLUMN_N; column++) // One character at a time
{
data(SEGCONFIGURATION); // displays the character 0xDB (block)
softDelay(50); // Waits, only for visual effect purpose
}
softDelay(200); // Waits, only for visual effect purpose
}
}
/**
* @brief initial setup
*/
void setup(void)
{
softDelay(10); // Waits 10 ms for stabilization purpose
if (ROW_N == 2 || ROW_N == 4)
rows = 0x08; // Display mode: 2/4 lines
else
rows = 0x00; // Display mode: 1/3 lines
command(FUNCTIONBLINK | rows); // Function set: extended command set (RE=1), lines #
command(FUNCTIONSELECTA); // Function selection A
data(0x5C); // enable internal Vdd regulator at 5V I/O mode (def. value) (0x00 for disable, 2.8V I/O)
command(FUNCTIONLINE | rows); // Function set: fundamental command set (RE=0) (exit from extended command set), lines #
command(DISPLAYCTRL); // Display ON/OFF control: display off, cursor off, blink off (default values)
command(FUNCTIONBLINK | rows); // Function set: extended command set (RE=1), lines #
command(OLEDCHARACTERIZ_SD); // OLED characterization: OLED command set enabled (SD=1)
command(DISPLAYSET); // Set display clock divide ratio/oscillator frequency:
command(0x70); // divide ratio=1, frequency=7 (default values)
command(OLEDCHARACTERIZ); // OLED characterization: OLED command set disabled (SD=0) (exit from OLED command set)
if (ROW_N > 2)
command(FUNCTIONSET_N); // Extended function set (RE=1): 5-dot font, B/W inverting disabled (def. val.), 3/4 lines
else
command(FUNCTIONSET); // Extended function set (RE=1): 5-dot font, B/W inverting disabled (def. val.), 1/2 lines
command(ENTRYMODESET_C); // Entry Mode set - COM/SEG direction: COM0->COM31, SEG99->SEG0 (BDC=1, BDS=0)
command(FUNCTIONSELECTB); // Function selection B
data(0x0A); // ROM/CGRAM selection: ROM C, CGROM=250, CGRAM=6 (ROM=10, OPR=10)
command(OLEDCHARACTERIZ_SD); // OLED characterization: OLED command set enabled (SD=1)
command(0xDA); // Set SEG pins hardware configuration:
command(0x10); // alternative odd/even SEG pin, disable SEG left/right remap (default values)
command(FUNCTIONSELECTC); // Function selection C:
command(0x00); // internal VSL, GPIO input disable
command(CONTRASTCONTROL); // Set contrast control:
command(0x7F); // contrast=127 (default value)
command(PHASELENGHT); // Set phase length:
command(0xF1); // phase2=15, phase1=1 (default: 0x78)
command(0xDB); // Set VCOMH deselect level:
command(0x40); // VCOMH deselect level=1 x Vcc (default: 0x20=0,77 x Vcc)
command(OLEDCHARACTERIZ); // OLED characterization: OLED command set disabled (SD=0) (exit from OLED command set)
command(FUNCTIONLINE | rows); // Function set: fundamental command set (RE=0) (exit from extended command set), lines #
command(CLEARDISPLAY); // Clear display
softDelay(2); // After a clear display, a minimum pause of 1-2 ms is required
command(SETDDRAMADDR); // Set DDRAM address 0x00 in address counter (cursor home) (default value)
command(DISPLAYCTRL_D); // Display ON/OFF control: display ON, cursor off, blink off
softDelay(250); // Waits 250 ms for stabilization purpose after display on
if (ROW_N == 2)
new_line[1] = 0xC0; // DDRAM address for each line of the display (only for 2-line mode)
}
/**
* @brief clear display
*/
void clearDisplay(void)
{
command(CLEARDISPLAY); // Clears display (and cursor home)
}
/**
* @brief display on
*/
void displayON(void)
{
command(DISPLAYCTRL_DCB); // Set the display/cursor/blink ON
}
/**
* @brief display off
*/
void displayOFF(void)
{
command(DISPLAYCTRL); // Set the display/cursor/blink OFF
}
/**
* @brief main program
*/
void mainOledDisplay(void)
{
i2cmInit(); // Initialize the I2C master
setup(); // Initial setup
displayON(); // Set the display ON
output(); // Execute subroutine "output"
softDelay(100); // Waits, only for visual effect purpose
blocks(); // Execute subroutine "blocks"
softDelay(100); // Waits, only for visual effect purpose
displayOFF(); // Set the display OFF
gpioSetLedTxd(FALSE);
}
So the mainOledDisplay function will be launched first.
Here is my code, the problem is simply that the display does not work and that I do not find the problem.
Summary of how the code works:
The main function initializes the i2c, then initializes all the commands (I already have test by removing this function call and same result), then we call the function that turns on the display, for all the hexadecimal commands used I refer to to the NHD datasheet so normally.
In the command and data functions I have already tried to use the tx_packet array that I defined as: uint8_t tx_packet [MAXPACKET] = {0}; but it does not work so for the moment I left i2cBuffer (which does not work too) or maybe the problem comes from elsewhere, that's why I need you.
Then the function send_packet which has first parameter the number of byte recorded, here 2 because
- and [1] contain the data. The function has as a second parameter a pointer to the first element of the array i2cBuffer or tx_packet if I have tx_packet.
This function uses a function that can be found in my code i2cMaster.c it is also sent the slave address. However, I think, but I can not use this display correctly. I mean, ok the operation of what I said above may work but it does not advance me to operate the display because I do not even know how to make sure that what I do be displayed.
So I'm blocked for some time on it. Thank you.
Thank you very much for taking the time to read me and thank you in advance. Really sorry for my english ! Thanks a lot !