REXYGEN Community Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Login
    1. Home
    2. AlexanderH
    3. Posts
    A
    • Profile
    • Following 0
    • Followers 0
    • Topics 2
    • Posts 8
    • Best 1
    • Controversial 0
    • Groups 0

    Posts made by AlexanderH

    • RE: Problems Sequential reading channels ADC MCP3424 via I2C

      @Jan-Reitinger:

      Dear Jan, thank you for this quick reply. In the coming days I will send an email to the supplied email address. To be continued.

      Greetings,
      Alex

      posted in Communication (RS232
      A
      AlexanderH
    • RE: Problems Sequential reading channels ADC MCP3424 via I2C

      @Jan-Reitinger Dear Jan, I tried a lot last couple of days but nothing seems to work. I can only read one channel, and not multiple over time. I am also doubting if I should put the configuration of the different channels into the "init(void)" should keep that in the "main(void)". The channels cannot be read in parallel but should be read in sequential mode. I cannot figure out how to do that. Any help is appreciated.

      posted in Communication (RS232
      A
      AlexanderH
    • RE: Problems Sequential reading channels ADC MCP3424 via I2C

      @Jan-Reitinger Dear Jan, Thanks for these valuable tips :-). I will start with it this weekend. Hopefully I will succeed. If not, I will let you know via this forum. I will keep you posted. Greetings, Alex

      posted in Communication (RS232
      A
      AlexanderH
    • Problems Sequential reading channels ADC MCP3424 via I2C

      Hello, I am Alexander and probing a lot with Rexygen, with good results until now. However, at this moment I am trying to read data with the Rexlang block (I2C communication) from an ADC (analog-digital converter) MCP3424, without succes. I am relatively new with respect to the Rexlang block and i2c. I know that I have to send a not-acknowledge (NAK) bit and a stop bit to exit the current read operation and send a new read command for the latest conversion data. However I don't know how to do that.

      Hopefully somebody is willing to help me with my problem.
      Many thanks in advance.

      Below my code:

      /************************************************************
      *
      * REXLANG - Reading data from MCP3424 AD converter via I2C
      *
      *************************************************************/
      
      string parameter(0) i2c_dev; // the I2C bus is defined by the p0 parameter
      
      //assigning variables to outputs, these variables are WRITE-ONLY
      long output(0) channel1; // output of value of ADC channel 1
      long output(1) channel2; // output of value of ADC channel 2
      long output(2) channel3; // output of value of ADC channel 3
      long output(3) channel4; // output of value of ADC channel 4
      
      //declaration of variables
      long i2c_bufTx[3]; //buffer for transmitting data
      long i2c_bufRx[3]; //buffer for receiving data
      long i2c_bus_handle;
      long i2c_chip_address;
      long i2c_write_count;
      long i2c_read_count;
      long i2c_ret_fun;
      
      //the init procedure is executed once when the REXLANG function block initializes
      int init(void)
      {
        i2c_bus_handle = OpenI2C(i2c_dev); // open I2C bus
        /* Address: 1 1 0 1 A2 A1 A0 */
        i2c_chip_address = 0x68; // 7-bit address of the I2C device
        
        return 0;
      }
      
      //the main procedure is executed once in each sampling period
      long main(void)
      {
        /* Configuration register: 
           =====================================================================================
           | bit 7                | bit 6-5        | bit 4          | bit 3-2     | bit 1-0      |
           -------------------------------------------------------------------------------------
           | 1 = start conversion | 00 = channel 1 | 1 = continuous | 00 = 12-bit | 00 = gain x1 |
           | 0 = no effect        | 01 = channel 2 | 0 = one-shot   | 01 = 14-bit | 01 = gain x2 |
           |                      | 10 = channel 3 |                | 10 = 16-bit | 10 = gain x4 |
           |                      | 11 = channel 4 |                | 11 = 18-bit | 11 = gain 8x |
           =====================================================================================
        */
        i2c_bufTx[0] = 0x90; // read channel 1, continuous, 12bit, gain 1 (see MCP3424 datasheet)
        i2c_write_count = 1;
        i2c_read_count = 2;
        //Sending data via I2C
        i2c_ret_fun = I2C(i2c_bus_handle, i2c_chip_address, i2c_bufTx, i2c_write_count, i2c_bufRx, i2c_read_count);
        channel1 = ((i2c_bufRx[0]<<8) + i2c_bufRx[1])/2;
        
        return  0;
      
        i2c_bufTx[0] = 0xB0; // read channel 2 continuous, 12bit, gain 1 (see MCP3424 datasheet)
        i2c_write_count = 1;
        i2c_read_count = 2;
        //Sending data via I2C
        i2c_ret_fun = I2C(i2c_bus_handle, i2c_chip_address, i2c_bufTx, i2c_write_count, i2c_bufRx, i2c_read_count);
        channel2 = ((i2c_bufRx[0]<<8) + i2c_bufRx[1])/2;
        
        return 0;
      }
      
      //the exit procedure is executed once when the task is correctly terminated
      // (system shutdown, downloading new control algorithm, etc.)
      long exit(void)
      {
        if(i2c_bus_handle>=0) Close(i2c_bus_handle); // close I2C bus
        return 0;
      }
      posted in Communication (RS232
      A
      AlexanderH
    • RE: Problems reading from PCF8574A

      @Jan-Reitinger, Hi Jan,

      I solved the problem and can read from the PCF8574.
      Thank you very much for pointing me in the right direction :-).

      So this problem is solved -).

      With kind regards,
      Alexander

      posted in Communication (RS232
      A
      AlexanderH
    • RE: Problems reading from PCF8574A

      @Jan-Reitinger , Dear Jan,

      yesterday I was not in the opportunity to include the code. Below the (little modified) code in a better way. Thank you already very much for your reply.

      *
      *   REXLANG - Using the PCF8574A as Digital Input via I2C
      *
      *************************************************************/
      
      string parameter(0) i2c_dev; // the I2C bus is defined by the p0 parameter
      
      //assigning inputs to variables, these variables are READ-ONLY
      
      long output(10) digital_in; //the state of the input pins is published via output y10 of the REXLANG block
      
      //declaration of variables
      long i2c_bufTx[3]; //buffer for transmitting data
      long i2c_bufRx[3]; //buffer for receiving data
      long i2c_bus_handle;
      long i2c_chip_address;
      long i2c_write_count;
      long i2c_read_count;
      long i2c_ret_fun;
      
      //the init procedure is executed once when the REXLANG function block initializes
      long init(void)
      {
      i2c_bus_handle = OpenI2C(i2c_dev); // open I2C bus
      i2c_chip_address = 0x38; // 7-bit address of the I2C device
      
      i2c_ret_fun = I2C(i2c_bus_handle, i2c_chip_address, i2c_bufTx, i2c_write_count, i2c_bufRx, i2c_read_count);
      
      return 0;
      
      }
      
      //the main procedure is executed once in each sampling period
      long main(void)
      {
      //Reading inputs
      i2c_bufTx[0] = 0xFF; //Slave address (0x38) including the reading bit (1)
      i2c_write_count = 1;
      i2c_read_count = 0;
      i2c_ret_fun = I2C(i2c_bus_handle, i2c_chip_address, i2c_bufTx, i2c_write_count, i2c_bufRx, i2c_read_count);
      
      //Controlling outputs  
      i2c_write_count = 0;
      i2c_read_count = 1;
      digital_in = i2c_bufRx[0]; //publishing the received data    
      i2c_ret_fun = I2C(i2c_bus_handle, i2c_chip_address, i2c_bufTx, i2c_write_count, i2c_bufRx, i2c_read_count);
      
      return 0;
      
      }
      
      //the exit procedure is executed once when the task is correctly terminated
      // (system shutdown, downloading new control algorithm, etc.)
      
      long exit(void)
      
      {
      
      if(i2c_bus_handle>=0) Close(i2c_bus_handle); // close I2C bus
      return 0;
      
      }
      posted in Communication (RS232
      A
      AlexanderH
    • RE: Problems reading from PCF8574A

      @Jan-Reitinger Hi Jan,
      I tried already several things. So much I lost count already.
      I dont get any error in the system log screen. But i think i am not getting it in the read modus.

      Hopefully somebody can help me with this problem.

      With kind regards,
      Alexander

      posted in Communication (RS232
      A
      AlexanderH
    • Problems reading from PCF8574A

      Hello, I am Alexander and probing a lot with Rexygen, with good results until now. However, at this moment I am trying to read data from a PCF8574A, without succes. I am new with respect to the Rexlang block and i2c.

      Below my code:

      /************************************************************
      *

      • REXLANG - Using the PCF8574A as Digital Input via I2C

      *************************************************************/

      string parameter(0) i2c_dev; // the I2C bus is defined by the p0 parameter

      //assigning inputs to variables, these variables are READ-ONLY
      long input(3) digital_out; //the signal controlling the outputs is connected to input u3 of the REXLANG block
      long output(10) digital_in; //the state of the input pins is published via output y10 of the REXLANG block

      //declaration of variables
      long i2c_bufTx[3]; //buffer for transmitting data
      long i2c_bufRx[3]; //buffer for receiving data
      long i2c_bus_handle;
      long i2c_chip_address;
      long i2c_write_count;
      long i2c_read_count;
      long i2c_ret_fun;

      //the init procedure is executed once when the REXLANG function block initializes
      long init(void)
      {
      i2c_bus_handle = OpenI2C(i2c_dev); // open I2C bus
      i2c_chip_address = 0x38; // 7-bit address of the I2C device

      i2c_ret_fun = I2C(i2c_bus_handle, i2c_chip_address, i2c_bufTx, i2c_write_count, i2c_bufRx, i2c_read_count);
      
      return 0;
      

      }

      //the main procedure is executed once in each sampling period
      long main(void)
      {
      //Reading inputs
      i2c_bufTx[0] = 0x71; //Slave address (0x38) including the reading bit (1)
      i2c_bufTx[1] = digital_out; //masking the data to control the outputs
      i2c_write_count = 2;
      i2c_read_count = 0;
      i2c_ret_fun = I2C(i2c_bus_handle, i2c_chip_address, i2c_bufTx, i2c_write_count, i2c_bufRx, i2c_read_count);

      //Controlling outputs  
      i2c_write_count = 0;
      i2c_read_count = 1;
      digital_in = i2c_bufRx[0]; //publishing the received data    
      i2c_ret_fun = I2C(i2c_bus_handle, i2c_chip_address, i2c_bufTx, i2c_write_count, i2c_bufRx, i2c_read_count);
      
      return 0;
      

      }

      //the exit procedure is executed once when the task is correctly terminated
      // (system shutdown, downloading new control algorithm, etc.)
      long exit(void)
      {
      if(i2c_bus_handle>=0) Close(i2c_bus_handle); // close I2C bus
      return 0;
      }

      Hopefully somebody can help me and tell/show me what I am doing wrong.

      posted in Communication (RS232
      A
      AlexanderH