I2C display doesn't give an acknowledge

Status
Not open for further replies.

3Dfx

New Member
Hello everyone!
I've got a NHD-C160100DiZ-FSW-FBW display and a Simcom sim5360 module. The display is connected correctly - that is for sure. I tried to get connected using a datasheet example (using Lua language), but the display doesn't get ACK-bit - the SDA line is staying HIGH.
Here is a modified code I am using now but there is still no ACK bit. I would greatly appreciate any help from you.
Code:
function I2C_out(j) --//I2C Output
    print("~~I2C output '",string.format("0x%X",j),"':\r\n")
    local d, n;
    d=j;
    n=0;
    vmsleep(delay);
    print("1. Sending 8 bits (n = [0,7])\r\n")
    for n = 0,7 do --//send 8 bits
        print("1.",n+1,".1) n = ", n, ", d = ",d, ", d and 0x80 = ",bit.band(d,0x80),". ");
        if(bit.band(d,0x80) == 0x80) then --//get only the MSB
            setHIGH(SDA);--SDA=1; --//If it is 1 then SDA=1
            print("SDA to 1: SDA == ", gpio.getv(SDA),"\r\n");
        else
            setLOW(SDA);--SDA=0; --//If 0 then SDA=0   
            print("SDA to 0: SDA == ", gpio.getv(SDA),"\r\n");           
        end
       
        vmsleep(delay);
        print("1.",n+1,".2) SCL clocks\r\n");
        print("SСL to 0: ")   
        setLOW(SCL);--SCL = 0;
        print("SCL == ",gpio.getv(SCL),"\r\n")
        vmsleep(delay);
        print("SСL to 1: ")   
        setHIGH(SCL);--SCL = 1; --//clock in data
        print("SCL == ",gpio.getv(SCL),"\r\n")
        vmsleep(2*delay);
       
        d = bit.lshift(d,1);--d=(d<<1); --//shift data byte left
       
        print("SСL to 0: ")   
        setLOW(SCL);--SCL = 0;
        print("SCL == ",gpio.getv(SCL),"\r\n")
        vmsleep(delay);
    end;
   
    print("\r\n2.\r\n")
   
    print("SDA to 1: ")
    setHIGH(SDA);--SDA = 1;
    print("SDA == ",gpio.getv(SDA),"\r\n")   
    vmsleep(2*delay);
   
    print("SСL to 1: ")   
    setHIGH(SCL);--SCL = 1; --//clock in data
    print("SCL == ",gpio.getv(SCL),"\r\n")
    vmsleep(2*delay);
   
    print("SСL to 0: ")   
    setLOW(SCL);--SCL = 0;
    print("SCL == ",gpio.getv(SCL),"\r\n")
    vmsleep(delay);
   
    pinToIN(SDA);
   
    --[
    print("3. Wait until ACK:\r\n")
    while(gpio.getv(SDA)==1) do --//wait here until ACK
        print("SСL to 0: ")   
        setLOW(SCL);--SCL = 0;
        print("SCL == ",gpio.getv(SCL),"\r\n")
        vmsleep(delay);
        print("SСL to 1: ")   
        setHIGH(SCL);--SCL = 1;
        print("SCL == ",gpio.getv(SCL),"\r\n")
        vmsleep(delay);
        print("NACK (Sending '", string.format("0x%X",j)," (gpio.getv(SDA) == ",gpio.getv(SDA),"')\r\n");
    end;   
   
    print("!!!!!!!!!!!ACK!!!!!!!!!!!!\r\n");   
    pinToOUT(SDA);
    vmsleep(delay);
   
    setLOW(SCL);--SCL = 0;   
    vmsleep(delay);
end;
--/*****************************************************/
function I2C_Start(void)
    print("~~Start:\r\n")           
   
    print("SСL to 1: ");
    setHIGH(SCL)--SCL = 1;   
    print("SCL == ",gpio.getv(SCL),"\r\n");
    vmsleep(10)
   
    print("SDA to 1: ")
    setHIGH(SDA);--SDA = 1;
    print("SDA == ",gpio.getv(SDA),"\r\n")   
    vmsleep(10)
   
    print("SDA to 0: ")   
    setLOW(SDA);--SDA = 0;
    print("SDA == ",gpio.getv(SDA),"\r\n")
    vmsleep(10)   
   
    print("SСL to 0: ")   
    setLOW(SCL);--SCL = 0;
    print("SCL == ",gpio.getv(SCL),"\r\n")
    vmsleep(10)
   
    print("~~(endstart)\r\n");
end
--/*****************************************************/
function I2C_Stop(void)
    print("~~Stop:\r\n")       

    print("SDA to 0: ")   
    setLOW(SDA);--SDA = 0;
    print("SDA == ",gpio.getv(SDA),"\r\n")
    vmsleep(10)   
   
    print("SСL to 0: ")   
    setLOW(SCL);--SCL = 0;
    print("SCL == ",gpio.getv(SCL),"\r\n")
    vmsleep(10)   
   
    print("SСL to 1: ");
    setHIGH(SCL)--SCL = 1;   
    print("SCL == ",gpio.getv(SCL),"\r\n");
    vmsleep(10)
   
    print("SDA to 1: ")
    setHIGH(SDA);--SDA = 1;
    print("SDA == ",gpio.getv(SDA),"\r\n")   
    vmsleep(10)
   
    print("~~(endstop)\r\n");
end
--/*****************************************************/
function Show(text)
    local n,i;
    local page=0xB0;  --//first page
    for i=0, 13 do --//100 pixels = 12.5 pages
        I2C_Start();
        I2C_out(Slave);
        I2C_out(Comsend);
        I2C_out(page);
        I2C_out(0x10); --//column address Y9:Y6
        I2C_out(0x01); --//column address Y5:Y2
        I2C_Stop();
        I2C_Start();
        I2C_out(Slave);
        I2C_out(Datasend);
        for n=0, 160 do
            I2C_out(text);  --//send data 4 times for grayscaling
            I2C_out(text);
            I2C_out(text);
            I2C_out(text);
            text = text+1;  --//point to next byte of data
            vmsleep(10);
        end
        I2C_Stop();
        page = page+1;  --//move to next page
    end
end
--/****************************************************
--* LCD Initialization *
--*****************************************************/
function init_LCD()
    I2C_Start();
    I2C_out(Slave);
   
    for n = 1, #initTable do
        I2C_out(initTable[n]);
    end
   
    I2C_Stop();
end
--/*****************************************************/
--]]

