Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 6 of 6

Thread: 2 i2c buss timing issue

  1. #1

    2 i2c buss timing issue

    hello
    im dealing with teensy 3.6 project with 2 different i2c busses first is SCL0 SDA0
    and the second is SCL1 SDA1. im using i2c_t3 lib. master teensy connected to 2 devices.
    SCL0 SDA0 connected to another (slave) teensy 3.6 that controlling motors in my project.
    the SCL1 SDA1 connected to TCA9548A i2c multiplexer for 8 oled screens.
    i write the code in 2 parts to test stability.
    first part of the master code use wire.begin() for sending and recive command to teensy, to control motors and recive data.
    the second part is using wire1.begine to send data to screens.
    the codes work great till i combine the 2 parts together and use the 2 i2c in same time.
    *imported to know: SDA0 SCL0 running in 1MKh for most fast motors action and SDA1 SCL1 srunning is 400Kh cos this is the max speed of TCA9548A is 400kh.
    thats why im not running (soldering) all device on the same buss.
    now my problem is when im useing 2 i2c together they interrupts each other. i figure out that when commend sends to screens the motor freezing for that moment and keep move after the data has been sent.
    so i tested to be sure and i just stops the screen action in the code and thats prove me that i2c buss interrupt the other cos the motors now moves smooth again.
    i tested allso large interval time for screen up date but steel every time the interval ends and the screen command sent the motors stops reading for that moment.
    now my question is, first: the 2 i2c busses cant send data in the same time? if so why?
    and second:what is the right why to deal that situation for fast action in 2 i2c buss together?
    tnx
    rota

  2. #2
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    2,385
    Use DMA for the I2C transfers. Then, these will not be blocking.

  3. #3
    Quote Originally Posted by Theremingenieur View Post
    Use DMA for the I2C transfers. Then, these will not be blocking.
    tnx for you fast replay Theremingenieur
    i really dont know much about DMA for i2c transfer can you please give me some point to start with?
    that should be hard to implant it to the code or its just simple few lines?

    here is the code im working on
    Code:
    #include <i2c_t3.h>
    #include <MIDIUSB.h>
    #include <Bounce.h>
    
    #define TARGET    0x10              // All faders to target value as fast as possible. PID state is cleared with each command.
    #define FOLLOW    0x20 
    #define MESSAGE_LEN 17 
    #include <U8g2lib.h>
    
    U8G2_SSD1306_128X64_NONAME_F_SW_I2C  u8g2(U8G2_R0, /* clock=*/ 37, /* data=*/ 38, /* reset=*/ U8X8_PIN_NONE);   // All Boards without Reset of the Display
    
    int SCRNUM[8] = {0x07,0x06,0x05,0x04,0x03,0x02,0x01,0x00};
    int MUTNUM[8] = {0x07,0x06,0x05,0x04,0x03,0x02,0x01,0x00};
    int dbRA[8] = {0,0,0,0,0,0,0,0};
    
    String chname1[8];
    String chname2[8];
    String chname3[8];
    String chname4[8];
    int centerword[8];
    int hi[8];
    int lo[8];
    int hibyte[8];
    int lobyte[8];
    int Gain[8];
    String chmute[8] ;
    String chsolo[8] ;
    
    
    elapsedMicros sinceupdatescreenvalues;                         // timer for fader check
    unsigned int  updatescreenvaluesInterval = 5000000;
    
    unsigned long interval=500; // the time we need to wait
    unsigned long previousMillis=0; // millis() returns an unsigned long.  
    elapsedMicros sinceButtonmsgRead;                         // timer for fader check
    unsigned int  ButtonmsgReadInterval = 1000;
    elapsedMicros sinceFaderRead;                         // timer for fader check
    unsigned int  faderReadInterval = 5000;
    elapsedMicros sinceFaderWrite;                         // timer for fader check
    unsigned int   faderWriteInterval = 20000;
    
    bool FaderState = false; // state variable for the LED
    int faderTouchCount;
    
    uint8_t panelAddress = 0x66;
    byte faderValueData[MESSAGE_LEN];    // 16 bytes for values, 1 byte for touch
    byte faderTargetData[MESSAGE_LEN];   // 16 for target values, 1 byte for indicating which faders should be moved.
    
    boolean faderTouched[8];                              // boolean indicating if fader is touched
    int     faderValue[8];                                // fader value ranging 0 to 1023
    int     faderTarget[8];                               // fader target value ranging 0 to 1023
    boolean faderMove[8];                               // fader target value ranging 0 to 1023
    boolean updateFaders[8];
    byte INT2HEX[8] = {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07};
    
    //MUX BUTTOMS
    // Store the elapsed milliseconds for analog and multiplexed input smoothing/de-bouncing
    elapsedMillis msec0 = 0;
    long msecMux0[5] = {0, 0, 0, 0, 0};
    elapsedMillis msec1 = 0;
    long msecMux1[5] = {0, 0, 0, 0, 0};
    
    // Setup mux0 chip pins
    const int selectPins0[4] = {43, 44, 45, 46}; // S0~0, S1~1, S2~12
    //const int zOutput 
    const int zInput0 = 13; // Connect common (Z) to 19 (digital input)
    // Setup mux1 chip pins
    const int selectPins1[4] = {24, 25, 26, 27}; // S0~0, S1~1, S2~12
    //const int zOutput 
    const int zInput1 = 28; // Connect common (Z) to 19 (digital input)
    
    // Mux0 button states for de-bouncing
    int buttonState0[16] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
    int buttonStatePrev0[16] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
    // Mux1 button states for de-bouncing
    int buttonState1[15] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
    int buttonStatePrev1[15] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
    
    void setup() {
    //**** I2C ***** 
      Serial.begin(31250);
      // Setup for Master mode, pins 18/19, external pullups, 1MHz, 200ms default timeout
      Wire.begin(I2C_MASTER, 0x00, I2C_PINS_18_19, I2C_PULLUP_EXT, 1000000);
      Wire.setDefaultTimeout(200000); // 200ms
        Wire1.begin(I2C_MASTER, 0x00, I2C_PINS_37_38, I2C_PULLUP_EXT, 400000);
      Wire1.setDefaultTimeout(200000); // 200ms
      usbMIDI.setHandleControlChange(myControlChange);
      usbMIDI.setHandleSysEx(handleSysEx); 
      u8g2.begin();
    
      //startscreen();
      
      for (int i = 0; i < 4; i++)
      {
        pinMode(selectPins0[i], OUTPUT);
        digitalWrite(selectPins0[i], HIGH);
        pinMode(selectPins1[i], OUTPUT);
        digitalWrite(selectPins1[i], HIGH);
      }
      // Set up mux Z as an input
      pinMode(zInput0, INPUT_PULLUP);
      // Set up mux Z as an input
      pinMode(zInput1, INPUT_PULLUP);
    }
    
    void loop() {
      usbMIDI.read();
    
      // substract interval to maintain schedule
      // Buttons 
        if (sinceButtonmsgRead >=ButtonmsgReadInterval) {
        sinceButtonmsgRead = sinceButtonmsgRead - ButtonmsgReadInterval;
        SysexButtonmsg0();
        SysexButtonmsg1();
      }
      // substract interval to maintain schedule
      // read faders
      if (sinceFaderRead >=faderReadInterval) {
        sinceFaderRead = sinceFaderRead - faderReadInterval;
        getFaderData();
      }
      // substract interval to maintain schedule
      // write faders 
      if (sinceFaderWrite >=faderWriteInterval) {
        sinceFaderWrite = sinceFaderWrite - faderWriteInterval;
      for (int i=0;i<8;i++){
      if(updateFaders[i] == true ){  
        
        sendFaderCommand(TARGET);
      }
      }
      }
         if (sinceupdatescreenvalues >=updatescreenvaluesInterval) {
        sinceupdatescreenvalues = sinceupdatescreenvalues - updatescreenvaluesInterval;
       updatescreenvalues();  
       }
    }
    void tcaselect(uint8_t i) {
      if (i > 7) return;
      Wire1.beginTransmission(0x70);
      Wire1.write(1 << i);
      Wire1.endTransmission();  
    
    }
    void handleSysEx(const byte* sysExData, uint16_t sysExSize, bool complete) 
    { 
        //sysex array
        const byte *pSysExArray = usbMIDI.getSysExArray(); //capture data   
        for (int t=0;t<8;t++) {
        if (pSysExArray[6] == 0x10){  // 0x10 = Scribble strip 4 bytes
         if (pSysExArray[7] == SCRNUM[t]){           
             for (int i=8;i<11;i++) {
             String data = String(sysExData[i]);
             int w = u8g2.getUTF8Width(data.c_str());
             int center = 64-w;                           
             centerword[t] = center;                                                 
             chname1[t] = sysExData[8];
             chname2[t] = sysExData[9];
             chname3[t] = sysExData[10];
             chname4[t] = sysExData[11];
             }
             }
         }
        }
    }
    // get fader values and touch status
    void getFaderData() {
      size_t idx;
      int incomingFaderValue[16];    // 
      int touchCount=0;
      // Read from Slave
        Wire.requestFrom(panelAddress, (size_t)MESSAGE_LEN); // Read from Slave
        // Check if error occured
        if(Wire.getError())
           Serial.print("FAIL\n");
        else
        {
        // If no error then read Rx data into buffer
          idx = 0;
          while(Wire.available()) faderValueData[idx++] = Wire.readByte();
        // Process data in buffer
          for (int i=0;i<8;i++){
          updateFaders[i] = true;
        // combine bytes back to integers and put in temporary array
        incomingFaderValue[i]= faderValueData[(i*2)];
        incomingFaderValue[i]= incomingFaderValue[i] << 8 | faderValueData[(i*2)+1];
        // fill touch boolean array with last byte
        faderTouched[i] = 1 & faderValueData[16] >> i;
        if (faderTouched[i]) touchCount++;
    
          // check if faderValue needs to be updated
          if (incomingFaderValue[i]!=faderValue[i] and faderTouched[i]){
          faderValue[i]=incomingFaderValue[i];
          
          faderValue[i] = map(faderValue[i], 0, 1023, 126, 0);
            
          byte touch[] = { 0xb0 ,0x0f ,INT2HEX[i], 0xb0,0x2f,0x40}; // ACK msg - should be safe for any device even if listening for 7D
          usbMIDI.sendSysEx(6, touch, true);
          usbMIDI.sendControlChange(i,faderValue[i], 1); 
          usbMIDI.sendControlChange(i+32, faderValue[i], 1);      
          byte releas[] = { 0xb0 ,0x0f ,INT2HEX[i], 0xb0,0x2f,0x00}; // ACK msg - should be safe for any device even if listening for 7D
          usbMIDI.sendSysEx(6, releas, true);       
         
          
        }
      }
      faderTouchCount=touchCount;
      }
    }
    // Send command with faderTarget array values to fader, TARGET or FOLLOW mode
    void sendFaderCommand(byte mode){
      size_t idx;
      faderTargetData[16]=0;
        for (int i=0;i<8;i++){
          updateFaders[i] = false;
          faderTargetData[(i*2)]=(faderTarget[i] >> 8) & 0xFF;                // split Target integers over two bytes in array
          faderTargetData[(i*2)+1]=faderTarget[i] & 0xFF;
          faderTargetData[16] |= faderMove[i] << i;                           // fill last byte in array with faderMove boolean array   
        }
        Wire.beginTransmission(panelAddress);                                  // Transmit to Slave
        Wire.write(mode);                                                         // Send mode (TARGET or FOLLOW)
        for(idx = 0; idx < MESSAGE_LEN; idx++) Wire.write(faderTargetData[idx]);  // Write data to I2C Tx buffer
        Wire.endTransmission();                                                   // Transmit to Slave    
        faderstop();
    }
    void myControlChange(byte channel, byte control, byte value) {               // blink the LED a number of times  
    
      //value = map(value, 0, 127, 127, 0);
      for (int i=0; i<8;i++){
      if (control == i+32) {   
       hi[i] = value;
      }
      if (control == i) {
        lo[i] = value;
        Gain[i] = (hi[i] >> 7) + lo[i]*8.055;
        Gain[i] = map(Gain[i], 0, 1022, 1022, 0);
    
        faderMove[i] = 1; 
        
        dbRA[7]=GetDB(lo[0]);
        dbRA[6]=GetDB(lo[1]);
        dbRA[5]=GetDB(lo[2]);
        dbRA[4]=GetDB(lo[3]);
        dbRA[3]=GetDB(lo[4]);
        dbRA[2]=GetDB(lo[5]);
        dbRA[1]=GetDB(lo[6]);
        dbRA[0]=GetDB(lo[7]); 
      } 
      }
      for (int j=0;j<8;j++){
        faderTarget[j] = Gain[j];          
      }
    for (int t=0; t<8;t++){
      if (control == 12) {
      lobyte[t] = value;
      } 
      if (control == 44) {   
      hibyte[t] = value;
      }
    
         if(lobyte[t] == MUTNUM[t]){
         if(hibyte[t] == 2){
         chmute[t] = " ";
         }
         }
         if(lobyte[t] == MUTNUM[t]){
         if(hibyte[t] == 66){
         chmute[t] = "M";    
         }
         }   
         
         if(lobyte[t] == MUTNUM[t]){
         if(hibyte[t] == 67){  
         chsolo[t] = "S";    
         }     
         if(lobyte[t] == MUTNUM[t]&&hibyte[t] == 3){      
         chsolo[t] = " ";    
         }      
         }     
      if(chmute[t] == "M"){
        chsolo[t] = " ";
      }
       }
    }
    void selectMuxPin(byte pin){
      for (int i = 0; i < 4; i++)
      {
        if (pin & (1 << i)){
          digitalWrite(selectPins0[i], HIGH);
          delayMicroseconds(10);
        }
        else {
          digitalWrite(selectPins0[i], LOW);
          delayMicroseconds(10);
        }
        if (pin & (1 << i)){
          digitalWrite(selectPins1[i], HIGH);
          delayMicroseconds(10);
        }
        else {
          digitalWrite(selectPins1[i], LOW);
          delayMicroseconds(10);
        }
      }
    }
    void SysexButtonmsg0(){
      //MUX0
    
      // Loop through only the first five mux pins (last three are not connected)
      for (byte pin = 0; pin <= 15; pin++)
      {    
        // Effectively a 5ms debounce
        if ((millis() - msecMux0[pin]) >= 5) {
          selectMuxPin(pin); // Select one at a time
          buttonState0[pin] = digitalRead(zInput0); // and read Z
        
          if (buttonState0[pin] != buttonStatePrev0[pin]) {
            // If a button is pressed
       
       //SOLO BUTTONS  
        if (buttonState0[0] == 0) {    
        byte solo1push[] = { 0xB0,0x0F,0x00, 0xB0,0x2F,0x43}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, solo1push, true);
        }
        else {    
        byte solo1release[] = { 0xB0,0x0F,0x00, 0xB0,0x2F,0x03}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, solo1release, true);
        }
        if (buttonState0[2] == 0) {
        byte solo2push[] = { 0xB0,0x0F,0x01, 0xB0,0x2F,0x43}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, solo2push, true);
        }
        else { 
        byte solo2release[] = { 0xB0,0x0F,0x01, 0xB0,0x2F,0x03}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, solo2release, true);
        }  
        if (buttonState0[4] == 0) {
        byte solo3push[] = { 0xB0,0x0F,0x02, 0xB0,0x2F,0x43}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, solo3push, true);
        }
        else {   
        byte solo3release[] = { 0xB0,0x0F,0x02, 0xB0,0x2F,0x03}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, solo3release, true);
        }   
        if (buttonState0[6] == 0) {
        byte solo4push[] = { 0xB0,0x0F,0x03, 0xB0,0x2F,0x43}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, solo4push, true);
        }
        else { 
        byte solo4release[] = { 0xB0,0x0F,0x03, 0xB0,0x2F,0x03}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, solo4release, true);
        }   
        if (buttonState0[8] == 0) {
        byte solo5push[] = { 0xB0,0x0F,0x04, 0xB0,0x2F,0x43}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, solo5push, true);
        }
        else { 
        byte solo5release[] = { 0xB0,0x0F,0x04, 0xB0,0x2F,0x03}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, solo5release, true);
        }    
        if (buttonState0[10] == 0) {
        byte solo6push[] = { 0xB0,0x0F,0x05, 0xB0,0x2F,0x43}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, solo6push, true);
        }
        else { 
        byte solo6release[] = { 0xB0,0x0F,0x05, 0xB0,0x2F,0x03}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, solo6release, true);
        }   
        if (buttonState0[12] == 0) {
        byte solo7push[] = { 0xB0,0x0F,0x06, 0xB0,0x2F,0x43}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, solo7push, true);
        }
        else { 
        byte solo7release[] = { 0xB0,0x0F,0x06, 0xB0,0x2F,0x03}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, solo7release, true);
        }   
        if (buttonState0[14] == 0) {
        byte solo8push[] = { 0xB0,0x0F,0x07, 0xB0,0x2F,0x43}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, solo8push, true);
        }
        else { 
        byte solo8release[] = { 0xB0,0x0F,0x07, 0xB0,0x2F,0x03}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, solo8release, true);
        }
         
    //MUTE BUTTONS
        if (buttonState0[1] == 0) {
        byte mute1push[] = { 0xB0,0x0F,0x00, 0xB0,0x2F,0x42}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, mute1push, true);
        }
        else {
        byte mute1release[] = { 0xB0,0x0F,0x00, 0xB0,0x2F,0x02}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, mute1release, true);
        }  
        if (buttonState0[3] == 0) {
        byte mute2push[] = { 0xB0,0x0F,0x01, 0xB0,0x2F,0x42}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, mute2push, true);
        }
        else {
        byte mute2release[] = { 0xB0,0x0F,0x01, 0xB0,0x2F,0x02}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, mute2release, true);
        }     
        if (buttonState0[5] == 0) {
        byte mute3push[] = { 0xB0,0x0F,0x02, 0xB0,0x2F,0x42}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, mute3push, true);
        }
        else {
        byte mute3release[] = { 0xB0,0x0F,0x02, 0xB0,0x2F,0x02}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, mute3release, true);
        }    
        if (buttonState0[7] == 0) {
        byte mute4push[] = { 0xB0,0x0F,0x03, 0xB0,0x2F,0x42}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, mute4push, true);
        }
        else {
        byte mute4release[] = { 0xB0,0x0F,0x03, 0xB0,0x2F,0x02}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, mute4release, true);
        }     
        if (buttonState0[9] == 0) {
        byte mute5push[] = { 0xB0,0x0F,0x04, 0xB0,0x2F,0x42}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, mute5push, true);
        }
        else {   
        byte mute5release[] = { 0xB0,0x0F,0x04, 0xB0,0x2F,0x02}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, mute5release, true);
        }       
        if (buttonState0[11] == 0) {
        byte mute6push[] = { 0xB0,0x0F,0x05, 0xB0,0x2F,0x42}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, mute6push, true);
        }
        else {   
        byte mute6release[] = { 0xB0,0x0F,0x05, 0xB0,0x2F,0x02}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, mute6release, true);
        }     
        if (buttonState0[13] == 0) {  
        byte mute7push[] = { 0xB0,0x0F,0x06, 0xB0,0x2F,0x42}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, mute7push, true);
        }
        else { 
        byte mute7release[] = { 0xB0,0x0F,0x06, 0xB0,0x2F,0x02}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, mute7release, true);
        }
        if (buttonState0[15] == 0) {  
        byte mute8push[] = { 0xB0,0x0F,0x07, 0xB0,0x2F,0x42}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, mute8push, true);
        }
        else {     
        byte mute8release[] = { 0xB0,0x0F,0x07, 0xB0,0x2F,0x02}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, mute8release, true);
        }
            msecMux0[pin] = millis();
            buttonStatePrev0[pin] = buttonState0[pin];
          }
        }
      }
      while (usbMIDI.read()) { 
        // ignore incoming messages
      }
      delay(10);
    }
    void SysexButtonmsg1(){
      //TRANSPORT BUTTONS
    //MUX1
      // Loop through only the first five mux pins (last three are not connected)
      for (byte pin = 0; pin <= 14; pin++)
      {    
        // Effectively a 5ms debounce
       if ((millis() - msecMux1[pin]) >= 5) {
          selectMuxPin(pin); // Select one at a time
          buttonState1[pin] = digitalRead(zInput1); // and read Z
          if (buttonState1[pin] != buttonStatePrev1[pin]) {
            
        // If a button is pressed
        if (buttonState1[2] == 0) {  
        byte playpush[] = { 0xB0,0x0F,0x0e, 0xB0,0x2F,0x44}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, playpush, true);
        }
        else { 
        byte playrelease[] = { 0xB0,0x0F,0x0e, 0xB0,0x2F,0x04}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, playrelease, true);
        }
        if (buttonState1[3] == 0) {  
        byte stoppush[] = { 0xB0,0x0F,0x0e, 0xB0,0x2F,0x43}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, stoppush, true);
        }
        else { 
        byte stoprelease[] = { 0xB0,0x0F,0x0e, 0xB0,0x2F,0x03}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, stoprelease, true);
        }
        if (buttonState1[1] == 0) {  
        byte fastfwdpush[] = { 0xB0,0x0F,0x0e, 0xB0,0x2F,0x42}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, fastfwdpush, true);
        }
        else { 
        byte fastfwdrelease[] = { 0xB0,0x0F,0x0e, 0xB0,0x2F,0x02}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, fastfwdrelease, true);
        }
        if (buttonState1[0] == 0) {  
        byte rewindpush[] = { 0xB0,0x0F,0x0e, 0xB0,0x2F,0x41}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, rewindpush, true);
        }
        else { 
        byte rewindrelease[] = { 0xB0,0x0F,0x0e, 0xB0,0x2F,0x01}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, rewindrelease, true);
        }
        if (buttonState1[4] == 0) {  
        byte recpush[] = { 0xB0,0x0F,0x0e, 0xB0,0x2F,0x45}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, recpush, true);
        }
        else { 
        byte recrelease[] = { 0xB0,0x0F,0x0e, 0xB0,0x2F,0x05}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, recrelease, true);
        }
        if (buttonState1[5] == 0) {  
        byte qckpnchpush[] = { 0xB0,0x0F,0x0f, 0xB0,0x2F,0x44}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, qckpnchpush, true);
        }
        else { 
        byte qckpnchrelease[] = { 0xB0,0x0F,0x0f, 0xB0,0x2F,0x04}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, qckpnchrelease, true);
        }
        if (buttonState1[6] == 0) {  
        byte looppush[] = { 0xB0,0x0F,0x0f, 0xB0,0x2F,0x43}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, looppush, true);
        }
        else { 
        byte looprelease[] = { 0xB0,0x0F,0x0f, 0xB0,0x2F,0x03}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, looprelease, true);
        }
    
    // READ TOUCH LATCH WRITE  
        if (buttonState1[7] == 0) {  
        byte readpush[] = { 0xB0,0x0F,0x18, 0xB0,0x2F,0x42}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, readpush, true);
        }
        else { 
        byte readrelease[] = { 0xB0,0x0F,0x18, 0xB0,0x2F,0x02}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, readrelease, true);
        }
        if (buttonState1[8] == 0) {  
        byte touchpush[] = { 0xB0,0x0F,0x18, 0xB0,0x2F,0x45}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, touchpush, true);
        }
        else { 
        byte touchrelease[] = { 0xB0,0x0F,0x18, 0xB0,0x2F,0x05}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, touchrelease, true);
        }
        if (buttonState1[9] == 0) {  
        byte latchpush[] = { 0xB0,0x0F,0x18, 0xB0,0x2F,0x41}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, latchpush, true);
        }
        else { 
        byte latchrelease[] = { 0xB0,0x0F,0x18, 0xB0,0x2F,0x01}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, latchrelease, true);
        }
        if (buttonState1[10] == 0) {  
        byte writepush[] = { 0xB0,0x0F,0x18, 0xB0,0x2F,0x44}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, writepush, true);
        }
        else { 
        byte writerelease[] = { 0xB0,0x0F,0x18, 0xB0,0x2F,0x04}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, writerelease, true);
        }
    
    //BANKS LEFT RIGHT  
        if (buttonState1[14] == 0) {  
        byte  chanl1leftpush[] = { 0xB0,0x0F,0x0a, 0xB0,0x2F,0x40}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, chanl1leftpush, true);
        }
        else { 
        byte chanl1leftrelease[] = { 0xB0,0x0F,0x0a, 0xB0,0x2F,0x00}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, chanl1leftrelease, true);
        }
        if (buttonState1[13] == 0) {  
        byte  chanl8leftpush[] = { 0xB0,0x0F,0x0a, 0xB0,0x2F,0x41}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, chanl8leftpush, true);
        }
        else { 
        byte chanl8leftrelease[] = { 0xB0,0x0F,0x0a, 0xB0,0x2F,0x01}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, chanl8leftrelease, true);
        }
        if (buttonState1[11] == 0) {  
        byte  chanl1rightpush[] = { 0xB0,0x0F,0x0a, 0xB0,0x2F,0x42}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, chanl1rightpush, true);
        }
        else { 
        byte chanl1rightrelease[] = { 0xB0,0x0F,0x0a, 0xB0,0x2F,0x02}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, chanl1rightrelease, true);
        }
        if (buttonState1[12] == 0) {  
        byte  chanl8rightpush[] = { 0xB0,0x0F,0x0a, 0xB0,0x2F,0x43}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, chanl8rightpush, true);
        }
        else { 
        byte chanl8rightrelease[] = { 0xB0,0x0F,0x0a, 0xB0,0x2F,0x03}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, chanl8rightrelease, true);
        }
            msecMux1[pin] = millis();
            buttonStatePrev1[pin] = buttonState1[pin];
          }
        }
      }
      while (usbMIDI.read()) { 
        // ignore incoming messages
      }
      delay(10);
    }
    void faderstop() {
     unsigned long FaderStopMillis = millis(); // grab current time
     
     // check if "interval" time has passed (1000 milliseconds)
     if ((unsigned long)(FaderStopMillis - previousMillis) >= interval) {
        for (int i=0; i<8;i++){   
        faderMove[i] = 0;    
        }
       previousMillis = millis();
     }
    }
    void updatescreenvalues(){
         
         for (int i=0;i<8;i++){
         Wire1.begin();   
         tcaselect(i);    
        
         //larg letters names
         chname1[i].toUpperCase();
         chname2[i].toUpperCase();
         chname3[i].toUpperCase();
         chname4[i].toUpperCase();
         
         //page structure
         u8g2.clearBuffer();
         u8g2.drawLine(0, 32, 128, 32);
         u8g2.setFont(u8g2_font_ncenB10_tr); // choose a suitable font
         u8g2.setCursor(90, 60);
         u8g2.print("dbA");
         
         //values update
         u8g2.setFont(u8g2_font_ncenB14_tr);     
         u8g2.setCursor(centerword[i], 18);       
         u8g2.print(String(chname1[i]+chname2[i]+chname3[i]+chname4[i]));            
         u8g2.setFont(u8g2_font_ncenB14_tr); // choose a suitable font
         u8g2.setCursor(42, 60);
         u8g2.print(dbRA[i]);
    
          //mute update screens      
         if(chmute[i] == "M"){
         u8g2.setFontMode(1);  /* activate transparent font mode */
         u8g2.drawFrame(00,40, 24, 23);
         u8g2.setDrawColor(2);
         u8g2.setFont(u8g2_font_ncenB12_tr); // choose a suitable font
         u8g2.setCursor(4, 58);    
         u8g2.print(chmute[i]);  
         }
         
         //solo update screens
         if(chsolo[i] == "S"){
         u8g2.setFontMode(1);  /* activate transparent font mode */
    //     u8g2.drawBox(01,35, 24, 50);
    //     u8g2.setDrawColor(2);
         u8g2.drawBox(00,40, 24, 23);
         u8g2.setFont(u8g2_font_ncenB12_tr); // choose a suitable font
         u8g2.setCursor(6, 58);
         u8g2.print(chsolo[i]);
      
         }
         u8g2.sendBuffer(); 
         }
    }
    
    //Startup screen
    void startscreen(){
      for (int i=0;i<8;i++){
      Wire1.begin();
      tcaselect(i);
      u8g2.begin();
      u8g2.clearBuffer();          // clear the internal memory
      u8g2.drawRFrame(2 ,2,122,62,7);
      u8g2.setFont(u8g2_font_ncenB18_tr); // choose a suitable font
      u8g2.setCursor(25,35);
      u8g2.print("AMC8");  // write something to the internal memory
      u8g2.setFont(u8g2_font_ncenB08_tr); // choose a suitable font
      u8g2.setCursor(26, 55);
      u8g2.print("HUI Protocol"); // write something to the internal memory
      u8g2.sendBuffer();          // transfer internal memory to the display
     }
    delay(7000);
    }
    
    //velocity to db map
    float GetDB(int Gain){ 
    float DB; 
     if (Gain == 0){
    DB = -140.0 ;
    }
    if (Gain == 1){
    DB = -100.0 ;
    }
    if (Gain == 2){
    DB = -84.0 ;
    }
    if (Gain == 3){
    DB   = -78.4 ;
    }
    if (Gain == 4){
    DB   = -72.7 ;
    }
    if (Gain == 5){
    DB   = -69.7 ;
    }
    if (Gain == 6){
    DB   = -67.2;
    }
    if (Gain == 7){
    DB   = -64.6;
    }
    if (Gain == 8){
    DB   = -62.0;
    }
    if (Gain == 9){
    DB   = -59.4;
    }
    if (Gain == 10){
    DB   = -56.8;
    }
    if (Gain == 11){
    DB  = -54.2;
    }
    if (Gain == 12){  
    DB = -51.6;
    }
    if (Gain == 13){
    DB  = -49.1;
    }
    if (Gain == 14){
    DB = -46.5;
    }
    if (Gain == 15){  
    DB   = -43.9;
    }
    if (Gain == 16){
    DB  = -41.3;
    }
    if (Gain == 17){
    DB  = -39.7;
    }
    if (Gain == 18){
    DB  = -39.0;
    }
    if (Gain == 19){
    DB  = -38.4;
    }
    if (Gain == 20){
    DB  = -37.7;
    }
    if (Gain == 21){
    DB  = -37.1;
    }
    if (Gain == 22){
    DB  = -36.4;
    }
    if (Gain == 23){
    DB  = -35.8;
    }
    if (Gain == 24){
    DB  = -35.1 ;
    }
    if (Gain == 25){
    DB  = -34.5;
    }
    if (Gain == 26){
    DB  = -33.8;
    }
    if (Gain == 27){
    DB  = -33.2;
    }
    if (Gain == 28){
    DB  = -32.5;
    }
    if (Gain == 29){
    DB  = -31.9;
    }
    if (Gain == 30){
    DB  = -31.2;
    }
    if (Gain == 31){
    DB  = -30.6;
    }
    if (Gain == 32){
    DB  = -30.0;
    }
    if (Gain == 33){
    DB  = -29.3;
    }
    if (Gain == 34){
    DB  = -28.7;
    }
    if (Gain == 35){
    DB  = -28.0;
    }
    if (Gain == 36){
    DB  = -27.4;
    }
    if (Gain == 37){
    DB  = -26.7;
    }
    if (Gain == 38){
    DB  = -26.1;
    }
    if (Gain == 39){
    DB  = -25.4 ;
    }
    if (Gain == 40){
    DB  = -24.8;
    }
    if (Gain == 41){
    DB  = -24.1;
    }
    if (Gain == 42){
    DB  = -23.5;
    }
    if (Gain == 43){
    DB  = -22.8;
    }
    if (Gain == 44){
    DB  = -22.2;
    }
    if (Gain == 45){
    DB  = -21.5;
    }
    if (Gain == 46){
    DB  = -20.9;
    }
    if (Gain == 47){
    DB  = -20.2;
    }
    if (Gain == 48){
    DB  = -19.7;
    }
    if (Gain == 49){
    DB  = -19.3;
    }
    if (Gain == 50){
    DB  = -18.9;
    }
    if (Gain == 51){
    DB  = -18.5;
    }
    if (Gain == 52){
    DB  = -18.1;
    }
    if (Gain == 53){
    DB  = -17.5;
    }
    if (Gain == 54){
    DB  = -17.2;
    }
    if (Gain == 55){
    DB  = -16.8;
    }
    if (Gain == 56){
    DB  = -16.4;
    }
    if (Gain == 57){
    DB  = -16.0;
    }
    if (Gain == 58){
    DB  = -15.6;
    }
    if (Gain == 59){
    DB  = -15.2;
    }
    if (Gain == 60){
    DB  = -14.8;
    }
    if (Gain == 61){
    DB  = -14.4;
    }
    if (Gain == 62){
    DB  = -13.9 ;
    }
    if (Gain == 63){
    DB  = -13.5;
    }
    if (Gain == 64){
    DB  = -13.1;
    }
    if (Gain == 65){
    DB  = -12.7;
    }
    if (Gain == 66){
    DB  = -12.2;
    }
    if (Gain == 67){
    DB  = -11.8;
    }
    if (Gain == 68){
    DB  = -11.4;
    }
    if (Gain == 69){
    DB  = -11.0;
    }
    if (Gain == 70){
    DB  = -10.6;
    }
    if (Gain == 71){
    DB  = -10.2;
    }
    if (Gain == 72){
    DB  = -9.8;
    }
    if (Gain == 73){
    DB  = -9.4 ;
    }
    if (Gain == 74){
    DB  = -8.9;
    }
    if (Gain == 75){
    DB  = -8.5;
    }
    if (Gain == 76){
    DB  = -8.1;
    }
    if (Gain == 77){
    DB  = -7.7;
    }
    if (Gain == 78){
    DB  = -7.3;
    }
    if (Gain == 79){
    DB  = -6.9;
    }
    if (Gain == 80){
    DB  = -6.5;
    }
    if (Gain == 81){
    DB  = -6.1;
    }
    if (Gain == 82){
    DB  = -5.6;
    }
    if (Gain == 83){
    DB  = -5.2;
    }
    if (Gain == 84){
    DB  = -4.8;
    }
    if (Gain == 85){
    DB  = -4.4;
    }
    if (Gain == 86){
    DB  = -4.0;
    }
    if (Gain == 87){
    DB  = -3.6;
    }
    if (Gain == 88){
    DB  = -3.2;
    }
    if (Gain == 89){
    DB  = -2.8;
    }
    if (Gain == 90){
    DB  = -2.3;
    }
    if (Gain == 91){
    DB  = -1.9 ;
    }
    if (Gain == 92){
    DB  = -1.5;
    }
    if (Gain == 93){
    DB  = -1.1;
    }
    if (Gain == 94){
    DB  = -0.7;
    }
    if (Gain == 95){
    DB  = -0.3;
    }
    if (Gain == 96){
    DB  = 0.1;
    }
    if (Gain == 97){
    DB  = 0.5;
    }
    if (Gain == 98){
    DB  = 1.0;
    }
    if (Gain == 99){
    DB  = 1.2;
    }
    if (Gain == 100){
    DB = 1.6;
    }
    if (Gain == 101){
    DB = 2.0;
    }
    if (Gain == 102){
    DB = 2.4;
    }
    if (Gain == 103){
    DB = 2.8;
    }
    if (Gain == 104){
    DB = 3.1;
    }
    if (Gain == 105){
    DB = 3.5;
    }
    if (Gain == 106){
    DB = 4.0;
    }
    if (Gain == 107){
    DB = 4.2;
    }
    if (Gain == 108){
    DB = 4.6;
    }
    if (Gain == 109){
    DB = 5.0;
    }
    if (Gain == 110){
    DB = 5.4;
    }
    if (Gain == 111){
    DB = 5.7;
    }
    if (Gain == 112){
    DB = 6.1;
    }
    if (Gain == 113){
    DB = 6.5;
    }
    if (Gain == 114){
    DB = 7.0;
    }
    if (Gain == 115){
    DB = 7.2;
    }
    if (Gain == 116){
    DB = 7.6;
    }
    if (Gain == 117){
    DB = 8.0;
    }
    if (Gain == 118){
    DB = 8.4;
    }
    if (Gain == 119){
    DB = 8.7;
    }
    if (Gain == 120){
    DB =9.1;
    }
    if (Gain == 121){
    DB = 9.5;
    }
    if (Gain == 122){
    DB = 10.0;
    }
    if (Gain == 123){
    DB = 10.2;
    }
    if (Gain == 124){
    DB = 10.6;
    }
    if (Gain == 125){
    DB = 11.0;
    }
    if (Gain == 126){
    DB = 11.4;
    }
    if (Gain == 127){
    DB = 12.00;
    }
      return DB;}

  4. #4
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    2,385
    Using the non blocking DMA mode is described here:https://github.com/nox771/i2c_t3

  5. #5
    ok i tryed to config it in that way but its not changing much

    Code:
      Wire.begin(I2C_MASTER, 0x00, I2C_PINS_18_19, I2C_PULLUP_EXT, 1000000,I2C_OP_MODE_DMA);
      Wire.setDefaultTimeout(200000); // 200ms
      Wire1.begin(I2C_MASTER, 0x00, I2C_PINS_37_38, I2C_PULLUP_EXT, 400000,I2C_OP_MODE_DMA);
      Wire1.setDefaultTimeout(200000); // 200ms
    im config it right?

  6. #6
    Quote Originally Posted by rotabox View Post
    ok i tryed to config it in that way but its not changing much

    Code:
      Wire.begin(I2C_MASTER, 0x00, I2C_PINS_18_19, I2C_PULLUP_EXT, 1000000,I2C_OP_MODE_DMA);
      Wire.setDefaultTimeout(200000); // 200ms
      Wire1.begin(I2C_MASTER, 0x00, I2C_PINS_37_38, I2C_PULLUP_EXT, 400000,I2C_OP_MODE_DMA);
      Wire1.setDefaultTimeout(200000); // 200ms
    im config it right?
    I'm.reelly lost here about DMA I read some info and read some examples and I try few thing on my system but I can't get the 2 i2c write to slaves and read in "same time" like I post I try configuration of DMA in wire.begin() and also in setopmode.
    That is any chance that i2c_t3 not build to work simultaneity on 2 i2c busses together?
    I read in some place that for work with two busses I need to double all the i2c_t3 library.
    And that is too completed for me I guess.
    Any solution?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •