Go to Post As we all know, a low Center of Gravity is a beautiful thing. - Andy Baker [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 28-01-2017, 06:05
DavidOrser DavidOrser is offline
Registered User
FRC #2987 (Rogue Robotics)
Team Role: Mentor
 
Join Date: Feb 2016
Rookie Year: 2014
Location: Minneapolis, MN
Posts: 6
DavidOrser will become famous soon enough
I2C Class Issues

Disclaimer: I'm aware that the I2C class states "This class is intended to be used by sensor (and other I2C device) drivers. It probably should not be used directly."

We have been playing with the I2C class a fair amount lately and I wanted to share those results with others and see if anyone else can confirm some of these odd behaviors. I'm not sure if its just the device we are using or if several of the class methods are really broken.

We have a Lidar Lite v3 plugged into the kOnBoard I2C port. We have the Logic 4 as a scope/logic analyser. We have a working Pixy that we add to the bus, adding the Pixy doesn't change the behavior.

Class functions/members/methods:
Code:
AddressOnly()  // Doesn't appear to work at all
Transaction() // Write portion might work, but it reads back the same value all the time
Read() // reads back the same value all the time

ReadOnly() // works fine
WriteBulk() // Works fine
Write() // Works fine, but requires a two byte write
It appears as if the Read() and Transaction() always return the first value returned by the device. I can confirm this is the pattern on the bus, due to the logic analyser. So the problem has to be either the SDA pin is being driven by the RoboRio (I2C Slave Periph is active on the same pins) or somehow the Start/Stop/ReStart/ACK sequence is not being handled correctly and the Lidar gets stuck in some way that repeats the answer to the first request..which is really really weird.

A few specific questions:
1.) Can anyone else confirm that AddressOnly() doesn't work at all?
2.) Has anyone seen issues with "addressed" reads from I2C devices? (Pixy uses ReadOnly())

More generally, does anyone have experience with this type of behavior? Any other thoughts?

We were able to successfully read and write to the Lidar with the following code snippet (utilizing only "working" methods):
Code:
#define LIDAR_I2C_DEFAULT_ADDR           0x62
I2C* i2c_Lidar; //Declare i2c for Lidar
   i2c_Lidar = new I2C(I2C::Port::kOnboard, LIDAR_I2C_DEFAULT_ADDR); //(I2C::Port::kOnboard or kMXP, Pixy Address)
...
      i2c_Lidar->Write(0x00, 0x00);
      Wait(.025);
      i2c_Lidar->Write(0x00, 0x04);
      Wait(.005);

      djoSendData[0] = 0x01;  // Bulk Write Based Read_Only for a single register Read of 0x01 (status)
      i2c_Lidar->WriteBulk(djoSendData,1);
      i2c_Lidar->ReadOnly(1,LidarMassData);
      printf("Mass Data 0 %4X \n", LidarMassData[0]);
      Wait(0.001);

      djoSendData[0] = 0x8F;  // Bulk Write Based Read_Only for a two register Read of 0x8F (distance)
      i2c_Lidar->WriteBulk(djoSendData,1);
      i2c_Lidar->ReadOnly(2,LidarMassData);
      printf("Mass Data 0 %4X \n", LidarMassData[0]);
      printf("Mass Data 1 %4X \n", LidarMassData[1]);
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 13:19.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi