AMS ENS210 sensor on SK-S7G2

Hello suport!

I have this sensor: http://ams.com/eng/Support/Demoboards/Environmental-Sensors/Relative-Humidity-and-Temperature-Sensors/ENS210-Eval-Kit

It comes with a USB dongle to interface from I2C to USB. 

The SK-S7G2 has both I2C and USB ports. Can this sensor be interfaced to the board via USB? or does the USB connection only work when plugged to a computer?

1) if it can be interfaced via USB to the S7G2 board, would the protocol still be I2C or does it need to be configured serial/USB?

Any references I can use to set up the port configuration and display the readings on my touchgfx GUI?


2) if I interface using the I2C pins (SCL/SDA) what kind of cable can I use to go from the sensor to the ports of the S7G2? I noticed that regular female jumper wires don't quite fit the pins on the sensor.

Thank you.

  • Hi Zfeng,

    The choice is really up to you. You can connect directly to the SK S7 J6 and configure the S7 as a USB Host and select the CDC class driver.

    You can also disconnect the sensor board from the USB dongle and just connect the I2C SDA, SCL, Vcc and GND to the pins on the SK. This is most probably the way you will be using it in an embedded system. You have a choice of which pins to use - check the schematic of the SK board and pick port you want to connect to. Configure the pins as n-channel open drain and either the SCI_I2C or RIIC interface. Please refer to the module guides for further information.

    There is also a IoT fast prototyping kit S5D9 available from Seed Studio which has an ENS210, a MS5637 barometric pressure sensor and a Bosch BMC150 6-axis sensor already interfaced to the MCU. This is an inexpensive board that may be easier for you to experiment with as everything is already interfaced to the processor. wiki.seeedstudio.com/.../

    -Gary
  • In reply to garyj:

    Thanks. I'll be connecting just the sensor board to the SK board. However, I'm a bit puzzled right now by the peripheral/port configuration.

    Say I want to use SCI1 as the I2C connection for the sensor:

    Which pins on the hradware board would 213/212 correspond to? They aren't shown on the board. Are the labels read a certain way to determine that?

  • In reply to zfeng:

    Hi Zfeng,

    P2_13 and P2_12 are dedicated to the XTAL1 and XTAL2 on this board and are not available for I/O re-assignment.
    Please use the schematic for the SK_S7G2 board to determine what is available on the board. About 80% of the I/O pins are available, the rest are in use and can't be re-assigned.

    -Gary
  • In reply to garyj:

    Thanks. I ended up using SCI2 with pins P302/301. I'm first testing the sensor by printing to the debug console. So far the I2C checks out but when it comes to the ENS sensor it's failing in the Open function. I'm using a reference source code.

     

    ssp_err_t ENS210Open(i2c_master_instance_t * const i2c, uint8_t address)
    {
    ssp_err_t error;

    // Disable Low Power Mode
    error = ENS210SetSystemControl (i2c, address, 0x00);
    if (error != SSP_SUCCESS)
    return error;

    // Wait for sensor to be active
    uint8_t status = 0;
    TimerSleepMs (50);
    error = ENS210GetSystemStatus (i2c, address, &status);
    while ((status & 0x01) == 0)
    {
    printf (".");
    TimerSleepMs (50);
    error = ENS210GetSystemStatus (i2c, address, &status);
    if (error != SSP_SUCCESS)
    return error;
    }

    // Enable Continuous Measurements
    error = ENS210SetSensorRunMode (i2c, address, 0x03);
    if (error != SSP_SUCCESS)
    return error;

    // Start R & H Measurements
    error = ENS210SetSensorStart (i2c, address, 0x03);
    if (error != SSP_SUCCESS)
    return error;

    return SSP_SUCCESS;
    }

    ssp_err_t ENS210SetSystemControl(i2c_master_instance_t * const i2c, uint8_t address, uint8_t const systemControl)
    {
    return I2CWriteRegister (i2c, address, ENS210RegisterAddresses.SYS_CTRL, systemControl, false);
    }

     

    It appears to fail at the first line of the Open function:

    error = ENS210SetSystemControl (i2c, address, 0x00);
    if (error != SSP_SUCCESS)
    return error;

     

    Looking at the I2CWriteRegister function:

    ssp_err_t I2CWriteRegister(i2c_master_instance_t * const i2c, uint8_t slaveAddress, uint8_t registerAddress, uint8_t data, bool const restart)
    {
    uint8_t slaveData[2] = {registerAddress, data};
    // Write single byte to slave
    return I2CWrite (i2c, slaveAddress, (uint8_t * const ) slaveData, 2, restart);
    }

     

    In my I2CWrite function there is an error when it comes to setting the address of the slave device.

    ssp_err_t I2CWrite(i2c_master_instance_t * const i2c, uint8_t slaveAddress, uint8_t * const data, uint32_t const length, bool const restart)
    {
    // Set the slave address to the device we want to talk to.
    i2c->p_ctrl->info.slave = slaveAddress;

    // Write data to the slave
    return i2c->p_api->write (i2c->p_ctrl, data, length, restart);
    }

     

    I did some research and found that info.slave was used in an older version of SSP. What would be recommended way to set the slave address for 1.2.0? This is how my thread/driver is configured. Thank you.

  • In reply to zfeng:

    Hi zfeng,

    to change the slave address please try to use the .slaveAddressSet function:

    i2c->p_api->slaveAddressSet(i2c->p_ctrl, slaveAddress, I2C_ADDR_MODE_7BIT);

    Best regards,
    anper

  • In reply to anper:

    I did the change to use the new function. However, I'm still unable to run the functions for the ENS sensors.

    I've tried the Open and retrieving the part ID / Unique ID.

    I have the Main Thread running another I2C Master Driver on r_iic for the LCD. Would this cause any conflict to my sensor I2C? Each are running on different channels and have different slave address so I don't think it's an issue.

    source files located here: https://www.dropbox.com/sh/zmq7epacsf1wnaj/AAAnnN3vQkQ9n3kpzaVTA1tka?dl=0

     

    Main Thread:

     

    sensor config settings:

     

     

  • In reply to zfeng:

    Hello zfeng,

    in the screenshots I noticed that there is channel 0 set in the "g_sf_i2c_bus0 I2C Framework Shared Bus on sf_i2c" module parameters. As you wrote earlier, that you are going to use channel 2, please change this setting accordingly and verify that pins are configured correctly for the chosen SCI channel.

    In the SSP 1.2.0 User's Manual it is stated that:
    "In framework, the channel number given in this bus configuration overrides the channel number given in the HAL driver."
    (SSP 1.2.0 User's Manual > User Guides > Framework Layer > I2C Framework > Configuring the SF I2C Bus Module Parameters)

    The IIC channel 2 seems not to collide with the SCI channel 2 nor the channel 0 - they use different pins - so it should be possible to use them simultaneously.

    Please also provide here the error value returned by the particular function, which causes the application to fail. This will help to find the solution.

    EDIT:
    At the link to your source code I was able to find only the Synergy generated files.

    Best regards,
    anper

  • In reply to anper:

    Files should be visible now: https://www.dropbox.com/sh/zmq7epacsf1wnaj/AAAnnN3vQkQ9n3kpzaVTA1tka?dl=0

    You're correct. I'm using SCI2 and have changed the channel accordingly for the module "g_sf_i2c_bus0 I2C Framework Shared Bus on sf_i2c".

    These are my settings for SCI2:

     

    Should the Module temp_humidity I2C Master Driver on r_sci_i2c also be set to channel 2? I had it on channel 1 (channel 0 was giving me errors). I tested it with channel 2 and noticed the application was running for a longer period of time when executing the ENS210 Open function. Eventually it still fails after several minutes.

     

    Here are the stacks:

     

     

    Here are the return values of variables and error:

     

     

     

     

  • In reply to zfeng:

    Hello zfeng,

    thanks for providing the source files.

    The channel set in the "temp_humidity I2C Master Driver on r_sci_i2c" module should not be important, according to the SSP User's Manual. However, it may cause the "redefinition" errors, if the same SCI channel is set in another module. This probably occurred in your project, because SCI channel 0 is used by the "g_uart0 UART Driver on r_sci_uart" module. Therefore, I suggest to set the same channel in the "temp_humidity I2C Master Driver on r_sci_i2c" module as the one set in the "g_sf_i2c_bus0 I2C Framework Shared Bus on sf_i2c" module. Setting it to SCI channel 1 should also work, as this channel is currently unused in the project.

    The application seems to get stuck in the "while (false == p_ctrl->transaction_completed)" loop. I will investigate it further and come back with my feedback.

    Best regards,
    anper

  • In reply to zfeng:

    Hello zfeng,

    a few more ideas:

    • create a new, simpler project, implementing only the communication with the sensor - receiving the measurements (no GUI or other functionalities). This will make it easier to expose problems related to the sensor only.
    • try to use the "I2C Master Driver" module instead of the "I2C Framework Device"
    • try to use Rate: Fast-mode parameter in the "I2C Master Driver" module properties

    And some general tips for the project development:

    • use lower priorities for threads - although it is possible to use priority 1, usually it is not necessary
    • differentiate thread priorities according to threads importance - that way crucial threads will be able to preempt less important ones;

    The following documentation and sample code may be helpful for you:

    You will find there the sample code and the documentation, which you can use as a reference during your own code development.

    The following Renesas Synergy module guides can be helpful as well:

    Best regards,
    anper

  • In reply to anper:

    Thanks anper.

    I started a new project with BSP template to just interface the sensor. I believe I'm still running into the same issue. I used the I2C Master Driver this time.

    source files: https://www.dropbox.com/sh/cc7lqa4tqgiedl6/AABtLbzGuJtg7tESJSgk8pHBa?dl=0

     

     

     

    Would having a bad sensor hardware cause an issue with the application/sensor starting? I'm not using the PMOD AMS sensor that comes in the IoT Fast Prototype kit. I'm using the standard one sold by AMS directly and I had to play around with the connections to wire into the breakout pins of the S7G2. It's a high possibility it might have been damaged when I was soldering jumper wires to the I2C pins on the sensor. 

    But if you can find anything else in the source files for this project let me know. Much appreciated.

  • In reply to zfeng:

    Hello zfeng,

    thanks for sharing your new source files. Could you also share the rest of the project files, such as configuration.xml and *.pincfg?

    The best way to share a project is to export it from e2 Studio. To do that, please select its name in the Project Explorer window and proceed with the following:

    • menu File > Export > General > Renesas Synergy Archive File >
      • deselect .module_descriptions and Debug directories
      • press Finish

    To view a specified variable value during runtime it is convenient to use the Expressions window instead of the Variables window. To prevent a variable from being "optimized out", please select the project name in the Project Explorer window and set:
    menu Project > Properties > C/C++ Build > Settings > Tool Settings tab > Optimization > Optimization level: None (-O0).

    Best regards,
    anper

  • In reply to anper:

    Not sure how I miss those files the first time, here's the archive file:

    https://www.dropbox.com/s/a4w40fg7c62fc5s/ams_sensor_i2c_master_driver_archive.zip?dl=0

     

    These are the error values before getting the fail.

    hal_entry():

     

    ENS210Open():

     

    The operation aborts after some time :

     

  • In reply to zfeng:

    Some things you might want to do:
    1) change the SCL (on Port 3 Pin 1 to CMOS) Also, change the drive for both SDA and SCL to Medium.
    2) add a callback routine for the SCI_I2C.
    3) you will need a global bool flag for this. As an example the call back could be.

    void g_sensor_bus_callback(i2c_callback_args_t * p_args)
    {
    if (p_args->event)
    {
    /*
    I2C_EVENT_ABORTED = 1, A transfer was aborted
    I2C_EVENT_RX_COMPLETE = 2, A receive operation was completed successfully
    I2C_EVENT_TX_COMPLETE = 3 A transmit operation was completed successfully
    */
    g_Sensor_Bus_Done = true;
    }
    }

    Using an example of your code you would have something like:

    g_Sensor_Bus_Done = false;
    error = ENS210SetSystemControl (i2c, address, 0x00);
    while(!g_Sensor_Bus_Done);
    if (error != SSP_SUCCESS)
    return error;

    (regards Mike)
  • In reply to zfeng:

    Hello zfeng,

    thanks for uploading the exported project. I analysed the application behaviour during the runtime. I did not connect any device to P301 and P302 pins. I got the same result as you did - after running for a few seconds the sci_siic_run_hw_master function returns SSP_ERR_ABORTED.

    Please check the hardware connections between the SK-S7G2 and the sensor. Please also verify the sensor functioning by connecting it to a PC using the USB dongle.

    Best regards,
    anper