void TWI_MasterMode_Write(unsigned short DeviceAddr, unsigned char *TWI_Data_Pointer, unsigned short Count, unsigned short TWI_Length)
{
int i, j, timeout;
if (*pTWI_MASTER_STAT & SDASEN)
{
if(!ClrSclSda())
return;
}
/* make sure no previous errors occured */
if (TWISuccess == 1)
{
*pTWI_FIFO_CTL = 0; /* clear the bit manually */
*pTWI_CONTROL = TWI_ENA | PRESCALE_VALUE; /* PRESCALE = fsclk/10MHz */
*pTWI_CLKDIV = ((CLKDIV_HI) << 8) | (CLKDIV_LO); /* CLKDIV = (1/SCL)/(1/10MHz) */
*pTWI_MASTER_ADDR = DeviceAddr; /* target address (7-bits plus the read/write bit) */
for (i = 0; i < Count; i++)
{
/* # of configurations to send */
*pTWI_XMT_DATA8 = *TWI_Data_Pointer++; /* pointer to data */
ssync();
*pTWI_MASTER_CTL = (TWI_Length<<6) | MEN /*| FAST*/; /* start transmission */
timeout = 0x1000;
for (j = 0; j < (TWI_Length-1); j++)
{
/* # of transfers before stop condition */
while ((*pTWI_FIFO_STAT == XMTSTAT) && --timeout) /* wait to load the next sample into the TX FIFO */ // TAR37913
{
ssync();
}
if(!timeout)
return;
*pTWI_XMT_DATA8 = *TWI_Data_Pointer++; /* load the next sample into the TX FIFO */
ssync();
}
timeout = 0x1000;
while (!(*pTWI_INT_STAT & MCOMP) && --timeout) /* wait until transmission complete and MCOMP is set */
{
ssync();
}
if(!timeout)
return;
/* check if an error occured */
if ((*pTWI_INT_STAT & MERR) == MERR)
{
*pTWI_INT_STAT |= MERR;
TWISuccess = 0;
}
*pTWI_INT_STAT = XMTSERV | MCOMP; /* service TWI for next transmission */
}
}
asm("nop;");
asm("nop;");
asm("nop;");
}
这个是TWI写程序,我想问问写入的话先要找到从机地址,再找到寄存器地址,再写入数据,我怎么调用这个函数啊,它就只有一个形参是从机地址,我怎么写入从机内部寄存器地址??