1
Discussion - Software / Re: I2C Master Read in multiple read requests.
« on: November 14, 2022, 08:03:16 PM »
Update: I have done tests, and verified under a Saleae logic analyzer, that this does work. There's just a huge gap between the reads on my Windows system.
Without full error checking (because this is bad code you shouldn't use for production):
In our case, our message format is a 5-byte header (starting with a Star Code, # of PayLoad Data Byters, and three other items), then payload bytes (if any), then a 2-byte CRC.
In testing, we took out all error checking and just did the two reads back to back. This works, but will have a 150uS-300uS gap between reading the first two bytes and reading the rest, due to overhead of Windows and such. We haven't benchmarked it under Linux yet, but that's on the list.
Hope this helps others.
Without full error checking (because this is bad code you shouldn't use for production):
Code: [Select]
uint8_t buffer[128];
memset (buffer, 0x0, sizeof(buffer));
ft4222Status = FT4222_I2CMaster_ReadEx (ftHandle, UNIVERSAL_BOARD_ADDRESS, START, &buffer[0], 2, &sizeTransferred);
if (ft4222Status == FT4222_OK)
{
uint16_t numDataBytes = 0;
printf ("Read %d bytes.\n", sizeTransferred);
// buffer[0] is our Start Code, and we'd error check that here.
// buffer[1] is the number of data bytes in our payload (if any)
numDataBytes = buffer[1];
printf ("Repsonse num data bytes %d.\n", numDataBytes);
ft4222Status = FT4222_I2CMaster_ReadEx (ftHandle, UNIVERSAL_BOARD_ADDRESS, STOP, &buffer[2], 3+numDataBytes+2, &sizeTransferred);
In our case, our message format is a 5-byte header (starting with a Star Code, # of PayLoad Data Byters, and three other items), then payload bytes (if any), then a 2-byte CRC.
In testing, we took out all error checking and just did the two reads back to back. This works, but will have a 150uS-300uS gap between reading the first two bytes and reading the rest, due to overhead of Windows and such. We haven't benchmarked it under Linux yet, but that's on the list.
Hope this helps others.