• S3C2440 I2C总线控制


    概述:话不多说,直接上图

    多主机IIC总线控制(IICCON):

    IIC控制总线状态(IICSTAT):

    IIC总线地址(IICADD):

    IIC发送,接收总线寄存器(IICDS)

    IIC总线控制寄存器:

    源码如下:

    void Rd24C080(U32 slvAddr,U32 addr,U8 *data)
    {
     _iicMode      = SETRDADDR;
     _iicPt        = 0;
     _iicData[0]   = (U8)addr;
     _iicDataCount = 1;

     rIICDS   = slvAddr;
     rIICSTAT = 0xf0;                    //MasTx,Start 
     //Clearing the pending bit isn't needed because the pending bit has been cleared.
     while(_iicDataCount!=-1);

     _iicMode      = RDDATA;
     _iicPt        = 0;
     _iicDataCount = 1;
       
     rIICDS        = slvAddr;
     rIICSTAT      = 0xb0;               //MasRx,Start
     rIICCON       = 0xaf;               //Resumes IIC operation.  
     while(_iicDataCount!=-1);

     *data = _iicData[1];

    void Wr24C080(U32 slvAddr,U32 addr,U8 data)
    {
     _iicMode      = WRDATA;
     _iicPt        = 0;
     _iicData[0]   = (U8)addr;
     _iicData[1]   = data;
     _iicDataCount = 2;
       
     rIICDS   = slvAddr;                 //0xa0
     rIICSTAT = 0xf0;                    //MasTx,Start
     //Clearing the pending bit isn't needed because the pending bit has been cleared.
       
     while(_iicDataCount!=-1);

     _iicMode = POLLACK;

     while(1)
     {
      rIICDS     = slvAddr;
      _iicStatus = 0x100;
      rIICSTAT   = 0xf0;              //MasTx,Start
      rIICCON    = 0xaf;              //Resumes IIC operation.
              
      while(_iicStatus==0x100);
              
      if(!(_iicStatus&0x1))
       break;                      //When ACK is received
     }
     rIICSTAT = 0xd0;                    //Stop MasTx condition
     rIICCON  = 0xaf;                    //Resumes IIC operation.
     Delay(1);                           //Wait until stop condtion is in effect.
     //Write is completed.
    }
           

    void Test_Iic(void)
    {
     unsigned int i,j,save_E,save_PE;
     static U8 data[256];

     Uart_Printf(" IIC Test(Interrupt) using AT24C02 ");

     save_E   = rGPECON;
     save_PE  = rGPEUP;
     rGPEUP  |= 0xc000;                  //Pull-up disable
     rGPECON |= 0xa00000;                //GPE15:IICSDA , GPE14:IICSCL

     pISR_IIC = (unsigned)IicInt;
     rINTMSK &= ~(BIT_IIC);

     //Enable ACK, Prescaler IICCLK=PCLK/16, Enable interrupt, Transmit clock value Tx clock=IICCLK/16
     // If PCLK 50.7MHz, IICCLK = 3.17MHz, Tx Clock = 0.198MHz
     rIICCON = (1<<7) | (0<<6) | (1<<5) | (0xf);

     rIICADD  = 0x10;                    //2440 slave address = [7:1]
     rIICSTAT = 0x10;                    //IIC bus data output enable(Rx/Tx)
     rIICLC = (1<<2)|(1);      // Filter enable, 15 clocks SDA output delay       added by junon
       
     Uart_Printf("Write test data into AT24C02 ");

     for(i=0;i<256;i++)
      Wr24C080(0xa0,(U8)i,i);
              
     for(i=0;i<256;i++)
      data[i] = 0;

     Uart_Printf("Read test data from AT24C02 ");
       
     for(i=0;i<256;i++)
      Rd24C080(0xa0,(U8)i,&(data[i]));

            //Line changed 0 ~ f
     for(i=0;i<16;i++)
     {
      for(j=0;j<16;j++)
       Uart_Printf("%2x ",data[i*16+j]);
      Uart_Printf(" ");
     }
     rINTMSK |= BIT_IIC;   
     rGPEUP  = save_PE;
     rGPECON = save_E;
    }

    void main()

    {

    Test_Iic();

    }

  • 相关阅读:
    使用.Net Core RT 标准动态库
    X509 颁发者和使用者 详解
    .Net Core 中X509Certificate2 私钥保存为 pem 的方法
    dpkg:处理软件包 mysql-server-5.5 (--configure)时出错
    sql server time(7) 默认值
    如何 打包整合linux系统文件夹 用于刷机包等等, 其中包括打包 句号开头 . 开头的文件, 排除系统文件 等
    Visual Studio 2015中 安卓环境 cannot find adb.exe in specified sdk path
    PuTTY 命令行改进 有效解决 中文乱码
    System.Windows.Forms.WebBrowser中 处理 js 脚本 window.Open 禁止新建窗口 的方法
    rest_framework之认证与权限 token不存数据库认证
  • 原文地址:https://www.cnblogs.com/suncoolcat/p/3297285.html
Copyright © 2020-2023  润新知