Skip to topic | Skip to bottom
Home
Instrumentation
Instrumentation.ArduinoTTHybridCoder1.1 - 04 Jun 2013 - 17:27 - AlvaroDosiltopic end

Start of topic | Skip to actions
// This program is used to program any of the 4 beetles of the LHCb Silicon Tracker TT hybrid while reading with the Alibava system
// The program waits for the number of the beetle to be programmed on the serial monitor,
// After programmig compare with the read back data
// by Pablo Vazquez

// Created 7 June 2011
//Modified 30 July 2012 -> in new Wire.h library send command is replaced with write and receive with read
//by Pablo Rodriguez

#include <Wire.h>
#include <inttypes.h>

void setup()
{
 Wire.begin(); // join i2c bus
 Serial.begin(9600);
 Serial.flush();
 Serial.println("Type the Beetle to be programmed [0,1,2,3]:");
}

//int beetleAddress [4] = {0x20, 0x21, 0x22, 0x23};  // Beeetle addresses of the TT hybrid
int beetleAddress [4] = {0x10, 0x12, 0x14, 0x16};  // Beeetle addresses of the TT hybrid
//int p;  // pointer for beetleAddress array
uint8_t p;
// Beetle Parameters   "PointerByte","Itp","Ipre","Isha","Ibuf","Vfp","Vfs", "Icomp", "Ithdelta", "Ithmain","Vrc","Ipipe", "Vd","Vdcl","Ivoltbuf","Isf","Icurrbuf","Latency","ROCtrl","RclkDiv","CompCtrl"
byte beetleWrite[21] = {         0x0, 0x00,  0x4c,  0x0A,  0x0A, 0x00, 0x00,     0x0,        0x0,       0x0, 0x00,   0x0d, 0x82,  0x69,      0x14, 0x1a,      0x66,     0x80,    0x1a,     0x00,   0x09};
byte beetleRead[21];
char* i2cEnd[5] = {"success.", "data too long to fit in transmit buffer.", "received NACK on transmit of address.", "received NACK on transmit of data.", "other error."}; // status of i2c transmission
byte q=0; // result of i2c transmission
byte i=0,error=0;
void loop()
{
 if ( Serial.available() > 0) {                   // write on i2c only when data is availabe on the console
    p = Serial.read() - 48;                        // substrac 48 to convert the ascii value given by Serial.read to the desired inte
    Serial.flush();                                // flush the console buffer
    if  ( 0 <= p && p <= 3) {
     Serial.println(" test1 ");
     Wire.beginTransmission(beetleAddress[p]);    // set i2c address to write
     Serial.println(" test2 ");
     Wire.write(beetleWrite,sizeof(beetleWrite));  // Beetle programming
     Serial.println(" test3 ");
     q = Wire.endTransmission();
     Serial.println(" test4 ");
     Serial.println(q);

     if ( q == 0 ) {                              // if no error on Beetle programming
       Wire.beginTransmission(beetleAddress[p]);  // set i2c address to write
       uint8_t p0 = 0;
       Wire.write(p0);                              // preset the Beetle PointerByte
       q = Wire.endTransmission();                //
       if ( q == 0 ) {                            // if no error on preset PointerByte
         i=1;                                     // i=0 is PointerByte, data starts on i=1
         Wire.requestFrom(beetleAddress[p],21);   // read back programmed Beetle
         while ( Wire.available() ) {             // slave may send less than requested  
           beetleRead[i] = Wire.read();        // fill beetleRead with data from beetle
           i++;
         }
         for ( i=0;i<sizeof(beetleRead);i++ ) {   // compare read and write values
           if ( beetleRead[i] != beetleWrite[i] ) {
             error++;
           }
         }
         if ( error != 0) {                      // in case write and read values do not match
           Serial.print("Beetle ");
           Serial.print(p);
           Serial.println(" Error: beetleWrite and beetleRead do not match.");
           Serial.print("beetleWrite: ");
           for (i=0;i<sizeof(beetleWrite);i++) {      
             Serial.print(beetleWrite[i],HEX);
             Serial.print(", ");
           }
           Serial.println();
           Serial.print("beetleRead:  ");
           for (i=0;i<sizeof(beetleRead);i++) {
             Serial.print(beetleRead[i],HEX);
             Serial.print(", ");
           }
           Serial.println();
         }
         else {
           Serial.print("Beetle ");
           Serial.print(p);
           Serial.println(" programmed successfully: ");
         }
       }
       else {                                    // print error of PointerByte preset
         Serial.print("Beetle ");
         Serial.print(p);
         Serial.print(" pointerByte preset error: ");
         Serial.println(i2cEnd[q]);
       }
     }
     else {                                       // print error of beetle programming
       Serial.print("Beetle ");
       Serial.print(p);
       Serial.print(" programming error: ");
       Serial.println(i2cEnd[q]);
     }
    }
    else {
     Serial.print(p);
     Serial.println(" is not a valid");
    }
    Serial.println("Type the Beetle to be programmed [0,1,2,3]:");    
 }
}

-- AlvaroDosil - 04 Jun 2013
to top


You are here: Instrumentation > SiliconResearch > Documentation > Arduino > ArduinoTTHybridCode

to top

Copyright © 1999-2019 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding this material Send feedback