You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mynewt.apache.org by Łukasz Wolnik <lu...@gmail.com> on 2017/04/09 13:57:10 UTC

I2C not working on nrf52xxx's rb-nano2

Hello,

I cannot get I2C working on my RedBear BLE Nano 2 board. I connected an
accelerometer (LIS3DH) but according to gdb the hal_i2c_master_write/read
functions just time out.

RedBear BLE Nano 2 pins layout:

https://www.kickstarter.com/projects/redbearinc/bluetooth-5-ready-ble-module-nano-2-and-blend-2#h:nano-2


Because rb-nano2's bsp is not configured to support I2C below is what I
added to mynewt-core:

https://github.com/limal/incubator-mynewt-core/commit/353fcb10368811a7bbe3e2b10f019fb44dc121f7


To rule out a possibility that UART_0 is interfering with I2C, that share
the same pins on rb-nano2, I disabled it and send any logging information
via Bluetooth to another nano-2 board. Unfortunately the I2C is still
timing out.

9100:[ts=71093744ssb, mod=4 level=1] GAP procedure initiated: advertise;
disc_mode=2 adv_channel_map=0 own_addr_type=0 adv_filter_policy=0
adv_itvl_min=50 adv_itvl_max=75 adv_data_len=0
9817:[ts=76695268ssb, mod=64 level=1] connection established; status=0
handle=1 our_ota_addr_type=0 our_ota_addr=91:0a:c0:ff:42:57
our_id_addr_type=0 our_id_addr=91:0a:c0:ff:42:57 peer_ota_addr_type=0
peer_ota_addr=0f:0f:0a:0a:0a:0a peer_id_addr_type=0
peer_id_addr=0f:0f:0a:0a:0a:0a conn_itvl=40 conn_latency=0
supervision_timeout=256 encrypted=0 authenticated=0 bonded=0
9827:[ts=76773388ssb, mod=64 level=1]
9828:[ts=76781200ssb, mod=64 level=1] (0): open
10188:[ts=79593712ssb, mod=64 level=1] (0): read_check: 1111
10190:[ts=79609336ssb, mod=64 level=1] (0): hal_write_rc: -1 <-------------
10192:[ts=79624960ssb, mod=64 level=1] (0): hal_read_rc: -11 <-------------
10829:[ts=84601524ssb, mod=64 level=1] (0): read_check: 1111
10830:[ts=84609336ssb, mod=64 level=1] (0): hal_write_rc: -1 <-------------
11469:[ts=89601524ssb, mod=64 level=1] (0): read_check: 1111
12109:[ts=94601524ssb, mod=64 level=1] (0): read_check: 1111
12749:[ts=99601524ssb, mod=64 level=1] (0): read_check: 1111


I have tried adding 10k resistors to pull up SDA/SCL lines but to no avail.
And finally I have also connected the accelerometer to Arduino Uno to
confirm it's working (I posted Arduino code here:
http://discuss.redbear.cc/t/i2c-not-working-on-nano2-in-arduino-and-apache-mynewt/2106
).


I'm very satisfied with mynewt but being unable to use I2C renders the
whole project unusable.

I'd appreciate any help to sort it out and get I2C to work on rb-nano2.

Kind regards,
Lukasz

Re: I2C not working on nrf52xxx's rb-nano2

Posted by Łukasz Wolnik <lu...@gmail.com>.
Szymon, thanks! That sounds really promising. Looking forward to it. Not
sure if RTT is going to work with my OpenOCD/CMSIS-DAP debugger but for now
I can use gdb when UART is disabled.

Will, I think I managed to pinpoint the place where my app fails once the
UART_0 is disabled.

Below is my app's syscfg.yml:

syscfg.vals:
    # Setup PINs
    UART_0: 0
    I2C_0: 1

    # DEBUG logging is a bit noisy; use INFO.
    LOG_LEVEL: 255

    # Default task settings
    OS_MAIN_STACK_SIZE: 336

    # BLE settings
    BLE_MAX_CONNECTIONS: 4

    # Hardware-accelerated float arithmetics
    HARDFLOAT: 0

    # Log reboot messages to a flash circular buffer.
    REBOOT_LOG_FCB: 0
    LOG_FCB: 0
    CONFIG_FCB: 0

    # Enable newtmgr commands.
    STATS_NEWTMGR: 0
    LOG_NEWTMGR: 0

    # Enable Config.
    CONFIG_NEWTMGR: 0


And then there's the code that tried to use uart_blocking_tx, below is my
gdb session's log:

Breakpoint 2, hal_bsp_init () at
repos/apache-mynewt-core/hw/bsp/rb-nano2/src/hal_bsp.c:184
184    assert(rc == 0);
(gdb) p rc
$4 = 0
(gdb) c
Continuing.
Error: nrf52.cpu -- clearing lockup after double fault
nrf52.cpu -- clearing lockup after double fault
Polling target nrf52.cpu failed, trying to reexamine
Info : nrf52.cpu: hardware has 6 breakpoints, 4 watchpoints

