滴滴FAE

如果不是生活、情怀、使命所迫,谁愿意把自己搞得才华横溢!滴滴调屏,分享经验。

基本STM32F103调试ICN6211案例

0
阅读(231) 评论(0)

以下程序包含I2C的驱动以及ICN6211的配置,都有详细说明

image.png

//*************************************************

// * File Name:    lcd.c

// * Author:       Shie

// * Version:      V01

// * Date:         2019.10.27

// * QQ: 三三二四四五三七八 

// * CPU:        STM32F103VCT6  

// * Interface:    I2C

// * Resolution:1080*1920

//*************************************************

#include "main.h"

#include "ssd2828.h"


unsigned int LCDH;

unsigned int LCDV;


unsigned int HBPD;

unsigned int HFPD;

unsigned int HSPW;


unsigned int VBPD;

unsigned int VFPD;

unsigned int VSPW;

/*******************************************************************************************************/

#define ICN_RST_PIN        GPIO_Pin_1

#define I2C_SDA_PIN      GPIO_Pin_2

#define I2C_SCL_PIN        GPIO_Pin_3

/*******************************************************************************************************/

#define ICN_RST_PORT       GPIOA

#define I2C_SDA_PORT       GPIOA

#define I2C_SCL_PORT       GPIOA

/*******************************************************************************************************/

#define ICN_RST_1()    (GPIO_SetBits(ICN_RST_PORT,ICN_RST_PIN))

#define ICN_RST_0()    (GPIO_ResetBits(ICN_RST_PORT,ICN_RST_PIN))

/*******************************************************************************************************/

/*******************************************************************************************************/

#define I2C_SDA_1()    (GPIO_SetBits(I2C_SDA_PORT,I2C_SDA_PIN))

#define I2C_SDA_0()    (GPIO_ResetBits(I2C_SDA_PORT,I2C_SDA_PIN))

/*******************************************************************************************************/

/*******************************************************************************************************/

#define I2C_SCL_1()    (GPIO_SetBits(I2C_SCL_PORT,I2C_SCL_PIN))

#define I2C_SCL_0()    (GPIO_ResetBits(I2C_SCL_PORT,I2C_SCL_PIN))

/*******************************************************************************************************/

#define I2C_SDA_VAL()     GPIO_ReadInputDataBit(I2C_SDA_PORT, I2C_SDA_PIN)


#define Bit_SET 1

#define Bit_CLR 0

#define MIPI_Lane 4       

#define MIPI_speed 750               

#define Horizontal 1080      

#define Vertical 1920    

#define HBP 50        

#define HFP 50  

#define HSW 20     

#define VBP 16      

#define VFP 22   

#define VSW 2


extern void I2cInit(void);

extern void I2C_SDA_IN(void);

extern void I2C_SDA_OUT(void);

extern void I2cStart(void);

extern void I2cStop(void);

extern u8 I2cWaitAck(void);

extern void I2cAck(void);

extern void I2cNoAck(void);

extern void I2cSendByte(u8 txd);

extern u8 I2cReadByte(u8 ack);

extern void I2C_Delay(unsigned char t);

extern void colorbar(void);

extern void display(unsigned char RED,unsigned char GREEN,unsigned char BLUE);

extern void ICN6211_Initial(void);

extern unsigned char ID[10]; 

/*****************************************************************************************************/

/*****************************************************************************************************/

unsigned char error;

unsigned char ID[10]; 

#define SlaveAddress   0x58

typedef enum

{

  I2C_NO_ACK,

  I2C_ACK

} AckTypeDef;


//=============================================================//

//Function name:I2cInit

//Function:Initial I2C GPIO(SDA,SCL,ICN_RST)

//Input1:None

//Input1:None

//Return Value:None

//=========================================================//

void I2cInit(void)

{

GPIO_InitTypeDef GPIO_InitStruct;

RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA,ENABLE);

GPIO_InitStruct.GPIO_Pin=I2C_SDA_PIN|I2C_SCL_PIN|ICN_RST_PIN;

GPIO_InitStruct.GPIO_Mode=GPIO_Mode_OUT;

GPIO_InitStruct.GPIO_OType=GPIO_OType_PP;

GPIO_InitStruct.GPIO_Speed=GPIO_Speed_Level_3;

GPIO_Init(GPIOA,&GPIO_InitStruct);

GPIO_ResetBits(GPIOA,I2C_SDA_PIN|I2C_SCL_PIN|ICN_RST_PIN);

}

//=============================================================//

//Function name:I2C_SDA_IN

//Function:Set I2C_SDA input mode

//Input1:None

//Input1:None

//Return Value:None

//==========================================================//

void I2C_SDA_IN(void)

{

GPIO_InitTypeDef GPIO_InitStruct;

GPIO_InitStruct.GPIO_Pin=I2C_SDA_PIN;

GPIO_InitStruct.GPIO_Mode=GPIO_Mode_IN;

GPIO_InitStruct.GPIO_OType=GPIO_OType_PP;

GPIO_InitStruct.GPIO_PuPd=GPIO_PuPd_UP;

GPIO_InitStruct.GPIO_Speed=GPIO_Speed_Level_3;

GPIO_Init(I2C_SDA_PORT,&GPIO_InitStruct);

}


