Hello,
I have 2 problems in my I2c driver testing software:
- the light one is that I set a 400.000 Hz speed and I see on the oscilloscope a 100.000 Hz (on SCL pin, I2C2 channel, follows more detailed listing)
- the second problem is about a thread managing of the driver: I set a VERY low priority of my thread-task (even up to 10) but sometimes ( easy replicable opening Internet Explorer) my task is delayed-stretched from another process… follow the code.
Obviously, this is only a performance test to know the limit.
#define MAX_THREADS 3
int _tmain(int argc, _TCHAR* argv[])
{
pWork pDataArray[MAX_THREADS];
DWORD dwThreadIdArray[MAX_THREADS];
HANDLE hThreadArray[MAX_THREADS];
HANDLE handleI2C;
HANDLE h= GetCurrentThread();
CeSetThreadPriority( h,50);
...
handleI2C= TegI2c_Init( L"I2C2");
TegI2c_SetConfigInt( handleI2C, L"SlaveAddrSize", 7, StoreVolatile);
TegI2c_SetConfigInt( handleI2C, L"RegisterAddrSize", 0, StoreVolatile);
TegI2c_SetConfigInt( handleI2C, L"BitRateHz", 400000, StoreVolatile);
TegI2c_Open( handleI2C);
pDataArray[0].handleI2C= handleI2C;
hThreadArray[0] = CreateThread(
NULL, // default security attributes
0, // use default stack size
SlotThread, // thread function name
pDataArray[0], // argument to thread function
0, // use default creation flags
&dwThreadIdArray[0]); // returns the thread identifier
while( true)
Sleep(500);
return 0;
}
DWORD WINAPI SlotThread( LPVOID lpParam )
{
pWork *pDataArray;
BYTE i2cDataWrite[10]= {0};
HANDLE h= GetCurrentThread();
CeSetThreadPriority( h, 50);
......
pDataArray= (pWork*)lpParam;
while( true)
{
i2cDataWrite[0]= 0x01;
retValue = TegI2c_Write(pDataArray->handleI2C, (DWORD*)i2cDataWrite, 1);
retValue = TegI2c_Read(pDataArray->handleI2C, (DWORD*)i2cDataRead, 10);
Sleep(1);
}
return 0;
}
so the questions are:
- why 400.000 Hz don’t run?
- why despite a very low task-thread priority can’t I have a repeatable timing?
thanks. Davide.