Program received signal SIGINT, Interrupt.
0x00001bdc in ?? ()
(gdb) bt
#0  0x00001bdc in ?? ()
#1  0x0001cb56 in uart_blocking_tx (byte=<optimized out>, dev=<optimized
out>) at repos/apache-mynewt-core/hw/drivers/uart/include/uart/uart.h:140
#2  console_blocking_tx (ch=<optimized out>) at
repos/apache-mynewt-core/sys/console/full/src/cons_tty.c:226
#3  0x0001ce0a in console_file_write (arg=<optimized out>, str=0x2000ff07
"0", cnt=1)
    at repos/apache-mynewt-core/sys/console/full/src/cons_tty.c:286
#4  0x0000ad3a in fwrite (stream=0x243dc <console_file>, nmemb=1, size=1,
buf=0x2000ff07)
    at repos/apache-mynewt-core/libc/baselibc/include/stdio.h:59
#5  fputc (f=0x243dc <console_file>, c=<optimized out>) at
repos/apache-mynewt-core/libc/baselibc/include/stdio.h:75
#6  putf (putp=putp@entry=0x243dc <console_file>, c=<optimized out>) at
repos/apache-mynewt-core/libc/baselibc/src/tinyprintf.c:135
#7  0x0000ae68 in putchw (putp=putp@entry=0x243dc <console_file>, p=p@entry
=0x2000ff48)
    at repos/apache-mynewt-core/libc/baselibc/src/tinyprintf.c:185
#8  0x0000b036 in tfp_format (putp=putp@entry=0x243dc <console_file>,
fmt=0x243e3 ":", fmt@entry=0xd "\001", va=...)
    at repos/apache-mynewt-core/libc/baselibc/src/tinyprintf.c:286
#9  0x0000b186 in vfprintf (va=..., fmt=0xd "\001", f=0x243dc
<console_file>) at
repos/apache-mynewt-core/libc/baselibc/src/tinyprintf.c:338
#10 fprintf (f=f@entry=0x243dc <console_file>, fmt=0x243e0 "%lu:") at
repos/apache-mynewt-core/libc/baselibc/src/tinyprintf.c:345
#11 0x0001cb10 in console_printf (fmt=0x23cd8 "Unhandled interrupt (%ld),
exception sp 0x%08lx\n")
    at repos/apache-mynewt-core/sys/console/full/src/cons_fmt.c:48
#12 0x00008ee6 in os_default_irq (tf=0x2000ffc0) at
repos/apache-mynewt-core/kernel/os/src/arch/cortex_m4/os_fault.c:152
#13 0x0000a9f2 in os_default_irq_asm () at
repos/apache-mynewt-core/kernel/os/src/arch/cortex_m4/m4/HAL_CM4.s:223
#14 <signal handler called>
#15 0x00000000 in ?? ()
#16 0x000082ca in SystemInit () at
repos/apache-mynewt-core/hw/mcu/nordic/nrf52xxx/src/system_nrf52.c:312
#17 0x00000000 in ?? ()
(gdb) c <--- from this point on my app won't recover
Continuing.
Error: nrf52.cpu -- clearing lockup after double fault
nrf52.cpu -- clearing lockup after double fault
Polling target nrf52.cpu failed, trying to reexamine
Info : nrf52.cpu: hardware has 6 breakpoints, 4 watchpoints

Program received signal SIGINT, Interrupt.
0x00001bdc in ?? ()
(gdb)


Unfortunately I don't know what caused the original interrupt that
triggered dumping data to the console.


On Mon, Apr 10, 2017 at 3:41 PM, will sanfilippo <wi...@runtime.io> wrote:

> Just an FYI: I was playing around with some code for something I was
> working on and I was able to disable UART0 although I did not try to
> re-purpose the pins. The UART was certainly not enabled did not attempt to
> grab the gpio. This was using the nrf52dk bsp though.
>
> Anyway, I think it worth a bit of effort to try and figure out exactly
> what happened in your case Lukasz.
>
> > On Apr 10, 2017, at 1:04 AM, Szymon Janc <sz...@codecoup.pl>
> wrote:
> >
> > Hi,
> >
> > On Sunday, 9 April 2017 21:47:26 CEST Łukasz Wolnik wrote:
> >
> > <snip>
> >
> >> Later I found out that my pull-up resistors were actually 100 Ohms
> instead
> >> of 10k. So actually above change to the drive wasn't necessary (it
> should
> >> stay as GPIO_PIN_CNF_DRIVE_S0D1) but I have to say that fixing hardware
> >> issues using software feels good. Besides RedBear Nano2 has it's own
> >> pull-ups so no resistors are required in the first place.
> >>
> >> And just for completeness, I have tried different setups to share the
> lines
> >> with UART_0 (pins 2, 28, 29 and 30) but none of them worked. So my
> previous
> >> try with the Bluetooth serial logging must have been sabotaged by the
> 100
> >> Ohm pull-up resistors. I have a feeling that it's not so easy to disable
> >> UART_0 completely so your advice to change SPI0_CONFIG_SCK_PIN pin might
> >> have been necessary as well. Luckily there's no need to checking it.
> >
> > Just a heads up, but Michał was working on adding RTT console support for
> > Mynewt and with those patches it should be possible to disable UART_0
> ie. we
> > are able to use console over RTT while using UART for HCI monitoring
> (other
> > feature we are working on). Currently this is pending review and PR
> should be
> > updated in upcoming days.
> >
> > Code is available at
> > https://github.com/michal-narajowski/incubator-mynewt-core/tree/bletiny2
> >
> > --
> > pozdrawiam
> > Szymon Janc
>
>

Re: I2C not working on nrf52xxx's rb-nano2

Posted by will sanfilippo <wi...@runtime.io>.
Just an FYI: I was playing around with some code for something I was working on and I was able to disable UART0 although I did not try to re-purpose the pins. The UART was certainly not enabled did not attempt to grab the gpio. This was using the nrf52dk bsp though.

Anyway, I think it worth a bit of effort to try and figure out exactly what happened in your case Lukasz.

> On Apr 10, 2017, at 1:04 AM, Szymon Janc <sz...@codecoup.pl> wrote:
> 
> Hi,
> 
> On Sunday, 9 April 2017 21:47:26 CEST Łukasz Wolnik wrote:
> 
> <snip>
> 
>> Later I found out that my pull-up resistors were actually 100 Ohms instead
>> of 10k. So actually above change to the drive wasn't necessary (it should
>> stay as GPIO_PIN_CNF_DRIVE_S0D1) but I have to say that fixing hardware
>> issues using software feels good. Besides RedBear Nano2 has it's own
>> pull-ups so no resistors are required in the first place.
>> 
>> And just for completeness, I have tried different setups to share the lines
>> with UART_0 (pins 2, 28, 29 and 30) but none of them worked. So my previous
>> try with the Bluetooth serial logging must have been sabotaged by the 100
>> Ohm pull-up resistors. I have a feeling that it's not so easy to disable
>> UART_0 completely so your advice to change SPI0_CONFIG_SCK_PIN pin might
>> have been necessary as well. Luckily there's no need to checking it.
> 
> Just a heads up, but Michał was working on adding RTT console support for 
> Mynewt and with those patches it should be possible to disable UART_0 ie. we 
> are able to use console over RTT while using UART for HCI monitoring (other 
> feature we are working on). Currently this is pending review and PR should be 
> updated in upcoming days.
> 
> Code is available at
> https://github.com/michal-narajowski/incubator-mynewt-core/tree/bletiny2
> 
> -- 
> pozdrawiam
> Szymon Janc


Re: I2C not working on nrf52xxx's rb-nano2

Posted by Szymon Janc <sz...@codecoup.pl>.
Hi,

On Sunday, 9 April 2017 21:47:26 CEST Łukasz Wolnik wrote:

<snip>

> Later I found out that my pull-up resistors were actually 100 Ohms instead
> of 10k. So actually above change to the drive wasn't necessary (it should
> stay as GPIO_PIN_CNF_DRIVE_S0D1) but I have to say that fixing hardware
> issues using software feels good. Besides RedBear Nano2 has it's own
> pull-ups so no resistors are required in the first place.
> 
> And just for completeness, I have tried different setups to share the lines
> with UART_0 (pins 2, 28, 29 and 30) but none of them worked. So my previous
> try with the Bluetooth serial logging must have been sabotaged by the 100
> Ohm pull-up resistors. I have a feeling that it's not so easy to disable
> UART_0 completely so your advice to change SPI0_CONFIG_SCK_PIN pin might
> have been necessary as well. Luckily there's no need to checking it.

Just a heads up, but Michał was working on adding RTT console support for 
Mynewt and with those patches it should be possible to disable UART_0 ie. we 
are able to use console over RTT while using UART for HCI monitoring (other 
feature we are working on). Currently this is pending review and PR should be 
updated in upcoming days.

Code is available at
https://github.com/michal-narajowski/incubator-mynewt-core/tree/bletiny2

-- 
pozdrawiam
Szymon Janc

Re: I2C not working on nrf52xxx's rb-nano2

Posted by will sanfilippo <wi...@runtime.io>.
I was going to mention drive strength but I had never had to do that in the past. Glad it worked! But with I2C it might help in some cases.

It is also a bit of a bummer that disabling UART_0 was not that easy or did not do the trick; we will look into this a bit more to see what the issue is.

Will
> On Apr 9, 2017, at 12:47 PM, Łukasz Wolnik <lu...@gmail.com> wrote:
> 
> Will, thank you very much for a handful of tips. Thanks to you I made it
> work!
> 
> It turned out that all I had to do was to change I2C's SDA/SCL pins to
> unallocated ones.
> 
> 
> But at first changing the pins didn't work. I had found a similar issue [1]
> on GitHub that resolved it by driving a higher current to SDA/SCL lines:
> 
> https://github.com/limal/incubator-mynewt-core/commit/3510504c5cccde7de54086672cde15f945b79a3e
> 
> And changing the settings to GPIO_PIN_CNF_DRIVE_H0D1 did the work [2]. My
> output was now the correct 0x33 value identifier of the accelerometer.
> 
> 2:[ts=15624ssb, mod=64 level=1] hal_i2c_master_write rc: 0
> 3:[ts=23436ssb, mod=64 level=1] readCheck: 51 rc: 0
> 
> 
> 
> Later I found out that my pull-up resistors were actually 100 Ohms instead
> of 10k. So actually above change to the drive wasn't necessary (it should
> stay as GPIO_PIN_CNF_DRIVE_S0D1) but I have to say that fixing hardware
> issues using software feels good. Besides RedBear Nano2 has it's own
> pull-ups so no resistors are required in the first place.
> 
> And just for completeness, I have tried different setups to share the lines
> with UART_0 (pins 2, 28, 29 and 30) but none of them worked. So my previous
> try with the Bluetooth serial logging must have been sabotaged by the 100
> Ohm pull-up resistors. I have a feeling that it's not so easy to disable
> UART_0 completely so your advice to change SPI0_CONFIG_SCK_PIN pin might
> have been necessary as well. Luckily there's no need to checking it.
> 
> Thanks again,
> Lukasz
> 
> [1]
> https://github.com/RedBearLab/nRF51822-Arduino/issues/38#issuecomment-186752735
> [2]
> https://github.com/limal/incubator-mynewt-core/commit/3510504c5cccde7de54086672cde15f945b79a3e
> 
> On Sun, Apr 9, 2017 at 5:30 PM, will sanfilippo <wi...@runtime.io> wrote:
> 
>> Just an FYI:
>> 
>> The timeout value is in units of “os ticks”. If you want a timeout of 1
>> second you would use OS_TICKS_PER_SEC. A timeout of 5 seconds would be 5 *
>> OS_TICKS_PER_SEC and a timeout of 100 msecs would be OS_TICKS_PER_SEC / 10.
>> 
>> For example: hal_i2c_master_write(0, &pwrite, OS_TICKS_PER_SEC, 1);
>> 
>> I am not trying to say that is why it is failing btw; just wanted to point
>> it out as the documentation may not be completely clear.
>> 
>> I know you disabled the UART, but something interesting to try might be to
>> use a completely different set of GPIO just in case. It also might be
>> interesting to change the pkg.yml file in the nano2 directory such that the
>> SPI0_CONFIG_SCK_PIN pin does not use pin 2. I doubt that is it but worth a
>> try as well.
>> 
>> Unfortunately I do not have a device handy to take a look at this but we
>> should be able to figure this out pretty quickly.
>> 
>> Looks like what you did in the code to enable things should work. I
>> presume that you stepped through the code and that indeed hal_i2c_init()
>> was being called and that it was returning 0.
>> 
>> 
>>> On Apr 9, 2017, at 7:02 AM, Łukasz Wolnik <lu...@gmail.com>
>> wrote:
>>> 
>>> P.S. The code that invokes i2c read/write functions in my project is
>> below:
>>> 
>>> uint8_t check = 0x0F;
>>> struct hal_i2c_master_data pwrite = {
>>>   .address = 0x19,
>>>   .len = 1,
>>>   .buffer = &check
>>> };
>>> 
>>> rc = hal_i2c_master_write(0, &pwrite, 500, 1); // always returns -1
>>> 
>>> uint8_t readCheck = 0;
>>> struct hal_i2c_master_data pdata = {
>>>   .address = 0x19,
>>>   .len = 1,
>>>   .buffer = &readCheck
>>> };
>>> 
>>> rc = hal_i2c_master_read(0, &pdata, 500, 1); // always returns -1
>>> 
>>> 
>>> And the timeouts are coming from /hw/mcu/nordic/nrf52xxx/src/hal_i2c.c
>>> 
>>>       while (!regs->EVENTS_TXDSENT && !regs->EVENTS_ERROR) {
>>>           if (os_time_get() - start > timo) {
>>>               regs->TASKS_STOP = 1;
>>>               goto err;
>>>           }
>>>       }
>>> 
>>> and
>>> 
>>>       while (!regs->EVENTS_RXDREADY && !regs->EVENTS_ERROR) {
>>>           if (os_time_get() - start > timo) {
>>>               regs->SHORTS = TWI_SHORTS_BB_STOP_Msk;
>>>               goto err;
>>>           }
>>>       }
>>> 
>>> On Sun, Apr 9, 2017 at 2:57 PM, Łukasz Wolnik <lu...@gmail.com>
>>> wrote:
>>> 
>>>> Hello,
>>>> 
>>>> I cannot get I2C working on my RedBear BLE Nano 2 board. I connected an
>>>> accelerometer (LIS3DH) but according to gdb the
>> hal_i2c_master_write/read
>>>> functions just time out.
>>>> 
>>>> RedBear BLE Nano 2 pins layout:
>>>> 
>>>> https://www.kickstarter.com/projects/redbearinc/bluetooth-
>>>> 5-ready-ble-module-nano-2-and-blend-2#h:nano-2
>>>> 
>>>> 
>>>> Because rb-nano2's bsp is not configured to support I2C below is what I
>>>> added to mynewt-core:
>>>> 
>>>> https://github.com/limal/incubator-mynewt-core/commit/
>>>> 353fcb10368811a7bbe3e2b10f019fb44dc121f7
>>>> 
>>>> 
>>>> To rule out a possibility that UART_0 is interfering with I2C, that
>> share
>>>> the same pins on rb-nano2, I disabled it and send any logging
>> information
>>>> via Bluetooth to another nano-2 board. Unfortunately the I2C is still
>>>> timing out.
>>>> 
>>>> 9100:[ts=71093744ssb, mod=4 level=1] GAP procedure initiated: advertise;
>>>> disc_mode=2 adv_channel_map=0 own_addr_type=0 adv_filter_policy=0
>>>> adv_itvl_min=50 adv_itvl_max=75 adv_data_len=0
>>>> 9817:[ts=76695268ssb, mod=64 level=1] connection established; status=0
>>>> handle=1 our_ota_addr_type=0 our_ota_addr=91:0a:c0:ff:42:57
>>>> our_id_addr_type=0 our_id_addr=91:0a:c0:ff:42:57 peer_ota_addr_type=0
>>>> peer_ota_addr=0f:0f:0a:0a:0a:0a peer_id_addr_type=0
>>>> peer_id_addr=0f:0f:0a:0a:0a:0a conn_itvl=40 conn_latency=0
>>>> supervision_timeout=256 encrypted=0 authenticated=0 bonded=0
>>>> 9827:[ts=76773388ssb, mod=64 level=1]
>>>> 9828:[ts=76781200ssb, mod=64 level=1] (0): open
>>>> 10188:[ts=79593712ssb, mod=64 level=1] (0): read_check: 1111
>>>> 10190:[ts=79609336ssb, mod=64 level=1] (0): hal_write_rc: -1
>> <-------------
>>>> 10192:[ts=79624960ssb, mod=64 level=1] (0): hal_read_rc: -11
>> <-------------
>>>> 10829:[ts=84601524ssb, mod=64 level=1] (0): read_check: 1111
>>>> 10830:[ts=84609336ssb, mod=64 level=1] (0): hal_write_rc: -1
>> <-------------
>>>> 11469:[ts=89601524ssb, mod=64 level=1] (0): read_check: 1111
>>>> 12109:[ts=94601524ssb, mod=64 level=1] (0): read_check: 1111
>>>> 12749:[ts=99601524ssb, mod=64 level=1] (0): read_check: 1111
>>>> 
>>>> 
>>>> I have tried adding 10k resistors to pull up SDA/SCL lines but to no
>>>> avail. And finally I have also connected the accelerometer to Arduino
>> Uno
>>>> to confirm it's working (I posted Arduino code here:
>>>> http://discuss.redbear.cc/t/i2c-not-working-on-nano2-
>>>> in-arduino-and-apache-mynewt/2106).
>>>> 
>>>> 
>>>> I'm very satisfied with mynewt but being unable to use I2C renders the
>>>> whole project unusable.
>>>> 
>>>> I'd appreciate any help to sort it out and get I2C to work on rb-nano2.
>>>> 
>>>> Kind regards,
>>>> Lukasz
>>>> 
>>>> 
>>>> 
>>>> 
>> 
>> 


