I'm a complete novice in everything except maybe breathing, so sorry if I'm not being clear, but here goes:
I have a function in C which writes bytes to a circuit via an I2C bus, and in the header file it looks like this:
BOOL WINAPI JidaI2CWrite(HJIDA hJida, DWORD dwType, BYTE bAddr, LPBYTE pBytes, DWORD dwLen);
If I wanted to write just one byte to a circuit with the address 0x98, I would do something like this:
unsigned char writing[1];
writing[0]=0x10;
unsigned char *pointer;
pointer = &writing[0];
JidaI2CWrite(hJida,0,0x98,pointer,1);
which seems to work, but if I wanted to write two bytes, say 0x10FF, it doesn't. So how do I make a pointer that points to two bytes instead of just one?
Thanks
You want something like this:
unsigned char writing[2];
writing[0] = 0x01;
writing[1] = 0x02;
JidaI2CWrite(hJida, 0, 0x98, writing, 2);
Notice that an array in C can be usually be used just like a pointer. The variable writing can be thought of as just a pointer to a chunk of memory that in this case has a size of 2 bytes. Creating another pointer to point to that location is redundant (in this case).
Note you could make it point to any number of bytes:
unsigned char writing[12];
//fill the array with data
JidaI2CWrite(hJida, 0, 0x98, writing, 12);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With