TI中文支持网
TI专业的中文技术问题搜集分享网站

AM1808: 关于AM1808使用I2C读取TSC2003坐标的问题

Part Number:AM1808Other Parts Discussed in Thread: TSC2003

在AM1808开发板中使用其硬件I2C进行读取TSC2003触摸屏数据,发现一直读取不到数据,不知道为什么原因,请教一下各位大佬,谢谢!

#include "tsc2003.h"
#include "i2c.h"
#include "soc_AM1808.h"
#include "def.h"

#define I2C0IsBusy()I2CMasterBusBusy(SOC_I2C_0_REGS)
 volatile unsigned int slaveData[3];volatile unsigned int dataIdx = 0;
 volatile unsigned int txCompFlag = 1;
/*
** Initializes the I2C interface for a slave
*/
void I2C0IfConfig(unsigned int slaveAddr, unsigned int speed)
{/* Put i2c in reset/disabled state */I2CMasterDisable(SOC_I2C_0_REGS);/* Configure i2c bus speed to 100khz */I2CMasterInitExpClk(SOC_I2C_0_REGS, 24000000, 8000000, speed);/* Set i2c slave address */I2CMasterSlaveAddrSet(SOC_I2C_0_REGS, slaveAddr);I2CMasterEnable(SOC_I2C_0_REGS);
}

/*
** Function to send data through i2c
*/
void I2C0SendBlocking(unsigned int dataCnt)
{txCompFlag = 1;dataIdx = 0;while(I2C0IsBusy());I2CSetDataCount(SOC_I2C_0_REGS, dataCnt);I2CMasterControl(SOC_I2C_0_REGS, I2C_CFG_MST_TX | I2C_CFG_STOP);I2CMasterIntEnableEx(SOC_I2C_0_REGS, I2C_INT_TRANSMIT_READY| I2C_INT_STOP_CONDITION| I2C_INT_NO_ACK);I2CMasterStart(SOC_I2C_0_REGS);/* Wait till the data is sent */while(txCompFlag);while(I2C0IsBusy());
}

/*
** Function to receive data from the Codec through I2C bus
*/
void I2C0RcvBlocking(unsigned int dataCnt)
{txCompFlag = 1;dataIdx = 0;while(I2C0IsBusy());I2CSetDataCount(SOC_I2C_0_REGS, dataCnt);I2CMasterControl(SOC_I2C_0_REGS, I2C_CFG_MST_RX | I2C_CFG_STOP);I2CMasterIntEnableEx(SOC_I2C_0_REGS, I2C_INT_DATA_READY| I2C_INT_STOP_CONDITION| I2C_INT_NO_ACK);I2CMasterStart(SOC_I2C_0_REGS);/* Wait till data is received fully */while(txCompFlag);while(I2C0IsBusy());
}


/*
** ISR to handler i2c interrupts
*/
void I2CIsr(void)
{volatile unsigned int intCode = 0;/* Get interrupt vector code */intCode = I2CInterruptVectorGet(SOC_I2C_0_REGS);while(intCode!=0){/* Clear status of interrupt */
#ifdef _TMS320C6X	IntEventClear(SYS_INT_I2C0_INT);
#elseIntSystemStatusClear(15);
#endifif (intCode == I2C_INTCODE_TX_READY){I2CMasterDataPut(SOC_I2C_0_REGS, slaveData[dataIdx]);dataIdx++;}if(intCode == I2C_INTCODE_RX_READY){slaveData[dataIdx] = I2CMasterDataGet(SOC_I2C_0_REGS);dataIdx++;}if (intCode == I2C_INTCODE_STOP){I2CMasterIntDisableEx(SOC_I2C_0_REGS, I2C_INT_TRANSMIT_READY |I2C_INT_DATA_READY |I2C_INT_NO_ACK |I2C_INT_STOP_CONDITION);txCompFlag = 0;}if (intCode == I2C_INTCODE_NACK){I2CMasterIntDisableEx(SOC_I2C_0_REGS, I2C_INT_TRANSMIT_READY |I2C_INT_DATA_READY |I2C_INT_NO_ACK |I2C_INT_STOP_CONDITION);/* Generate a STOP */I2CMasterStop(SOC_I2C_0_REGS);I2CStatusClear(SOC_I2C_0_REGS, I2C_CLEAR_STOP_CONDITION);/* Clear interrupt, if we missed any, in case of error */
#ifdef _TMS320C6XIntEventClear(SYS_INT_I2C0_INT);
#elseIntSystemStatusClear(15);
#endiftxCompFlag = 0;}if (I2CMasterIntStatus(SOC_I2C_0_REGS) & I2C_ICSTR_NACKSNT){I2CMasterIntDisableEx(SOC_I2C_0_REGS, I2C_INT_TRANSMIT_READY |I2C_INT_DATA_READY |I2C_INT_NO_ACK |I2C_INT_STOP_CONDITION);/* Generate a STOP */I2CMasterStop(SOC_I2C_0_REGS);I2CStatusClear(SOC_I2C_0_REGS, (I2C_CLEAR_NO_ACK_SENT |I2C_CLEAR_STOP_CONDITION));/* Clear interrupt, if we missed any, in case of error */
#ifdef _TMS320C6XIntEventClear(SYS_INT_I2C0_INT);
#elseIntSystemStatusClear(15);
#endiftxCompFlag = 0;}intCode = I2CInterruptVectorGet(SOC_I2C_0_REGS);}
}

/*
** Writes a slave register with the given data value
*/
void I2C0SlaveRegWrite(unsigned char regAddr, unsigned char regData)
{/* Send the register address and data */slaveData[0] = regAddr;slaveData[1] = regData;I2C0SendBlocking(2);
}

/*
** Reads a slave register contents
*/
unsigned char I2C0SlaveRegRead(unsigned char regAddr)
{/* Send the register address */slaveData[0] = regAddr;I2C0SendBlocking(1);/* Receive the register contents in slaveData */I2C0RcvBlocking(1);return (slaveData[0]);
}

/*
** Sets I2C slave register bit specified in the bit mask
*/
void I2C0SlaveRegBitSet(unsigned char regAddr, unsigned char bitMask)
{/* Send the register address */slaveData[0] = regAddr;I2C0SendBlocking(1);/* Receive the register contents in slaveData */I2C0RcvBlocking(1);slaveData[1] =  slaveData[0] | bitMask;slaveData[0] = regAddr;I2C0SendBlocking(2);
}

/*
** Clears slave register bits specified in the bit mask
*/
void I2C0SlaveRegBitClr(unsigned char regAddr, unsigned char bitMask)
{/* Send the register address */slaveData[0] = regAddr;I2C0SendBlocking(1);/* Receive the register contents in slaveData */I2C0RcvBlocking(1);slaveData[1] =  slaveData[0] & ~bitMask;slaveData[0] = regAddr;I2C0SendBlocking(2);
}





void myI2C0SlaveRegWrite(unsigned char regAddr)
{/* Send the register address and data */slaveData[0] = regAddr;I2C0SendBlocking(1);
}
void myI2C0SlaveRegRead(unsigned char regAddr)
{/* Send the register address */slaveData[0] = regAddr;I2C0SendBlocking(1);/* Receive the register contents in slaveData */I2C0RcvBlocking(2);/*这里打印的坐标数据都是0*/
	printf("slaveData[0] = 0x%02x, slaveData[1] = 0x%02x\r\n", slaveData[0], slaveData[1]);
	printf( "x = %d\n\n", (slaveData[1] >> 4) | ((U16)(slaveData[0] << 4)) );//return (slaveData[0]);
}

void TouchDisplay_Task(void *prio)
{	

	U16 data;

	I2CPinMuxSetup(0);
	I2C0IfConfig(0x48, 100000);
	myI2C0SlaveRegWrite(0xC0);

	#if 1
	while(1)
	{
		if(AAFLAG == 1 && GPIOPinRead(SOC_GPIO_0_REGS, 3)==0)
		{/*点击屏幕任何位置读取到的坐标数据都是0*/
			myI2C0SlaveRegRead(0xC0);
			
			//myI2C0SlaveRegWrite(0xD0);
			AAFLAG = 0;
		
		}
	}
	#endif

}
int main()
{/*I2C中断和触摸管脚中断注册到中断向量表了...*/OSTaskCreate(TouchDisplay_Task,  (void *)0,  (OS_STK *)&SYS_Task_Stack[STACKSIZE-1],  SYS_Task_Prio);OSStart();return 0;
}

Shine:

请问I2C管脚上的时序正确吗?

,

youjian su:

您的意思是在我调用I2C写传输或读传输的API时用示波器测量SCL、SDA管脚得到时序吗?

,

youjian su:

您好,我用示波器测量了,时序符合TSC2003手册里的I2C时序图

,

Shine:

请跟踪一下代码,看是否有进中断?

,

youjian su:

您好,中断都能正常触发,且代码中没有使用到中断嵌套

,

Shine:

中断能触发的话,能进中断子程序吗?DRR接收寄存器里有数据么?

,

youjian su:

能进入中断子程序,DXR传输寄存器能传输数据,但是DRR接收寄存器里数据一直是0,且我已经设置CNT寄存器接收数据长度为2个字节了,DRR接收寄存器却只接收一个字节,当DDR接收完一个数据字节后进入if (I2CMasterIntStatus(SOC_I2C_0_REGS) & I2C_ICSTR_NACKSNT)这个if语句被判断为真,处理该事件完之后一个测试坐标周期结束。

,

Shine:

建议先设置digital-loopback mode (DLB)自环模式,看是否是AM1808 I2C的配置问题。

,

youjian su:

您好,能提供DLB的例程资料参考吗?

,

Shine:

没有DLB例程,通过寄存器ICMDR位DLB配置。可以看一下TRM文档I2C章节。https://e2echina.ti.com/support/sensors/f/sensors-forum/215588/iwr6843aop-mmwave_demo_visualizer-3-5-0

,

youjian su:

您提供的链接错了吧,没看见有什么I2C章节

,

Shine:

抱歉,贴错了https://www.ti.com/lit/ug/spruh82c/spruh82c.pdf

赞(0)
未经允许不得转载:TI中文支持网 » AM1808: 关于AM1808使用I2C读取TSC2003坐标的问题
分享到: 更多 (0)

© 2024 TI中文支持网   网站地图 鲁ICP备2022002796号-1