Re: I2C not working on nrf52xxx's rb-nano2

Posted by Łukasz Wolnik <lu...@gmail.com>.
Will, thank you very much for a handful of tips. Thanks to you I made it
work!

It turned out that all I had to do was to change I2C's SDA/SCL pins to
unallocated ones.


But at first changing the pins didn't work. I had found a similar issue [1]
on GitHub that resolved it by driving a higher current to SDA/SCL lines:

https://github.com/limal/incubator-mynewt-core/commit/3510504c5cccde7de54086672cde15f945b79a3e

And changing the settings to GPIO_PIN_CNF_DRIVE_H0D1 did the work [2]. My
output was now the correct 0x33 value identifier of the accelerometer.

2:[ts=15624ssb, mod=64 level=1] hal_i2c_master_write rc: 0
3:[ts=23436ssb, mod=64 level=1] readCheck: 51 rc: 0



Later I found out that my pull-up resistors were actually 100 Ohms instead
of 10k. So actually above change to the drive wasn't necessary (it should
stay as GPIO_PIN_CNF_DRIVE_S0D1) but I have to say that fixing hardware
issues using software feels good. Besides RedBear Nano2 has it's own
pull-ups so no resistors are required in the first place.

And just for completeness, I have tried different setups to share the lines
with UART_0 (pins 2, 28, 29 and 30) but none of them worked. So my previous
try with the Bluetooth serial logging must have been sabotaged by the 100
Ohm pull-up resistors. I have a feeling that it's not so easy to disable
UART_0 completely so your advice to change SPI0_CONFIG_SCK_PIN pin might
have been necessary as well. Luckily there's no need to checking it.

Thanks again,
Lukasz

[1]
https://github.com/RedBearLab/nRF51822-Arduino/issues/38#issuecomment-186752735
[2]
https://github.com/limal/incubator-mynewt-core/commit/3510504c5cccde7de54086672cde15f945b79a3e

On Sun, Apr 9, 2017 at 5:30 PM, will sanfilippo <wi...@runtime.io> wrote:

> Just an FYI:
>
> The timeout value is in units of “os ticks”. If you want a timeout of 1
> second you would use OS_TICKS_PER_SEC. A timeout of 5 seconds would be 5 *
> OS_TICKS_PER_SEC and a timeout of 100 msecs would be OS_TICKS_PER_SEC / 10.
>
> For example: hal_i2c_master_write(0, &pwrite, OS_TICKS_PER_SEC, 1);
>
> I am not trying to say that is why it is failing btw; just wanted to point
> it out as the documentation may not be completely clear.
>
> I know you disabled the UART, but something interesting to try might be to
> use a completely different set of GPIO just in case. It also might be
> interesting to change the pkg.yml file in the nano2 directory such that the
> SPI0_CONFIG_SCK_PIN pin does not use pin 2. I doubt that is it but worth a
> try as well.
>
> Unfortunately I do not have a device handy to take a look at this but we
> should be able to figure this out pretty quickly.
>
> Looks like what you did in the code to enable things should work. I
> presume that you stepped through the code and that indeed hal_i2c_init()
> was being called and that it was returning 0.
>
>
> > On Apr 9, 2017, at 7:02 AM, Łukasz Wolnik <lu...@gmail.com>
> wrote:
> >
> > P.S. The code that invokes i2c read/write functions in my project is
> below:
> >
> >  uint8_t check = 0x0F;
> >  struct hal_i2c_master_data pwrite = {
> >    .address = 0x19,
> >    .len = 1,
> >    .buffer = &check
> >  };
> >
> >  rc = hal_i2c_master_write(0, &pwrite, 500, 1); // always returns -1
> >
> >  uint8_t readCheck = 0;
> >  struct hal_i2c_master_data pdata = {
> >    .address = 0x19,
> >    .len = 1,
> >    .buffer = &readCheck
> >  };
> >
> >  rc = hal_i2c_master_read(0, &pdata, 500, 1); // always returns -1
> >
> >
> > And the timeouts are coming from /hw/mcu/nordic/nrf52xxx/src/hal_i2c.c
> >
> >        while (!regs->EVENTS_TXDSENT && !regs->EVENTS_ERROR) {
> >            if (os_time_get() - start > timo) {
> >                regs->TASKS_STOP = 1;
> >                goto err;
> >            }
> >        }
> >
> > and
> >
> >        while (!regs->EVENTS_RXDREADY && !regs->EVENTS_ERROR) {
> >            if (os_time_get() - start > timo) {
> >                regs->SHORTS = TWI_SHORTS_BB_STOP_Msk;
> >                goto err;
> >            }
> >        }
> >
> > On Sun, Apr 9, 2017 at 2:57 PM, Łukasz Wolnik <lu...@gmail.com>
> > wrote:
> >
> >> Hello,
> >>
> >> I cannot get I2C working on my RedBear BLE Nano 2 board. I connected an
> >> accelerometer (LIS3DH) but according to gdb the
> hal_i2c_master_write/read
> >> functions just time out.
> >>
> >> RedBear BLE Nano 2 pins layout:
> >>
> >> https://www.kickstarter.com/projects/redbearinc/bluetooth-
> >> 5-ready-ble-module-nano-2-and-blend-2#h:nano-2
> >>
> >>
> >> Because rb-nano2's bsp is not configured to support I2C below is what I
> >> added to mynewt-core:
> >>
> >> https://github.com/limal/incubator-mynewt-core/commit/
> >> 353fcb10368811a7bbe3e2b10f019fb44dc121f7
> >>
> >>
> >> To rule out a possibility that UART_0 is interfering with I2C, that
> share
> >> the same pins on rb-nano2, I disabled it and send any logging
> information
> >> via Bluetooth to another nano-2 board. Unfortunately the I2C is still
> >> timing out.
> >>
> >> 9100:[ts=71093744ssb, mod=4 level=1] GAP procedure initiated: advertise;
> >> disc_mode=2 adv_channel_map=0 own_addr_type=0 adv_filter_policy=0
> >> adv_itvl_min=50 adv_itvl_max=75 adv_data_len=0
> >> 9817:[ts=76695268ssb, mod=64 level=1] connection established; status=0
> >> handle=1 our_ota_addr_type=0 our_ota_addr=91:0a:c0:ff:42:57
> >> our_id_addr_type=0 our_id_addr=91:0a:c0:ff:42:57 peer_ota_addr_type=0
> >> peer_ota_addr=0f:0f:0a:0a:0a:0a peer_id_addr_type=0
> >> peer_id_addr=0f:0f:0a:0a:0a:0a conn_itvl=40 conn_latency=0
> >> supervision_timeout=256 encrypted=0 authenticated=0 bonded=0
> >> 9827:[ts=76773388ssb, mod=64 level=1]
> >> 9828:[ts=76781200ssb, mod=64 level=1] (0): open
> >> 10188:[ts=79593712ssb, mod=64 level=1] (0): read_check: 1111
> >> 10190:[ts=79609336ssb, mod=64 level=1] (0): hal_write_rc: -1
> <-------------
> >> 10192:[ts=79624960ssb, mod=64 level=1] (0): hal_read_rc: -11
> <-------------
> >> 10829:[ts=84601524ssb, mod=64 level=1] (0): read_check: 1111
> >> 10830:[ts=84609336ssb, mod=64 level=1] (0): hal_write_rc: -1
> <-------------
> >> 11469:[ts=89601524ssb, mod=64 level=1] (0): read_check: 1111
> >> 12109:[ts=94601524ssb, mod=64 level=1] (0): read_check: 1111
> >> 12749:[ts=99601524ssb, mod=64 level=1] (0): read_check: 1111
> >>
> >>
> >> I have tried adding 10k resistors to pull up SDA/SCL lines but to no
> >> avail. And finally I have also connected the accelerometer to Arduino
> Uno
> >> to confirm it's working (I posted Arduino code here:
> >> http://discuss.redbear.cc/t/i2c-not-working-on-nano2-
> >> in-arduino-and-apache-mynewt/2106).
> >>
> >>
> >> I'm very satisfied with mynewt but being unable to use I2C renders the
> >> whole project unusable.
> >>
> >> I'd appreciate any help to sort it out and get I2C to work on rb-nano2.
> >>
> >> Kind regards,
> >> Lukasz
> >>
> >>
> >>
> >>
>
>

Re: I2C not working on nrf52xxx's rb-nano2

Posted by will sanfilippo <wi...@runtime.io>.
Just an FYI:

The timeout value is in units of “os ticks”. If you want a timeout of 1 second you would use OS_TICKS_PER_SEC. A timeout of 5 seconds would be 5 * OS_TICKS_PER_SEC and a timeout of 100 msecs would be OS_TICKS_PER_SEC / 10.

For example: hal_i2c_master_write(0, &pwrite, OS_TICKS_PER_SEC, 1);

I am not trying to say that is why it is failing btw; just wanted to point it out as the documentation may not be completely clear.

I know you disabled the UART, but something interesting to try might be to use a completely different set of GPIO just in case. It also might be interesting to change the pkg.yml file in the nano2 directory such that the SPI0_CONFIG_SCK_PIN pin does not use pin 2. I doubt that is it but worth a try as well.

Unfortunately I do not have a device handy to take a look at this but we should be able to figure this out pretty quickly.

Looks like what you did in the code to enable things should work. I presume that you stepped through the code and that indeed hal_i2c_init() was being called and that it was returning 0.


> On Apr 9, 2017, at 7:02 AM, Łukasz Wolnik <lu...@gmail.com> wrote:
> 
> P.S. The code that invokes i2c read/write functions in my project is below:
> 
>  uint8_t check = 0x0F;
>  struct hal_i2c_master_data pwrite = {
>    .address = 0x19,
>    .len = 1,
>    .buffer = &check
>  };
> 
>  rc = hal_i2c_master_write(0, &pwrite, 500, 1); // always returns -1
> 
>  uint8_t readCheck = 0;
>  struct hal_i2c_master_data pdata = {
>    .address = 0x19,
>    .len = 1,
>    .buffer = &readCheck
>  };
> 
>  rc = hal_i2c_master_read(0, &pdata, 500, 1); // always returns -1
> 
> 
> And the timeouts are coming from /hw/mcu/nordic/nrf52xxx/src/hal_i2c.c
> 
>        while (!regs->EVENTS_TXDSENT && !regs->EVENTS_ERROR) {
>            if (os_time_get() - start > timo) {
>                regs->TASKS_STOP = 1;
>                goto err;
>            }
>        }
> 
> and
> 
>        while (!regs->EVENTS_RXDREADY && !regs->EVENTS_ERROR) {
>            if (os_time_get() - start > timo) {
>                regs->SHORTS = TWI_SHORTS_BB_STOP_Msk;
>                goto err;
>            }
>        }
> 
> On Sun, Apr 9, 2017 at 2:57 PM, Łukasz Wolnik <lu...@gmail.com>
> wrote:
> 
>> Hello,
>> 
>> I cannot get I2C working on my RedBear BLE Nano 2 board. I connected an
>> accelerometer (LIS3DH) but according to gdb the hal_i2c_master_write/read
>> functions just time out.
>> 
>> RedBear BLE Nano 2 pins layout:
>> 
>> https://www.kickstarter.com/projects/redbearinc/bluetooth-
>> 5-ready-ble-module-nano-2-and-blend-2#h:nano-2
>> 
>> 
>> Because rb-nano2's bsp is not configured to support I2C below is what I
>> added to mynewt-core:
>> 
>> https://github.com/limal/incubator-mynewt-core/commit/
>> 353fcb10368811a7bbe3e2b10f019fb44dc121f7
>> 
>> 
>> To rule out a possibility that UART_0 is interfering with I2C, that share
>> the same pins on rb-nano2, I disabled it and send any logging information
>> via Bluetooth to another nano-2 board. Unfortunately the I2C is still
>> timing out.
>> 
>> 9100:[ts=71093744ssb, mod=4 level=1] GAP procedure initiated: advertise;
>> disc_mode=2 adv_channel_map=0 own_addr_type=0 adv_filter_policy=0
>> adv_itvl_min=50 adv_itvl_max=75 adv_data_len=0
>> 9817:[ts=76695268ssb, mod=64 level=1] connection established; status=0
>> handle=1 our_ota_addr_type=0 our_ota_addr=91:0a:c0:ff:42:57
>> our_id_addr_type=0 our_id_addr=91:0a:c0:ff:42:57 peer_ota_addr_type=0
>> peer_ota_addr=0f:0f:0a:0a:0a:0a peer_id_addr_type=0
>> peer_id_addr=0f:0f:0a:0a:0a:0a conn_itvl=40 conn_latency=0
>> supervision_timeout=256 encrypted=0 authenticated=0 bonded=0
>> 9827:[ts=76773388ssb, mod=64 level=1]
>> 9828:[ts=76781200ssb, mod=64 level=1] (0): open
>> 10188:[ts=79593712ssb, mod=64 level=1] (0): read_check: 1111
>> 10190:[ts=79609336ssb, mod=64 level=1] (0): hal_write_rc: -1 <-------------
>> 10192:[ts=79624960ssb, mod=64 level=1] (0): hal_read_rc: -11 <-------------
>> 10829:[ts=84601524ssb, mod=64 level=1] (0): read_check: 1111
>> 10830:[ts=84609336ssb, mod=64 level=1] (0): hal_write_rc: -1 <-------------
>> 11469:[ts=89601524ssb, mod=64 level=1] (0): read_check: 1111
>> 12109:[ts=94601524ssb, mod=64 level=1] (0): read_check: 1111
>> 12749:[ts=99601524ssb, mod=64 level=1] (0): read_check: 1111
>> 
>> 
>> I have tried adding 10k resistors to pull up SDA/SCL lines but to no
>> avail. And finally I have also connected the accelerometer to Arduino Uno
>> to confirm it's working (I posted Arduino code here:
>> http://discuss.redbear.cc/t/i2c-not-working-on-nano2-
>> in-arduino-and-apache-mynewt/2106).
>> 
>> 
>> I'm very satisfied with mynewt but being unable to use I2C renders the
>> whole project unusable.
>> 
>> I'd appreciate any help to sort it out and get I2C to work on rb-nano2.
>> 
>> Kind regards,
>> Lukasz
>> 
>> 
>> 
>> 