//============================================================//

//Function name:I2C_SDA_OUT

//Function:Set I2C_SDA output mode

//Input1:None

//Input2:None

//Return Value:None

//===========================================================//

void I2C_SDA_OUT(void)

{

GPIO_InitTypeDef GPIO_InitStruct;

GPIO_InitStruct.GPIO_Pin=I2C_SDA_PIN;

GPIO_InitStruct.GPIO_Mode=GPIO_Mode_OUT;

GPIO_InitStruct.GPIO_OType=GPIO_OType_PP;

GPIO_InitStruct.GPIO_PuPd=GPIO_PuPd_UP;

GPIO_InitStruct.GPIO_Speed=GPIO_Speed_Level_3;

GPIO_Init(I2C_SDA_PORT,&GPIO_InitStruct);

}

//==============================================================//

//Function name:I2C_Delay

//Function:delay for I2C

//Input1:t(0 to 255)

//Input2:None

//Return Value:None

//==============================================================//

void I2C_Delay(unsigned char t)

{

  unsigned char i,n;

  for (n = 0; n < t; n++)

  {

    for (i = 0; i < 35; i++)

    {

    }

  }

}

//============================================================//

//Function name:I2cStart

//Function:stat bit

//Input1:None

//Input2:None

//Return Value:None

//===============================================================//

void I2cStart(void)

{

    I2C_SDA_OUT();

    I2C_SDA_1();//SDA = 1;         

    I2C_SCL_1();//SCL = 1;              

    I2C_Delay(2);//Delay5us();  

    I2C_SDA_0();//SDA = 0;          

    I2C_Delay(2);//Delay5us();  

    I2C_SCL_0();//SCL = 0;         

}

//=============================================================//

//Function name:I2cStop

//Function:stop bit

//Input1:t(0 to 255)

//Input2:None

//Return Value:None

//=============================================================//

void I2cStop(void)

{

    I2C_SDA_OUT();

    I2C_SDA_0();//SDA = 0;     

    I2C_SCL_1();//SCL = 1;   

    I2C_Delay(2);//Delay5us(); 

    I2C_SDA_1();//SDA = 1;          

    I2C_Delay(2);//Delay5us();    

    I2C_SCL_0();

}

//=============================================================//

//Function name:I2cSendACK

//Function:send ACK Singal

//Input1:ack

//Input2:None

//Return Value:None

//==============================================================//

void I2CSendACK(unsigned char ack)

{   

    I2C_SDA_OUT();

    if(ack==0)//SDA = ack;      

    {

      I2C_SDA_0();

    }

    else

    {

      I2C_SDA_1();

    }

    I2C_SCL_1();//SCL = 1;                   

    I2C_Delay(2);//Delay5us();              

    I2C_SCL_0();//SCL = 0;                 

    I2C_Delay(5);//Delay5us();              

}

//===============================================================//

//Function name:I2cSendACK

//Function:Recive ACK Singal

//Input1:

//Input2:None

//Return Value:error

//==============================================================//

unsigned char I2CRecvACK(void)

{

    I2C_SDA_IN();

    I2C_SCL_1();//SCL = 1;                   

    I2C_Delay(2);//Delay5us();              

    I2C_SCL_1();

    if(I2C_SDA_VAL()==Bit_SET)           

    {

      error = 1;

    }

    else

    {

      error = 0;

    }

    I2C_SCL_0() ;              

    I2C_Delay(5);

    I2C_SDA_OUT();

    return error;

}

//==============================================================//

//Function name:I2CSendByte

//Function:send one byte

//Input1:dat

//Input2:None

//Return Value:None

//============================================================//

void I2CSendByte(unsigned char dat)

{

    unsigned char i;

    I2C_SDA_OUT();

    for (i=0;i<8;i++)        

    {

        I2C_Delay(5);            

        if(dat&0x80)  //SDA = CY;              

        {I2C_SDA_1();}

        else

        {I2C_SDA_0();}       

        I2C_Delay(5);             

        I2C_SCL_1();//SCL = 1;                

        I2C_Delay(5);            

        I2C_SCL_0();//SCL = 0;                

        dat <<= 1;              

    }

    I2CRecvACK();

}

//=============================================================//

//Function name:I2CRecvByte

//Function:Recive one byte

//Input1:dat

//Input2:None

//Return Value:None

//===========================================================//

unsigned char I2CRecvByte(void)

{

    unsigned char i;

    unsigned char Mid;

    unsigned char dat = 0;

    I2C_SDA_IN();

    for (i=0; i<8; i++)    

    {

        dat <<= 1;

        I2C_Delay(5);      

        I2C_SCL_1();

if(I2C_SDA_VAL()== Bit_SET)        

{

Mid = 1;

}

else

{

Mid = 0;

}

        if(Mid) dat++;

        I2C_Delay(5);     

        I2C_SCL_0();//SCL = 0;           

    }

    return dat;

}

