Avatar for fanoush


Member since Jul 2018 • Last active Nov 2018
  • 0 conversations

Most recent activity

  • in Projects
    Avatar for fanoush

    How complicated is to add support for two NRF52 I2C buses? Looks like this watch uses one for accelerometer and second one for HR sensor.It uses TWI0, TWI1 and SPI2 (for OLED). TWI0 uses scl 7 sda 8.

  • in Projects
    Avatar for fanoush

    I don't think I2C2 is supported on Espruino since you can't have two SPI and two I2C.

    oh, I see, I was confused by the board file having

      'spi' : 3,
      'i2c' : 2,
      'adc' : 1,

    and I2C2 being defined. But since there are 3 SPIs too and the i2c/spi resources are shared it clearly cannot work for all five at the same time even if those objects are all defined in the interpreter, however I did not use SPI yet so in theory both i2c interfaces should be free to use.

    Thanks for pointing the inverting code (would not have guessed it is done later at runtime), also will try with 'make clean', thanks.
    EDIT: oh, checked the file you linked and the answer to SPI/I2c is there too
    so currently just one SPI and one I2c. So perhaps the board file should reflect that if those numbers have any efffect on generating those SPIx and I2Cx objects at runtime.
    EDIT2: and indeed they have, I have reduced i2c and spi to 1 and jswrapper.c no longer has those not supported ones generated.

  • in Projects
    Avatar for fanoush

    Honestly, not sure why it's doing that

    As for i2c for some reason it did not work with I2C2. It did work however with I2C1. So I2C2.setup({scl:13, sda:14, bitrate:400000}) did nothing, I did also break into debugger after that and HW registers were still at default values for both TWI ports. I2C1.setup({scl:13, sda:14, bitrate:400000}) however did work and when using I2C1 for scannig the bus I got exceptions except 0x1F address which was expected. There should be KX022 accelometer. BTW is there some Espruino module for this one? I see it was mentioned in this thread but I don't see it here https://github.com/espruino/EspruinoDocs­/tree/master/devices

    but why not just look at the PCB (or even the manufacturer's docs) to try and find out what the I2C parts are then try and look at those addresses?

    Because I wanted to test i2c functionality - scanning the bus looks like good test.

    As for the negated button - it doesn't work. It is still as before - returning false when pressed and true otherwise and BTN1 gives

      port: "D", 
      num: 30, channel: 6, 
      functions: {  }

    so the line

      pinutils.findpin(pins, "PD30", True)["functions"]["NEGATED"]=0;

    seems to have no effect. I did find it used in boards/NRF52832DK.py in same way.

    gen/platform_config.h has

    [#define](http://forum.espruino.com/sear­ch/?q=%23define) BTN1_PININDEX 30/* D30 */
    [#define](http://forum.espruino.com/sear­ch/?q=%23define) BTN1_ONSTATE 1
    [#define](http://forum.espruino.com/sear­ch/?q=%23define) BTN1_PINSTATE JSHPINSTATE_GPIO_IN_PULLDOWN

    oh, there is scripts/build_pininfo.py which is using NEGATED and then there is build_platform_config.py which tests for "inverted". And no code to automagicaly negate pulldown to pullup.

    however gen/jspininfo.c contains


    so the 'NEGATED" works after all? but it still returned true when not pressed

  • in Projects
    Avatar for fanoush

    Did you try it?

    Not yet, I better asked.

    It's pull down because it's also inverted. Check some of the other .py files in the boards directory.

    Yes, I've seen it some board files, just was not sure. I was thinking inverted means the bit is just flipped in software before returning it back to js code while the pinstate should set pull up/down right in the HW registers. OK thanks for explanation, will try.

  • in Projects
    Avatar for fanoush

    It's not that useful on nRF52 as I2C/SPI/Serial can be on any bit

    Yes it can be on any pin but in this watch it is on specific pins so if it would set some predefined values out of box so one could just use it without setup in code it would make some sense.

    'BTN1' : { 'pin' : 'D30', 'pinstate' : 'IN_PULLDOWN' },

    Is it pull up or down? Since when the button is not touched the value is high and goes low when touched shouldn't this be pull up? or is there just 'INPUT' with no pull as it is always connected and not left floating

  • in Projects
    Avatar for fanoush

    looks like scl:13 or/and sda:14 is not used for I2C on this device.

    could be some mistake on my part, will double check but this is what I got from register dump when running the firmware and stopping it in gdb over swd https://github.com/fanoush/ds-d6/wiki/Ha­rdware

    0x40004500: 0x00000005
    0x40004508: 0x0000000d
    0x4000450c: 0x0000000e
    0x40004524: 0x06680000

    which I guessed is TWI1 with scl 13 sda 14 speed 400kbps
    as per https://infocenter.nordicsemi.com/index.­jsp?topic=%2Fcom.nordic.infocenter.nrf52­832.ps.v1.1%2Ftwi.html&cp=2_1_0_48_7_5&a­nchor=register.PSELSCL

    Check i2cdetect for a simple scanner

    Thanks a lot, this is what I was looking for :-)

  • in Projects
    Avatar for fanoush

    Thanks guys.

    I figured out the touch button - pin30 reversed (low when pressed) and charging/power status. Those were the easy ones. I put my current board diff here https://github.com/fanoush/ds-d6/wiki/Es­pruino I an confused about the pinutils.findpin section, what it is need for? What are correct names for pins and interfaces there? Pins are not Dxx but PDxx and names like UART or USART look random across different boards.

    Also how do I tell that the DFU bootloader should use negated touch button on pin 30?

    I also tried to scan I2C but basically any address returns some data. I used I2C2.setup({scl:13, sda:14, bitrate:400000}) and when using I2C2.readFrom(address, 1) with random adresses it always returns something - mostly array with [232] value. What am I doing wrong? How to scan i2c for devices in espruino?

  • in Projects
    Avatar for fanoush

    Yes, I never used SWD debugging before. Just recently I discovered that blackmagic probe firmware is available for bluepill - $1.67 STM32 board I had in drawer, so this was first time I used it. It is cool to stop existing firmware in any point and see HW registers. I did it both in DFU bootloader (serial enabled, i2c not) and app (serial not enabled but i2c yes) and with display on and off, charging/not charging - one can find a lot of basic stuff with that :-) I saw in datasheet section about the MWU — Memory watch unit. I wonder if it could be used to trace writes to peripherials at runtime with stock firmware still running?

    Also I wonder how long the battery will last with espruino flashed and bt enabled (and console on serial). It did last over night but I don't see how much battery is left.

  • in Projects
    Avatar for fanoush

    Just to let you know that I rebuilt Espruino from source, started from MDBT42Q board but removed LEDs etc and changed usart pins, flashed the result from gdb and now I have Espruino with serial console on usb data pins for further exploring :-) Also bluetooth works of course, console was default on bluetooth so I had to do Serial1.setConsole(false) over BLE connection first.

    I figured out the pins first by dumping hw registers for USART,TWI,SPI in gdb, currently I know there is TWI2 scl 13 sda 14 ,SPI2 master sck 5 mosi 6 miso -1 (display?) and UART rx 22, tx 23. Time to go to sleep.

    Anyway, I like that the USB data pins are connected, so one has two gpios or console without taking it apart. Not bad for $8 watch :-)

  • in Projects
    Avatar for fanoush

    Yes, you're right. I already tried and mostly failed. Updating soft device to 2.0.1 worked fine and original app works with such minor upgrade. However my app flashed to 0x1c000 linked to soft device 2.0.1 does not start, it reboots to DFU/bootloder. Later I found this https://infocenter.nordicsemi.com/index.­jsp?topic=%2Fcom.nordic.infocenter.sdk51­.v10.0.0%2Fexamples_ble_dfu.html "Note that if you program a DFU bootloader on the device, you must use this bootloader to install the application. Programming the application with other tools will not update the bootloader settings, which means that the application might not start. Erase the device if you do not want to use the DFU bootloader anymore." so it looks indeed tricky.

    However I already tried to restore from backup and it works (except maybe UICR area, will try that one too) so I am now confident enough to clear everything. So I'll try newer easier stuff first.

    Still, to allow updating current watch firmware over bluetooth, I should figure out how the update with existing bootloader and soft device works. I don't want to open second watch. Hopefully with such old soft device the DFU update procedure is not signed.

    And btw it is currently $8 watch at gearbest :-)