Re: I2C not working on nrf52xxx's rb-nano2

Posted by Łukasz Wolnik <lu...@gmail.com>.
P.S. The code that invokes i2c read/write functions in my project is below:

  uint8_t check = 0x0F;
  struct hal_i2c_master_data pwrite = {
    .address = 0x19,
    .len = 1,
    .buffer = &check
  };

  rc = hal_i2c_master_write(0, &pwrite, 500, 1); // always returns -1

  uint8_t readCheck = 0;
  struct hal_i2c_master_data pdata = {
    .address = 0x19,
    .len = 1,
    .buffer = &readCheck
  };

  rc = hal_i2c_master_read(0, &pdata, 500, 1); // always returns -1


And the timeouts are coming from /hw/mcu/nordic/nrf52xxx/src/hal_i2c.c

        while (!regs->EVENTS_TXDSENT && !regs->EVENTS_ERROR) {
            if (os_time_get() - start > timo) {
                regs->TASKS_STOP = 1;
                goto err;
            }
        }

and

        while (!regs->EVENTS_RXDREADY && !regs->EVENTS_ERROR) {
            if (os_time_get() - start > timo) {
                regs->SHORTS = TWI_SHORTS_BB_STOP_Msk;
                goto err;
            }
        }

On Sun, Apr 9, 2017 at 2:57 PM, Łukasz Wolnik <lu...@gmail.com>
wrote:

> Hello,
>
> I cannot get I2C working on my RedBear BLE Nano 2 board. I connected an
> accelerometer (LIS3DH) but according to gdb the hal_i2c_master_write/read
> functions just time out.
>
> RedBear BLE Nano 2 pins layout:
>
> https://www.kickstarter.com/projects/redbearinc/bluetooth-
> 5-ready-ble-module-nano-2-and-blend-2#h:nano-2
>
>
> Because rb-nano2's bsp is not configured to support I2C below is what I
> added to mynewt-core:
>
> https://github.com/limal/incubator-mynewt-core/commit/
> 353fcb10368811a7bbe3e2b10f019fb44dc121f7
>
>
> To rule out a possibility that UART_0 is interfering with I2C, that share
> the same pins on rb-nano2, I disabled it and send any logging information
> via Bluetooth to another nano-2 board. Unfortunately the I2C is still
> timing out.
>
> 9100:[ts=71093744ssb, mod=4 level=1] GAP procedure initiated: advertise;
> disc_mode=2 adv_channel_map=0 own_addr_type=0 adv_filter_policy=0
> adv_itvl_min=50 adv_itvl_max=75 adv_data_len=0
> 9817:[ts=76695268ssb, mod=64 level=1] connection established; status=0
> handle=1 our_ota_addr_type=0 our_ota_addr=91:0a:c0:ff:42:57
> our_id_addr_type=0 our_id_addr=91:0a:c0:ff:42:57 peer_ota_addr_type=0
> peer_ota_addr=0f:0f:0a:0a:0a:0a peer_id_addr_type=0
> peer_id_addr=0f:0f:0a:0a:0a:0a conn_itvl=40 conn_latency=0
> supervision_timeout=256 encrypted=0 authenticated=0 bonded=0
> 9827:[ts=76773388ssb, mod=64 level=1]
> 9828:[ts=76781200ssb, mod=64 level=1] (0): open
> 10188:[ts=79593712ssb, mod=64 level=1] (0): read_check: 1111
> 10190:[ts=79609336ssb, mod=64 level=1] (0): hal_write_rc: -1 <-------------
> 10192:[ts=79624960ssb, mod=64 level=1] (0): hal_read_rc: -11 <-------------
> 10829:[ts=84601524ssb, mod=64 level=1] (0): read_check: 1111
> 10830:[ts=84609336ssb, mod=64 level=1] (0): hal_write_rc: -1 <-------------
> 11469:[ts=89601524ssb, mod=64 level=1] (0): read_check: 1111
> 12109:[ts=94601524ssb, mod=64 level=1] (0): read_check: 1111
> 12749:[ts=99601524ssb, mod=64 level=1] (0): read_check: 1111
>
>
> I have tried adding 10k resistors to pull up SDA/SCL lines but to no
> avail. And finally I have also connected the accelerometer to Arduino Uno
> to confirm it's working (I posted Arduino code here:
> http://discuss.redbear.cc/t/i2c-not-working-on-nano2-
> in-arduino-and-apache-mynewt/2106).
>
>
> I'm very satisfied with mynewt but being unable to use I2C renders the
> whole project unusable.
>
> I'd appreciate any help to sort it out and get I2C to work on rb-nano2.
>
> Kind regards,
> Lukasz
>
>
>
>