//==============================================================//

//Function name:I2cWrite

//Function:Recive one byte

//Input1:REG_Address

//Input2:REG_data

//Return Value:None

//==========================================================//

void I2cWrite(unsigned char REG_Address,unsigned char REG_data)

{

    I2cStart();           

    I2CSendByte(SlaveAddress);   

    I2CSendByte(REG_Address);   

    I2CSendByte(REG_data);       

    I2cStop();                   

}

//=============================================================//

//Function name:Single_Read_I2C

//Function:Recive one byte

//Input1:REG_Address

//Input2:None

//Return Value:REG_data

//=========================================================//

unsigned char Single_Read_I2C(unsigned char REG_Address)

{  

unsigned char REG_data;

I2cStart();                         

I2CSendByte(SlaveAddress);           

I2CSendByte(REG_Address);            

I2cStart();                          

I2CSendByte(SlaveAddress+1);         

REG_data=I2CRecvByte();              

I2CSendACK(1);   

I2cStop();                          

return REG_data; 

}

void colorbar(void)

{

I2cWrite(0x14,0x43); 

I2cWrite(0x2A,0x49); 

I2cWrite(0x2E,0x00);//BIST CHESS X[7:0] register

I2cWrite(0x2F,0x00);//BIST CHESS Y[7:0] register

I2cWrite(0x30,0x00);//CHESS_X[11:8],CHESS_Y[11:8]

I2cWrite(0x09,0x10);//disply on 


}

ICN6211自动生成的彩条

image.png

//=============================================================//

//Function name:ICN6211_Initial

//Function:initial ICN6211

//Input1:None

//Input2:None

//Return Value:None

//==========================================================//

void ICN6211_Initial(void)

{

//unsigned int HACTIVE,VACTIVE;

//HACTIVE=Horizontal;

//VACTIVE=Vertical;

LCDH=Horizontal;

LCDV=Vertical;

LCDH=(LCDH>>8)&0x0F;

LCDV=(Vertical>>4)&0xF0;

ICN_RST_1(); 

I2C_Delay(100);     

ICN_RST_0(); 

I2C_Delay(250);   

ICN_RST_1(); 

I2C_Delay(250);   


//READ ICN6211 Device ID

ID[0]=Single_Read_I2C(0x00);

ID[1]=Single_Read_I2C(0x01);

ID[2]=Single_Read_I2C(0x02);

ID[3]=Single_Read_I2C(0x03);


if (ID[1]==0x62&&ID[2]==0x11&&ID[3]==0xFF)

{

printf("Success:ICN6211 Connected OK\n");

}

else

{

printf("Error:ICN6211 Connected failed\n");

}


//printf("VENDER_ID  =0x%02X \n", ID[0]);

//printf("DEVICE_ID_H=0x%02X \n", ID[1]);

//printf("DEVICE_ID_L=0x%02X \n", ID[2]);

//printf("VERSION_ID =0x%02X \n", ID[3]);


I2cWrite(0x20,Horizontal&0xFF);//HACTIVE[7:0] 

I2cWrite(0x21,Vertical&0xFF);//VACTIVE[7:0]

I2cWrite(0x22,LCDV|LCDH);//VACTIVE[11:8] for bit7-4,HACTIVE[11:8] for bit 3-0

I2cWrite(0x23,HFP);//HFP

I2cWrite(0x24,HSW);//HSW

I2cWrite(0x25,HBP);//HBP

I2cWrite(0x26,0x00);//HFP[9:8] for bit5-4,HSW[9:8] for 3-2,HBP[9:8] for bit 1-0

I2cWrite(0x27,VFP);//VFP

I2cWrite(0x28,VSW);//VS

I2cWrite(0x29,VBP);//VBP

I2cWrite(0x34,0x80);//SYNC_EVENT_DLY[7:0]

I2cWrite(0x36,0x28);//HSW_MIN

I2cWrite(0x86,0x29);//DSI_CTRL register

I2cWrite(0xB5,0xA0);//MIPI_PD_CK_LANE register

I2cWrite(0x5C,0xFF);//PLL_WT_LOCK[7:0] 

I2cWrite(0x2A,0x01);//BIST POL Register

I2cWrite(0x56,0x93);//内部时钟时设置为0x93,mipi作为像素时钟时设置为0x92

I2cWrite(0x6B,0x31);//PLL_REF_DIV register

//PCLK

//I2cWrite(0x69,0x1E);//0X1F,0x1E=100Mhz

//I2cWrite(0x69,0x22);//0X1F,0x1E=120Mhz


I2cWrite(0x69,0x23);//PLL_INT[7:0]

I2cWrite(0x10,0x40);//SYS_CTRL_0 register

I2cWrite(0x11,0x88);//SYS_CTRL_1 register

I2cWrite(0xB6,0x20);//MIPI_FORCE_0 register

I2cWrite(0x51,0x20);//PLL_CTRL_1 register

I2cWrite(0x09,0x10);// CONFIG_FINISH register,disply on 

}

下图是集创生成初始化代码的小软件,很方便

image.png