Some time ago I've made a sensor using the ADS7828 A/D converter. It has 8 input channels. Datasheet: http://www.ti.com/lit/ds/symlink/ads7828.pdf
In the datasheet is an explanation of how to use it on I2C, but I can't get it to work on NXC, because I don't know how the commands in NXC exactely work. I don't find any usefull examples of using I2C in NXC either.
Update: So far I've come up with this, but it doesn't work...
Code: Select all
 
byte CMD_Read[] = {0x90, 0x84};
 byte CMD_StartWrite[] = {0x91};
 byte cnt = 18;
 byte inBuffer[];
 char result;
 bool BResult;
 string resultBuffer;
 task main() {
      SetSensorLowspeed(S1);
      result = I2CWrite(S1, 2, CMD_Read);
      Wait(10);
      if (result == NO_ERR){
       TextOut(0, LCD_LINE1, "Write OK!");
      }
      BResult = I2CBytes(S1, CMD_StartWrite, cnt, inBuffer);
      result = I2CStatus(S1, cnt);
      if (result == NO_ERR){
       TextOut(0, LCD_LINE2, "Bytes OK!");
      }
      resultBuffer = ByteArrayToStr(inBuffer);
      TextOut(0, LCD_LINE4, resultBuffer);
      Wait(SEC_5);
 }
Does anyone knows how to access the values of the ADC in NXC?
Help is much appreciated!
Thank you,
Knutselman