Git Product home page Git Product logo

i2c's People

Contributors

cmumford avatar cpq avatar dimonomid avatar mac-michael avatar pimvanpelt avatar rojer avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

i2c's Issues

Misleading trace in mgos_i2c_send_byte does not help debugging I2C interface code

The log generated by mgos_i2c_send_byte incorrectly states that the byte sent is 0x00 at this line:

(" sent 0x%02x, recd %s", data, (ret_val == I2C_ACK ? "ACK" : "NAK")));

This is because the variable data has been modified by the previous for loop which does data<<=1. A better for loop which does not destroy the content of data is:

  for (i=0x80; i!=0; i>>=1) {
    bit = (data & i) ? 1 : 0;
    ...

A better name for i is probably mask with this new loop.

Add i2ctransfer(1) functionality

I'm interested in extending mgos_i2c.h with a string based i2ctransfer API. It looks like this:

 {r|w}<length_of_message>[@address]

       {r|w}  specifies if the message is read or write

       <length_of_message>
              specifies  the number of bytes read or written in this message.  It is parsed as an unsigned 16 bit integer, but note that the Linux Kernel applies an addi‐
              tional upper limit (8192 as of v4.10).

       [@address]
              specifies the 7-bit address of the chip to be accessed for this message, and is an integer.  If omitted, reuse the previous  address.   Normally,  addresses
              outside  the  range  of 0x03-0x77 and addresses with a kernel driver attached to them will be blocked.  With -f (force), all addresses can be used.  Be very
              careful when using that!  10-bit addresses are currently not supported at all.

       If the I2C message is a write, then a data block with the data to be written follows.  It consists of <length_of_message> bytes which can be marked with the  usual
       prefixes for hexadecimal, octal, etc.  To make it easier to create larger data blocks easily, the data byte can have a suffix.

       =      keep value constant until end of message (i.e. 0= means 0, 0, 0, ...)

       +      increase value by 1 until end of message (i.e. 0+ means 0, 1, 2, ...)

       -      decrease value by 1 until end of message (i.e. 0xff- means 0xff, 0xfe, 0xfd, ...)

       p      use value as seed for an 8 bit pseudo random sequence (i.e. 0p means 0x00, 0x50, 0xb0, ...)

Proposed:
bool mgos_i2c_transfer(struct mgos_i2c *i2c, const char *msg, uint8_t *read_buf);

The caller can compute the read_buf size at call time, as the author will know how many bytes will be requested in total.

Examples:
r1@0x01 -- read one byte from address 0x01
w1@0x11 0x32 r8 -- write 0x32 to address 0x11 and then read 8 bytes from 0x11

Advanced example:
w1@0x01 0x22 w1@0x11 0x32 r8@0x11 w1@0x11 0x32 r8 w17@0x22 0x42 0xff- w7@0x33 0x52 0x10+ w4@0x44 0x62 0p w9@0x55 0x72 0=" which does a whole lot of reads/writes to multiple device addresses.

I find interacting with I2C devices in this manner very useful, and I have a working prototype with tests. If there's an interest, simply let me know and I'll send a PR.

Small typo in mos.yml

It says SPI instead I2C: description: Implements SPI API on Mongoose OS. Is this correct?

I2C ESP32 can not send STOP signal

Hi all,

I create an example of CAP1106 touch IC with ESP32 on Mongoose OS. My Repo

My example now just reads 3 1byte registers from CAP1106. Link
but after the first read, the STOP signal can't send to bus.

Bus capture: https://drive.google.com/open?id=1P41dAlcQUE6ytt75Hbb5c9wzOq1Xx9YR
Here are log:

[Nov 19 16:13:10.663] s_cap1106_init       I2C master created 0x3ffc13cc
[Nov 19 16:13:10.667] mgos_i2c_write       write 1 to 40, start? 1 stop? 0
[Nov 19 16:13:10.672] mgos_i2c_write        0 sent 0xff
[Nov 19 16:13:10.682] esp32_i2c_exec         179 loops, ok? 1, ints 0x00000002 -> 0x0000024a, tx_fifo 0/0 rx_fifo 0/-1, status 0x36000000
[Nov 19 16:13:10.691] mgos_i2c_read        read 1 from 40, start? 1, stop? 1
[Nov 19 16:13:10.701] esp32_i2c_exec         225 loops, ok? 1, ints 0x00000242 -> 0x0000024a, tx_fifo 0/-1 rx_fifo 1/1, status 0x35000100
[Nov 19 16:13:10.712] mgos_i2c_read         0 recd 0x81
[Nov 19 16:13:10.712] mgos_i2c_stop        stop
[Nov 19 16:13:10.721] esp32_i2c_exec         573 loops, ok? 0, ints 0x00000242 -> 0x00000342, tx_fifo 0/-1 rx_fifo 0/-1, status 0x65000010
[Nov 19 16:13:10.732] esp32_i2c_exec           00001800 3
[Nov 19 16:13:10.733] s_cap1106_init       Revision: 0x81
[Nov 19 16:13:10.739] mgos_i2c_write       write 1 to 40, start? 1 stop? 0
[Nov 19 16:13:10.743] mgos_i2c_write        0 sent 0xfd
[Nov 19 16:13:10.753] esp32_i2c_exec         324 loops, ok? 0, ints 0x00000242 -> 0x00000342, tx_fifo 2/0 rx_fifo 0/-1, status 0x65080010
[Nov 19 16:13:10.768] esp32_i2c_exec           00000000 0
[Nov 19 16:13:10.769] esp32_i2c_exec           00000901 1
[Nov 19 16:13:10.771] esp32_i2c_exec           00000901 1
[Nov 19 16:13:10.776] esp32_i2c_exec           00002000 4
[Nov 19 16:13:10.777] s_cap1106_init       I2C read product id failed, err -1
[Nov 19 16:13:10.785] mgos_i2c_write       write 1 to 40, start? 1 stop? 0
[Nov 19 16:13:10.790] mgos_i2c_write        0 sent 0xfe
[Nov 19 16:13:10.800] esp32_i2c_exec         150 loops, ok? 0, ints 0x00000242 -> 0x00000342, tx_fifo 2/0 rx_fifo 0/-1, status 0x65080010
[Nov 19 16:13:10.814] esp32_i2c_exec           00000000 0
[Nov 19 16:13:10.816] esp32_i2c_exec           00000901 1
[Nov 19 16:13:10.816] esp32_i2c_exec           00000901 1
[Nov 19 16:13:10.819] esp32_i2c_exec           00002000 4
[Nov 19 16:13:10.824] s_cap1106_init       I2C read manufacturer id failed, err -1

Is it a issue or am I doing wrong? Thank you.

Using global and mgos_i2c_create causes read/write failures.

Hello,

It appears there is some type of issue/bug with the creating of an i2c bus maually and also using the i2c bus from the get global.
This was working fine back in firmware version 2.7, however when we upgraded to 2.12.1 we ran into the issue.

How I we were using the i2c buses.
We do some initialization code on the global i2c bus, then initialize the secondary i2c. All of this happens without errors. Then when we try to read/write to the global i2c, the read/writes return false.

Removing the secondary manual create resolves the problem (as a debugging measure), and then reading/writing to the global i2c works as expected.
I notice that an i2c1 was added to the config, so switching to using this, instead of manually creating the i2c also resolves the problem.

I traced the issue down to within the mgos_i2c_exec function. The ints (dev->int_raw.val) variable was 1600, during the read/writes that failed. This line

ok = (ints & I2C_DONE_INTS) && !(ints & I2C_ERROR_INTS);
is as far as I traced down the "issue".

-siftd106

error: Array 's_buses[1]' accessed at index 2, which is out of bounds.

I just ran static analysis by cppcheck and it found this in i2c master code:

$ cppcheck i2c/
Checking i2c/src/cc32xx/cc32xx_i2c_master.c ...
Checking i2c/src/cc32xx/cc32xx_i2c_master.c: CC3200_I2C_DEBUG...
1/5 files checked 19% done
Checking i2c/src/esp32/esp32_i2c_master.c ...
2/5 files checked 53% done
Checking i2c/src/gpio/mgos_i2c_gpio_master.c ...
3/5 files checked 72% done
Checking i2c/src/mgos_i2c_master.c ...
Checking i2c/src/mgos_i2c_master.c: MGOS_SYS_CONFIG_HAVE_I2C1...
Checking i2c/src/mgos_i2c_master.c: MGOS_SYS_CONFIG_HAVE_I2C1;MGOS_SYS_CONFIG_HAVE_I2C2...
Checking i2c/src/mgos_i2c_master.c: MGOS_SYS_CONFIG_HAVE_I2C2...
i2c/src/mgos_i2c_master.c:95:12: error: Array 's_buses[1]' accessed at index 2, which is out of bounds. [arrayIndexOutOfBounds]
    s_buses[2] = mgos_i2c_create(mgos_sys_config_get_i2c2());
           ^
i2c/src/mgos_i2c_master.c:96:16: error: Array 's_buses[1]' accessed at index 2, which is out of bounds. [arrayIndexOutOfBounds]
    if (s_buses[2] == NULL) return false;
               ^
4/5 files checked 88% done
Checking i2c/src/ubuntu/ubuntu_i2c_master.c ...
5/5 files checked 100% done

The MPU-6050 is not detected (ESP8266 + GY521 sensor)

The MPU-6050 is not detected using an ESP8266.

Hardware

  • WeMos D1 mini board (ESP8266)
  • GY521 sensor (MPU-6050)

Connections details

GY-521 pin WeMos board pin
VCC 3V3
GND GND
SCL D1 (GPIO 5)
SDA D2 (GPIO 4)
AD0 3V3

The mos.yaml

author:
description:
version: 1.0
manifest_version: 2017-05-18
libs_version: ${mos.version}
modules_version: ${mos.version}
mongoose_os_version: ${mos.version}

config_schema:
  - ["i2c.enable", true]
  - ["i2c.sda_gpio", 4]
  - ["i2c.scl_gpio", 5]

sources:
  - src
filesystem:
  - fs

libs:
  - origin: https://github.com/mongoose-os-libs/boards
  - origin: https://github.com/mongoose-os-libs/i2c

The main.c

#include "mgos.h"
#include "mgos_i2c.h"

enum mgos_app_init_result mgos_app_init(void) {
  LOG(LL_INFO, ("Scanning I2C bus for devices"));
  struct mgos_i2c *conn = mgos_i2c_get_global();
  for (int i = 0; i < 0x78; i++) {
    if (mgos_i2c_write(conn, i, NULL, 0, true)) {
      LOG(LL_INFO, ("Found device at I2C address 0x%02x", i));
    }
  }
  return MGOS_APP_INIT_SUCCESS;
}

The output

...
[May  5 16:09:54.515] mgos_i2c_gpio_maste:250 I2C GPIO init ok (SDA: 4, SCL: 5, freq: 100000)
...
[May  5 16:09:55.718] main.c:5               Scanning I2C bus for devices
[May  5 16:10:00.718] main.c:5               Scanning I2C bus for devices
[May  5 16:10:05.719] main.c:5               Scanning I2C bus for devices
...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.