大家好,我最近入手了一款TIVA系列TM4C123GH6PMI的launchpad,在使用I2C数据的时候遇到了一个问题,困扰了我数周,实在无法解决,希望得到大家的帮助。
我用该launchpad和一款tca6416 IO拓展芯片进行通信,该芯片的读需要先发送一个写信号,具体时序如下。
我的关于此芯片的代码如下
//中断服务程序,I2C通信在此服务程序中进行
void IntGPIOc(void)
{
GPIOIntDisable(GPIO_PORTC_BASE, GPIO_PIN_7);
GPIOIntClear(GPIO_PORTC_BASE,GPIO_PIN_7);
delay_ms(100);
if(GPIOPinRead(GPIO_PORTC_BASE,GPIO_PIN_7)==0)
{
PCIntFlag=~PCIntFlag;
I2CMasterSlaveAddrSet(I2C0_BASE, SLAVE_ADDRESS, false);
I2CMasterDataPut(I2C0_BASE, CommandByte);
//I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE);
while(I2CMasterBusBusy(I2C0_BASE))
{
}
I2CMasterSlaveAddrSet(I2C0_BASE, SLAVE_ADDRESS+1, true);
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE);
data=I2CMasterDataGet(I2C0_BASE);
UARTprintf("Hello world!%d\n",data);
}
GPIOIntEnable(GPIO_PORTC_BASE, GPIO_PIN_7);
//lcd_ShowChar_5x8(1,1,1,1,data);
}
//主函数代码
int
main(void)
{
// uint32_t ui32DataTx;
// Set the clocking to run directly from the crystal.
SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |
SYSCTL_OSC_MAIN);
ConfigureUART();
IntEnable(INT_GPIOC);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
GPIOPinTypeGPIOInput(GPIO_PORTC_BASE, GPIO_PIN_7);
//IntMasterEnable();
GPIOPadConfigSet(GPIO_PORTC_BASE,GPIO_PIN_7,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU);
GPIOIntTypeSet(GPIO_PORTC_BASE, GPIO_PIN_7, GPIO_BOTH_EDGES);
GPIOIntEnable(GPIO_PORTC_BASE, GPIO_PIN_7);
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
GPIOPinConfigure(GPIO_PB2_I2C0SCL);
GPIOPinConfigure(GPIO_PB3_I2C0SDA);
GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2);
GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3);
//HWREG(I2C0_BASE + I2C_O_MCR) |= 0x01;
//IntEnable(INT_I2C0);
//I2CSlaveIntEnableEx(I2C0_BASE, I2C_SLAVE_INT_DATA);
//
// Enable and initialize the I2C0 master module. Use the system clock for
// the I2C0 module. The last parameter sets the I2C data transfer rate.
// If false the data rate is set to 100kbps and if true the data rate will
// be set to 400kbps. For this example we will use a data rate of 100kbps.
//
I2CMasterInitExpClk(I2C0_BASE, SysCtlClockGet(), false);
I2CMasterEnable(I2C0_BASE);
//
// Enable the I2C0 slave module.
//
//I2CSlaveEnable(I2C0_BASE);
//
// Set the slave address to SLAVE_ADDRESS. In loopback mode, it's an
// arbitrary 7-bit number (set in a macro above) that is sent to the
// I2CMasterSlaveAddrSet function.
//
//I2CSlaveInit(I2C0_BASE, SLAVE_ADDRESS);
//
// Tell the master module what address it will place on the bus when
// communicating with the slave. Set the address to SLAVE_ADDRESS
// (as set in the slave module). The receive parameter is set to false
// which indicates the I2C Master is initiating a writes to the slave. If
// true, that would indicate that the I2C Master is initiating reads from
// the slave.
//
// I2CMasterSlaveAddrSet(I2C0_BASE, SLAVE_ADDRESS, false);
//
// Set up the serial console to use for displaying messages. This is just
// for this example program and is not needed for proper I2C operation.
//
//InitConsole();
//
// Enable interrupts to the processor.
//
IntMasterEnable();
while(1)
{
}
}
我调试了好久,但并不理解tca6416 restart的条件以及在该开发板上的函数, 希望得到大家的帮助,谢谢!!