只有一个Slave地址

[复制链接]
446|11
手机看帖
扫描二维码
随时随地手机跟帖
chuxh|  楼主 | 2017-9-22 22:46 | 显示全部楼层 |阅读模式

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在哪呢?
juventus9554| | 2017-9-22 22:47 | 显示全部楼层

函数什么功能

使用特权

评论回复
chuxh|  楼主 | 2017-9-22 22:48 | 显示全部楼层

/*******************************************************************************
* 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
*******************************************************************************/

使用特权

评论回复
stly| | 2017-9-22 22:50 | 显示全部楼层


搂主找I2C register address 做什么哪,在TRM可以找到 http://www.cypress.com/?rID=37833

使用特权

评论回复
chuxh|  楼主 | 2017-9-22 22:51 | 显示全部楼层

我现在要挂一个I2C的器件上去

使用特权

评论回复
llljh| | 2017-9-22 22:54 | 显示全部楼层
楼主是想知道程序有问题么?

使用特权

评论回复
chuxh|  楼主 | 2017-9-22 22:56 | 显示全部楼层

是啊,还有就是器件地址0x03寄存器地址0x20.怎么弄?

使用特权

评论回复
dingy| | 2017-9-22 22:57 | 显示全部楼层
你是说I2CMaster的REG_Addr? 这个可以参照I2C user moudle Datasheet 和PSoC® 3 Registers TRM

使用特权

评论回复
pengf| | 2017-9-22 22:59 | 显示全部楼层


这个是自己定义的,参照psoc creator > file > open > example project > EzI2Cdesign

使用特权

评论回复
renyaq| | 2017-9-22 23:01 | 显示全部楼层

请问为什么I2C元件的读写函数只涉及到从器件地址,但是我要对从器件里边的某个寄存器操作  要怎么办呢????????

使用特权

评论回复
supernan| | 2017-9-22 23:02 | 显示全部楼层
楼主的器件地址解决了吧,我现在有一个DAC8532,它的地址我也不清楚,请楼主帮忙

使用特权

评论回复
chuxh|  楼主 | 2017-9-22 23:04 | 显示全部楼层

不错,多谢大家

使用特权

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

本版积分规则

936

主题

11296

帖子

2

粉丝