This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320C55X 的I2C驱动程序配置问题



我刚学DSP没多久,在配置I2C驱动程序。遇到的问题是:从机可以检测到数据并且进入接受中断程序,但是无法收到数据,不知道主机发送的数据是什么.。

程序如下:

主机配置程序:

//I2C
/* Initialize I2C module */
I2C_init(CSL_I2C0);
/* Setup I2C module */
i2cSetup.addrMode = CSL_I2C_ADDR_7BIT;
i2cSetup.bitCount = CSL_I2C_BC_8BITS;
i2cSetup.loopBack = CSL_I2C_LOOPBACK_DISABLE;
i2cSetup.freeMode = CSL_I2C_FREEMODE_DISABLE;
i2cSetup.repeatMode = CSL_I2C_REPEATMODE_DISABLE;
i2cSetup.ownAddr = Master_ADDR;//CSL_I2C_OWN_ADDR;
i2cSetup.sysInputClk = CSL_I2C_SYS_CLK;
i2cSetup.i2cBusFreq = CSL_I2C_BUS_FREQ;
startStop = ((CSL_I2C_START) | (CSL_I2C_STOP));
I2C_setup(&i2cSetup);

/* Disable CPU Interrupts */
IRQ_globalDisable();
/* Clear any pending interrupts */
IRQ_clearAll();
/* Disable all the interrupts */
IRQ_disableAll();
/* Set the interrupt vector start address */
IRQ_setVecs((Uint32)(&VECSTART));
/* Plug the I2C Isr into vector table */
IRQ_plug(I2C_EVENT, &i2c_isr);
/* Enable I2C Interrupts */
IRQ_enable(I2C_EVENT);
/* Enable CPU Interrupts */
IRQ_globalEnable();
I2C_eventEnable(CSL_I2C_EVENT_ICRRDY);//打开接受中断

主机发送程序:

module_init();
gI2cWrBuf[0] = 0x01;
gI2cWrBuf[1] = 0x02;

for(looper = 0; looper < CSL_I2C_DATA_SIZE; looper++)
{
gI2cWrBuf[looper + CSL_EEPROM_ADDR_SIZE] = looper;
gI2cRdBuf[looper] = 0x0000;
}
gI2cWrBuf[2] = 0x03;
/* Write data */
//I2C_write(gI2cWrBuf, (CSL_I2C_DATA_SIZE + CSL_EEPROM_ADDR_SIZE),CSL_I2C_EEPROM_ADDR, TRUE, startStop,CSL_I2C_MAX_TIMEOUT);
I2C_write(gI2cWrBuf, 2,Slave_ADDR1, TRUE, startStop,CSL_I2C_MAX_TIMEOUT);

从机配置程序:

/* Initialize I2C module */
I2C_init(CSL_I2C0);
/* Setup I2C module */
i2cSetup.addrMode = CSL_I2C_ADDR_7BIT;
i2cSetup.bitCount = CSL_I2C_BC_8BITS;
i2cSetup.loopBack = CSL_I2C_LOOPBACK_DISABLE;
i2cSetup.freeMode = CSL_I2C_FREEMODE_DISABLE;
i2cSetup.repeatMode = CSL_I2C_REPEATMODE_DISABLE;
//i2cSetup.ownAddr = CSL_I2C_OWN_ADDR;
i2cSetup.ownAddr = Slave_ADDR1;
i2cSetup.sysInputClk = CSL_I2C_SYS_CLK;
i2cSetup.i2cBusFreq = CSL_I2C_BUS_FREQ;
startStop = ((CSL_I2C_START) | (CSL_I2C_STOP));
I2C_setup(&i2cSetup);
/* Disable CPU Interrupts */
IRQ_globalDisable();
/* Clear any pending interrupts */
IRQ_clearAll();
/* Disable all the interrupts */
IRQ_disableAll();
/* Set the interrupt vector start address */
IRQ_setVecs((Uint32)(&VECSTART));
/* Plug the I2C Isr into vector table */
IRQ_plug(I2C_EVENT, &i2c_isr);
/* Enable I2C Interrupts */
IRQ_enable(I2C_EVENT);
/* Enable CPU Interrupts */
IRQ_globalEnable();
I2C_eventEnable(CSL_I2C_EVENT_ICRRDY);//打开接受中断

从机接收中断:

interrupt void i2c_isr(void)
{
I2C_flag=1;
IRQ_disable(I2C_EVENT);
/* Read data */
I2C_read(gI2cRdBuf, 1, Master_ADDR, gI2cWrBuf, 1, FALSE, startStop, CSL_I2C_MAX_TIMEOUT, FALSE);//从机接收
IRQ_enable(I2C_EVENT);
}
//////////////////////////////////////////////////////////////

希望可以做出指导,谢谢