--/****************************************************
--* MAIN *
--/*****************************************************/
   
Slave = 0x3F; --//slave address
--Comsend = 0x00;
--Datasend = 0x40;
initTable = {
    0x00,    --Comsend
   
    -- Select partial display line (p. 56)
    -- Sets the ratio within range of 16 to 128 (ICON disabled) or 17 to 129 (ICON enabled)
    -- to realize partial display by using the 2-byte instruction
    0x48,    -- 1-st
    0x64,    -- 2-nd : 1/100 duty
   
    -- ADC select (p. 62)
    -- Changes the relationship between RAM column address and segment driver.
    -- The direction of segment driver output pins could be reversed by software.
    -- This makes IC layout flexible in LCD module assembly.
    0xA0,    -- ADC = 0: normal direction (SEG0 -> SEG127)

    -- SHL select (p. 61)
    -- COM output scanning direction is selected by this instruction which determines the LCD driver output status.
    0xC8,    -- SHL = 1: reverse direction (COM127 -> COM0)
   
    -- Set Initial COM0 Register (p. 55)
    -- Sets the initial row (COM) of the LCD panel using the 2-byte instruction.
    -- By using this instruction, it is possible to realize the window moving without the change of display data.
    0x44,    -- 1-st
    0x00,    -- 2-nd scan from COM0

    --    Oscillator ON Start (p. 62)
    0xAB,    -- This instruction enables the built-in oscillator circuit

    -- Select Regulator Resistor (p. 60)
    -- Selects resistance ratio of the internal resistor used in the internal voltage regulator.
    -- See voltage regulator section in power supply circuit
    0x26, -- 1+ (Rb / Ra) = 6.5

    -- Set Electronic Volume Register (p. 60)
    -- Consist of 2-byte Instructions
    -- The 1st instruction set Reference Voltage mode,
    -- the 2nd one updates the contents of reference voltage register.
    -- After second instruction, Reference Voltage mode is released.
    0x81,    -- 1-st *****
    0x18,    -- 2-nd
    -- 0x1C, -- 2-nd

    -- Select LCD bias (p. 60)
    -- Selects LCD bias ratio of the voltage required for driving the LCD.
    0x57,    -- 1/12
    -- 0x56, -- 1/11 ****
   
    -- Select DC-DC Step-up (p. 59)
    -- Selects one of 4 DC-DC step-up to reduce the power consumption by this instruction.
    -- It is very useful to realize the partial display function.
    0x64,    -- 3x times boosting circuit

    0xE3,    -- NOP (p. 64)
    0xE3,    -- NOP (p. 64)
   
    -- Power control (p. 58)
    0x2C,    --    Internal voltage converter circuit is ON
   
    -- Select DC-DC Step-up (p. 59)
    -- Selects one of 4 DC-DC step-up to reduce the power consumption by this instruction.
    -- It is very useful to realize the partial display function.
    0x66,    -- 5x times boosting circuit
   
    0xE3,    -- NOP (p. 64)
    0xE3,    -- NOP (p. 64)
   
    -- Power control (p. 58)
    0x2E,    -- Internal voltage converter circuit is ON
            -- Internal voltage regulator circuit is ON
   
    0xE3,    -- NOP (p. 64)
    0xE3,    -- NOP (p. 64)
   
    -- Power control (p. 58)
    0x2F,    -- Internal voltage converter circuit is ON
            -- Internal voltage regulator circuit is ON
            -- Internal voltage follower circuit is ON
   
    -- Set Bias Power Save Mode (p. 58)
    -- This command is for saving the IC current consumption by Bias Power Saving
    -- After this Instruction is set, Bias function is also working
    0xF3,    -- 1-st
    0x00,    -- 2-nd

    -- Set FRC & PWM mode (p. 65)
    0x96,    -- 3FRC
            -- 60PWM

    -- Set Mode Register (p. 49)
    -- 2-byte instruction to set Mode (EXT) and FR (Frame frequency control), BE (Booster efficiency control).
    -- Booster Efficiency
    -- The ST7528 incorporates software configurable Booster Efficiency Command.
    -- It could be used with Voltage multiplier to get the suitable Vout and Power consumption.
    -- Default setting is Level 2
    0x38,    -- 1-st
    0x75,    -- 2-nd
            -- FR frequency = 70 Hz ±20%
            -- Booster Efficiency Level 2
            -- The Instruction of EXT=1 Mode is available

    -- Set FRC & PWM mode (p. 65)
    0x95,    -- 3FRC
            -- 45PWM
    -- 0x97, ****

    -- 16-level (White Mode ~ Dark Mode) Gray Scale Display with PWM and FRC Methods
    -- (p. 1)

--------------------------------------------------
--start 16-level grayscale settings
--------------------------------------------------
    -- Set Gray Scale Mode & Register (p. 65)
    -- Consists of 2 bytes instruction.
    -- The first byte sets grayscale mode and the second byte updates the contents
    -- of gray scale register without issuing any other instruction.
    0x80, -- Set white mode and 1st frame
    0x00, -- set pulse width

    0x81, -- Set white mode and 2nd frame
    0x00, -- set pulse width
   
    0x82, -- Set white mode and 3rd frame
    0x00, -- set pulse width
   
    0x83, -- Set white mode and 4th frame
    0x00, -- set pulse width
--------------------------------------------------
    0x84,
    0x06,
    0x85,
    0x06,
    0x86,
    0x06,
    0x87,
    0x06,
    0x88,
    0x0B,
    0x89,
    0x0B,
    0x8A,
    0x0B,
    0x8B,
    0x0B,
    0x8C,
    0x10,
    0x8D,
    0x10,
    0x8E,
    0x10,
    0x8F,
    0x10,
    0x90,
    0x15,
    0x91,
    0x15,
    0x92,
    0x15,
    0x93,
    0x15,
    0x94,
    0x1A,
    0x95,
    0x1A,
    0x96,
    0x1A,
    0x97,
    0x1A,
    0x98,
    0x1E,
    0x99,
    0x1E,
    0x9A,
    0x1E,
    0x9B,
    0x1E,
    0x9C,
    0x23,
    0x9D,
    0x23,
    0x9E,
    0x23,
    0x9F,
    0x23,
    0xA0,
    0x27,
    0xA1,
    0x27,
    0xA2,
    0x27,
    0xA3,
    0x27,
    0xA4,
    0x2B,
    0xA5,
    0x2B,
    0xA6,
    0x2B,
    0xA7,
    0x2B,
    0xA8,
    0x2F,
    0xA9,
    0x2F,
    0xAA,
    0x2F,
    0xAB,
    0x2F,
    0xAC,
    0x32,
    0xAD,
    0x32,
    0xAE,
    0x32,
    0xAF,
    0x32,
    0xB0,
    0x35,
    0xB1,
    0x35,
    0xB2,
    0x35,
    0xB3,
    0x35,
    0xB4,
    0x38,
    0xB5,
    0x38,
    0xB6,
    0x38,
    0xB7,
    0x38,
    0xB8,
    0x3A,
    0xB9,
    0x3A,
    0xBA,
    0x3A,
    0xBB,
    0x3A,
--------------------------------------------------
    0xBC, -- Set Dark mode and 1st frame
    0x3C, -- set pulse width

    0xBD, -- Set Dark mode and 2nd frame
    0x3C, -- set pulse width

    0xBE, -- Set Dark mode and 3rd frame
    0x3C, -- set pulse width

    0xBF, -- Set Dark mode and 4th frame
    0x3C, -- set pulse width
--------------------------------------------------
-- end grayscale settings
--------------------------------------------------

    -- Set Mode Register (p. 49)
    -- 2-byte instruction to set Mode (EXT) and FR (Frame frequency control), BE (Booster efficiency control).
    -- Booster Efficiency
    -- The ST7528 incorporates software configurable Booster Efficiency Command.
    -- It could be used with Voltage multiplier to get the suitable Vout and Power consumption.
    -- Default setting is Level 2
    0x38,    -- 1-st
    0x74,    -- 2-nd
            -- FR frequency = 70 Hz ±20%
            -- Booster Efficiency Level 2
            -- The Instruction of EXT=0 Mode is available

    0xAF    -- Turns the display ON
};
delay = 10
   
    pinToOUT(SCL)
    pinToOUT(SDA)
    pinToOUT(RST)
    pinToOUT(CSB)

    print("CSB to 0: ")   
    setLOW(CSB)
    print("CSB == ",gpio.getv(CSB),"\r\n")
    vmsleep(5);
   
    print("RST to 0: ")   
    setLOW(RST)
    print("RST == ",gpio.getv(RST),"\r\n")
    vmsleep(100);
   
    print("RST to 1: ")   
    setHIGH(RST)
    print("RST == ",gpio.getv(RST),"\r\n")
    vmsleep(100);

    init_LCD();

--The end
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…