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 <[email protected]> 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 <[email protected]> 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 <[email protected]>
>> 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 <[email protected]>
>>> 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
>>>> 
>>>> 
>>>> 
>>>> 
>> 
>> 

Reply via email to