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

    Topics created by AlexanderH

    • A

      Problems Sequential reading channels ADC MCP3424 via I2C

      Communication (RS232, RS485, I2C, SPI, UDP, TCP, ...)
      • • • AlexanderH
      7
      0
      Votes
      7
      Posts
      383
      Views

      J

      Hi everyone,

      @AlexanderH solved his MCP3424 multi-channel reading issue! Here's the key takeaway:

      The Problem

      When reading multiple channels sequentially from MCP3424, conversion time must be respected. Each configuration byte starts a new conversion:

      12-bit: ~5ms (1/240 s) 18-bit: ~267ms (1/3.75 s)

      Table 4.3 from MCP3424 datasheet lists all data rates by resolution.

      The Solution

      One-shot mode + proper timing between configure/read operations:

      For 12-bit (2 channels):

      // Channel 1 - configure + convert + read i2c_bufTx[0] = 0x80; // CH1, one-shot, 12-bit, gain x1 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); Sleep(0.01); // wait for 10 ms before reading the first channel // Data rate: 12bit = 240 SPS, 14bit = 60 SPS, 16bit = 15 SPS, 18bit = 3.75 SPS i2c_write_count = 0; i2c_read_count = 3; i2c_ret_fun = I2C(i2c_bus_handle, i2c_chip_address, i2c_bufTx, i2c_write_count, i2c_bufRx, i2c_read_count); // i2c_bufRx[2] contains configuration byte channel1 = ((i2c_bufRx[0]<<8) + i2c_bufRx[1])/2; i2c_bufTx[0] = 0xA0; // channel 2, one-shot, 12bit, gain 1 (see MCP3424 datasheet) 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); Sleep(0.01); // wait for 10 ms before reading the second channel // Data rate: 12bit = 240 SPS, 14bit = 60 SPS, 16bit = 15 SPS, 18bit = 3.75 SPS i2c_write_count = 0; i2c_read_count = 3; 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; Important Notes

      Sleep time scales with resolution - 10ms works for 12-bit, 270ms needed for 18-bit

      Original MCP3422 example worked because it read only 1 channel (no channel switching). The message from the previous tick was probably returned as a response.

      Example Update

      REXYGEN example library will be extended with:

      read_mcp3424_12bit.c - 2 channels, 12-bit read_mcp3424_18bit.c - 2 channels, 18-bit

      Big thanks to Alexander for the thorough debugging, testing different timing scenarios, and sharing his working scripts!

      Cheers,
      Jan

    • A

      Problems reading from PCF8574A

      Communication (RS232, RS485, I2C, SPI, UDP, TCP, ...)
      • • • AlexanderH
      6
      1
      Votes
      6
      Posts
      687
      Views

      J

      @AlexanderH Hi,
      I'm sorry. For some reason I didn't get an email notifying me that you had replied. I'm glad you finally resolved the issue.

      Cheers,
      Jan