打印

REG_Addr在哪呢

[复制链接]
2708|8
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
zhanglli|  楼主 | 2011-11-24 13:12 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
ADDR, ST, I2c, TE, ui
uint8 I2C_MasterWriteBuf(uint8 slaveAddr, uint8 * xferData, uint8 cnt,uint8 mode)
{
    uint8 tmr;
    uint8 errStatus = I2C_MSTR_NO_ERROR;
    /* Determine whether or not to automatically generate a stop condition */
    if(mode & I2C_MODE_NO_STOP)
    {
       /* Do not generate a Stop at the end of transfer */
       I2C_mstrControl |= I2C_MSTR_NO_STOP;
    }
    else  /* Generate a Stop */
    {
       I2C_mstrControl &= ~I2C_MSTR_NO_STOP;
    }
    if((I2C_State == I2C_SM_IDLE) || (I2C_State == I2C_SM_MSTR_HALT))
    {
        errStatus = I2C_MSTR_BUS_TIMEOUT;
        if(I2C_State != I2C_SM_MSTR_HALT)
        {
            for(tmr = I2C_MSTR_TIMEOUT; tmr > 0; tmr--)
            {
                if((I2C_MCSR & I2C_MCSR_BUS_BUSY) == 0)
                {
                   errStatus = I2C_MSTR_NO_ERROR;
                   break;
                }
                CyDelay(1);    /* Wait 1 mSec */
            }
        }
        else   /* Bus halted waiting for restart */
        {
            errStatus = I2C_MSTR_NO_ERROR;
            I2C_mstrStatus &= ~I2C_MSTAT_XFER_HALT;
            CyIntClearPending(I2C_ISR_NUMBER);
        }
        /* If no timeout error, generate start */
        if(errStatus == I2C_MSTR_NO_ERROR)
        {
            slaveAddr = (slaveAddr << 1);
            I2C_State = I2C_SM_MSTR_WR_ADDR;
            I2C_mstrWrBufPtr   = xferData; /* Set buffer pointer */
            I2C_mstrWrBufIndex = 0u;       /* Start buffer at zero */
            I2C_mstrWrBufSize  = cnt;      /* Set buffer size */
            I2C_DATA = slaveAddr;            /* Write address to data reg */
            /* Generate a Start or ReStart depending on flag passed */
            if(mode & I2C_MODE_REPEAT_START)
            {
                I2C_MCSR = I2C_MCSR_RESTART_GEN;  /* Generate a ReStart */
            }
            else
            {
                I2C_MCSR = I2C_MCSR_START_GEN;  /* Generate a Start */
            }
            CyIntEnable(I2C_ISR_NUMBER);   /* IRQ must be enabled for this to work */
            /* Clear write complete flag */
            I2C_mstrStatus &= ~I2C_MSTAT_WR_CMPLT;
        }
    }
    else
    {
       errStatus = I2C_MSTR_SLAVE_BUSY;
    }
    return(errStatus);
}

在I2C的主模式下,只有一个Slave地址,还一个REG_Addr在哪呢?
沙发
zhanglli|  楼主 | 2011-11-24 13:22 | 只看该作者
这个是函数的功能!!
/*******************************************************************************
* Function Name: I2C_MasterWriteBuf
********************************************************************************
* Summary:
*  This function initiates a write transaction with an addressed slave.  Writes
*  one or more bytes (cnt) to the slave I2C device and gets the data from RAM
*  or ROM array pointed to by the array pointer.  Once this routine is called,
*  the included ISR will handle further data in byte by byte mode.  
*
*
* Parameters:  
*  slaveAddr: 7-bit slave address
*  xferData:  Pointer to data in array.
*  cnt:       Count of data to write.
*  mode:      Mode of operation.  It defines normal start, restart,
*             stop, no-stop, etc.
*
* Return:
*  void
*
* Theory:
*
* Side Effects:
*
*  //:TODO  incorporate mode
*******************************************************************************/

使用特权

评论回复
板凳
guoyt| | 2011-11-24 13:27 | 只看该作者
搂主找I2C register address 做什么哪,在TRM可以找到 http://www.cypress.com/?rID=37833

使用特权

评论回复
地板
zhanglli|  楼主 | 2011-11-24 13:33 | 只看该作者
我现在要挂一个I2C的器件上去

使用特权

评论回复
5
lium| | 2011-11-24 13:38 | 只看该作者
楼主是想知道程序有问题么?

使用特权

评论回复
6
zhanglli|  楼主 | 2011-11-24 13:44 | 只看该作者
是啊,还有就是器件地址0x03寄存器地址0x20.怎么弄?

使用特权

评论回复
7
langgq| | 2011-11-24 13:52 | 只看该作者
你是说I2CMaster的REG_Addr? 这个可以参照I2C user moudle Datasheet 和PSoC® 3 Registers TRM

使用特权

评论回复
8
wangzsa| | 2011-11-24 13:58 | 只看该作者
这个是自己定义的,参照psoc creator > file > open > example project > EzI2Cdesign

使用特权

评论回复
9
zhanglli|  楼主 | 2011-11-24 14:05 | 只看该作者
不错,多谢大家

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1016

主题

9386

帖子

1

粉丝