I work with the IOWarrior56 USB Dongle and having some issues to talk to the connected MPU6050 (Inertial Measurement Unit) that is connected via I2C.
When I run the provided simple I2C Test Program under Windows I can properly address the unit, which means I can perform manual "write"-requests and set the register address in the IMU, followed by "read" to get the content of the register, or even set register content via "write".
What I did first ist that I build the linux library as described in the SDK and installed it together with the header file.
I develop my software under Linux (Ubuntu) running in a Virtual Machine (VMWare) on my Windows PC. The USB Dongle is routed to the VMware and I can access it and e.g. retrieve its serial number. Therefore I think that the driver and library are working.
But when I want to access the registers of the IMU I run into issues. I read the API documentation and the IO-Warrior56 documentation, also looked into some code examples, but without success so far.
Attached is some code that I used to read the "WhoAmI" register from the IMU. The result shall simply be to get the device address of the IMU (0x68).
Hope that one can help me out here. I have the IMU actually running with real I2C and also SPI, but with the IOWarrior API I am bit struggling.
Maybe it is only a minor issue with the way I set up the write/read reports for the IOWarrior API.
OK, here is the code I used for testing:
Code: Select all
IOWKIT56_SPECIAL_REPORT report;
ULONG ioLen = 0;
IOWKIT_HANDLE ioHnd = NULL;
// Open IOWarrior
ioHnd = IowKitOpenDevice();
memset(&report, 0x00, IOWKIT56_SPECIAL_REPORT_SIZE);
// Enable I2C
report.ReportID = 0x01; // ID: I2C-Mode
report.Bytes[0] = 0x01; // Enable
report.Bytes[1] = 0x00; // Flags = standard
ioLen = IowKitWrite(ioHnd, IOW_PIPE_SPECIAL_MODE, (char*) &report, IOWKIT56_SPECIAL_REPORT_SIZE);
// set register address of device 0x68 (MPU6050) to 0x75 (WhoAmI)
report.ReportID = 0x02; // ID: I2C-Write
report.Bytes[0] = 0xC2; // flags: Start/Stop & length = 2
report.Bytes[1] = 0x68; // device address
report.Bytes[2] = 0x75; // register address
ioLen = IowKitWrite(ioHnd, IOW_PIPE_SPECIAL_MODE, (char*) &report, IOWKIT56_SPECIAL_REPORT_SIZE);
// the following read blocks. when disconnecting the dongle and reconnecting is does not block, but the next read below fails.
// sometimes this read also fails with the error bit set ...
ioLen = IowKitRead (ioHnd, IOW_PIPE_SPECIAL_MODE, (char*) &report, IOWKIT56_SPECIAL_REPORT_SIZE);
// read from register address of device 0x68 (MPU6050) to get the WhoAmI address (node address)
report.ReportID = 0x03; // ID: I2C-Read
report.Bytes[0] = 1; // count = 1
report.Bytes[1] = 0x68 + 0x01; // device address + READ
ioLen = IowKitWrite(ioHnd, IOW_PIPE_SPECIAL_MODE, (char*) &report, IOWKIT56_SPECIAL_REPORT_SIZE);
// when this line is reached then it returns with the error bit set
ioLen = IowKitRead (ioHnd, IOW_PIPE_SPECIAL_MODE, (char*) &report, IOWKIT56_SPECIAL_REPORT_SIZE);
// Disable I2C
report.ReportID = 0x01; // ID: I2C-Mode
report.Bytes[0] = 0x00; // Disable
report.Bytes[1] = 0x00; // Flags = standard speed
ioLen = IowKitWrite(ioHnd, IOW_PIPE_SPECIAL_MODE, (char*) &report, IOWKIT56_SPECIAL_REPORT_SIZE);
// Close IOWarrior
IowKitCloseDevice(ioHnd);
Regards,
Tom