Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - arrgon

Pages: [1]
1
OLEDs / Issue about drawing on NHD-0420CW-AY320 in i2c
« on: March 05, 2018, 07:10:24 AM »
Hello everyone,

I use an oled display NHD-0420CW-AY320. Datasheet: https://www.newhavendisplay.com/spec...0420CW-AY3.pdf
common driver US2066. Datasheet: http://www.newhavendisplay.com/app_notes/US2066.pdf
The microcontroller I use in my code is a STM32F107RC. Datasheet: http://www.st.com/content/ccc/resour...CD00220364.pdf

This display is connected to the IC 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]

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 !

2
OLEDs / [NHD-0420CW-Ax3] Start my display in C language
« on: February 20, 2018, 09:14:04 AM »
Hi,

I try to debug my code but when I initialize the start of my function about the display, it not work and I don't know how to do it.

First of all I have my main part that start my display management :

Code: [Select]
/**
 * \brief Entry point of the program
 */

/**
 * @brief Initializations done after parameters loading
 */
void initializations(void)
{
mainOledDisplay();
}

int main (void)
{
   
    periphInitMain();

    gpioInit();

    initializations();

    while (TRUE)
    {
        ethernetPeriodicProcess();
        taskProcess();
    }

}


Then I have my code part of the display :
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"
#include "../gpio.h"

/**
 * @brief SUBROUTINE: PREPARES THE TRANSMISSION OF A COMMAND
 *
 * @param[in] commandByte    The command to be executed by the display
 */
void command(uint8_t commandByte)
{
   tx_packet[0] = 0x00; // Control Byte; C0_bit=0, D/C_bit=0 -> following Data Byte contains command
   tx_packet[1] = commandByte;
   send_packet(2); // 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)
{
   tx_packet[0] = 0x40; // Control Byte; C0_bit=0, D/C_bit=1 -> following Data Byte contains data
   tx_packet[1] = dataByte;
   send_packet(2); // Transmits the two bytes
}

/**
 * @brief SUBROUTINE: SEND TO THE DISPLAY THE NUMBER OF BYTES STORED IN tx_packet
 *
 * @param[in] dataByte Command or bytes of data stored
 */
void send_packet(uint8_t byteStored)
{
   uint8_t index = 0; // Bytes index

   I2C_DeInit(I2CM_MODULE);
   I2C_GenerateSTART(I2CM_MODULE, ENABLE);
   I2C_SendData(I2CM_MODULE, SLAVE2W);
   I2C_Send7bitAddress(I2CM_MODULE, SLAVE2W, I2C_Direction_Transmitter);
   /*  Wire.beginTransmission(SLAVE2W); */ // Begin the transmission via I2C to the display with the given address

   for(index=0; index<byteStored; index++) // One byte at a time
   {
  i2cmWrite(SLAVE2W, 2, tx_packet[index]);
   /* Wire.write(tx_packet[index]); */  // queue bytes for transmission

   }

   I2C_ReceiveData(I2CM_MODULE);
   I2C_GenerateSTOP(I2CM_MODULE, ENABLE);
   /*  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(0x01);                     // 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(2000);                   // 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(0x01);                     // 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(0xDB);                  // displays the character 0xDB (block)
         softDelay(50);               // Waits, only for visual effect purpose
      }
      softDelay(500);                 // Waits, only for visual effect purpose
   }
}

/**
 * @brief INITIAL SETUP
 */
void setup(void)
{
//   pinMode(RES, OUTPUT);            // Initializes Arduino pin for the Reset line (optional)
//   digitalWrite(RES, HIGH);         // Sets HIGH the Reset line of the display (optional, can be always high)
   softDelay(0.2);              // Waits 200 us for stabilization purpose

   I2C_DeInit(I2CM_MODULE);
   I2C_GenerateSTART(I2CM_MODULE, ENABLE);      // Initiate the Wire library and join the I2C bus as a master

   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(0x22 | rows); // Function set: extended command set (RE=1), lines #
   command(0x71);        // Function selection A:
   data(0x5C);           //  enable internal Vdd regulator at 5V I/O mode (def. value) (0x00 for disable, 2.8V I/O)
   command(0x20 | rows); // Function set: fundamental command set (RE=0) (exit from extended command set), lines #
   command(0x08);        // Display ON/OFF control: display off, cursor off, blink off (default values)
   command(0x22 | rows); // Function set: extended command set (RE=1), lines #
   command(0x79);        // OLED characterization: OLED command set enabled (SD=1)
   command(0xD5);        // Set display clock divide ratio/oscillator frequency:
   command(0x70);        //  divide ratio=1, frequency=7 (default values)
   command(0x78);        // OLED characterization: OLED command set disabled (SD=0) (exit from OLED command set)

   if (ROW_N > 2)
      command(0x09);     // Extended function set (RE=1): 5-dot font, B/W inverting disabled (def. val.), 3/4 lines
   else
      command(0x08);     // Extended function set (RE=1): 5-dot font, B/W inverting disabled (def. val.), 1/2 lines

   command(0x06);        // Entry Mode set - COM/SEG direction: COM0->COM31, SEG99->SEG0 (BDC=1, BDS=0)
   command(0x72);        // Function selection B:
   data(0x0A);           //  ROM/CGRAM selection: ROM C, CGROM=250, CGRAM=6 (ROM=10, OPR=10)
   command(0x79);        // 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(0xDC);        // Function selection C:
   command(0x00);        //  internal VSL, GPIO input disable
   command(0x81);        // Set contrast control:
   command(0x7F);        //  contrast=127 (default value)
   command(0xD9);        // 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(0x78);        // OLED characterization: OLED command set disabled (SD=0) (exit from OLED command set)
   command(0x20 | rows); // Function set: fundamental command set (RE=0) (exit from extended command set), lines #
   command(0x01);        // Clear display
   softDelay(2);         // After a clear display, a minimum pause of 1-2 ms is required
   command(0x80);        // Set DDRAM address 0x00 in address counter (cursor home) (default value)
   command(0x0C);        // 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 MAIN PROGRAM
 */
void mainOledDisplay(void)
{
output();          // Execute subroutine "output"
softDelay(2000);   // Waits, only for visual effect purpose
    blocks();          // Execute subroutine "blocks"
    softDelay(2000);   // Waits, only for visual effect purpose
}

I do not know how to operate my display

The code seems correct?

Thanks a lot and sorry for my english  :P !

3
OLEDs / [STM32] [NHD-0420W-Ax3] [US2066] Problem Arduino to C
« on: February 20, 2018, 08:59:33 AM »
Hi,

I use a display NHD-0420CW-AY3

Common Driver with Controller : US2066.

I want to use it in I2C but i don't know how to do that.

I took that in arduino : 

Wire.beginTransmission(SLAVE2W);

Wire.write(tx_packet[ix]);

Wire.endTransmission();

but how I can translate this in C ?

Thanks a lot, sorry for my english.

Pages: [1]