Skip to content

Commit 3edfc77

Browse files
author
Marcus Chang
committed
Fix bug in Nordic SDK 14.2 I2C driver
Interrupts were not enabled before transmitting data leading to missed interrupts.
1 parent 5fcc961 commit 3edfc77

File tree

1 file changed

+30
-11
lines changed
  • targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/drivers_nrf/twi_master

1 file changed

+30
-11
lines changed

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/drivers_nrf/twi_master/nrf_drv_twi.c

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -558,12 +558,10 @@ static ret_code_t twi_tx_start_transfer(twi_control_block_t * p_cb,
558558
p_cb->bytes_transferred = 0;
559559
p_cb->error = false;
560560

561-
// In case TWI is suspended resume its operation.
562-
nrf_twi_task_trigger(p_twi, NRF_TWI_TASK_RESUME);
563-
nrf_twi_task_trigger(p_twi, NRF_TWI_TASK_STARTTX);
564-
565-
(void)twi_send_byte(p_twi, p_data, length, &p_cb->bytes_transferred, no_stop);
566-
561+
/**
562+
* 4/23/2018 Arm Mbed modification to Nordic SDK 14.2.
563+
* Interrupts must be enabled before transmitting the first byte in asynchronous mode.
564+
*/
567565
if (p_cb->handler)
568566
{
569567
p_cb->int_mask = NRF_TWI_INT_STOPPED_MASK |
@@ -572,7 +570,18 @@ static ret_code_t twi_tx_start_transfer(twi_control_block_t * p_cb,
572570
NRF_TWI_INT_RXDREADY_MASK;
573571
nrf_twi_int_enable(p_twi, p_cb->int_mask);
574572
}
575-
else
573+
574+
// In case TWI is suspended resume its operation.
575+
nrf_twi_task_trigger(p_twi, NRF_TWI_TASK_RESUME);
576+
nrf_twi_task_trigger(p_twi, NRF_TWI_TASK_STARTTX);
577+
578+
(void)twi_send_byte(p_twi, p_data, length, &p_cb->bytes_transferred, no_stop);
579+
580+
/**
581+
* 4/23/2018 Arm Mbed modification to Nordic SDK 14.2.
582+
* Interrupts must be enabled before transmitting the first byte in asynchronous mode.
583+
*/
584+
if (p_cb->handler == NULL)
576585
{
577586
while ((hw_timeout > 0) &&
578587
twi_transfer(p_twi,
@@ -632,10 +641,11 @@ static ret_code_t twi_rx_start_transfer(twi_control_block_t * p_cb,
632641
{
633642
nrf_twi_shorts_set(p_twi, NRF_TWI_SHORT_BB_SUSPEND_MASK);
634643
}
635-
// In case TWI is suspended resume its operation.
636-
nrf_twi_task_trigger(p_twi, NRF_TWI_TASK_RESUME);
637-
nrf_twi_task_trigger(p_twi, NRF_TWI_TASK_STARTRX);
638644

645+
/**
646+
* 4/23/2018 Arm Mbed modification to Nordic SDK 14.2.
647+
* Interrupts must be enabled before transmitting the first byte in asynchronous mode.
648+
*/
639649
if (p_cb->handler)
640650
{
641651
p_cb->int_mask = NRF_TWI_INT_STOPPED_MASK |
@@ -644,7 +654,16 @@ static ret_code_t twi_rx_start_transfer(twi_control_block_t * p_cb,
644654
NRF_TWI_INT_RXDREADY_MASK;
645655
nrf_twi_int_enable(p_twi, p_cb->int_mask);
646656
}
647-
else
657+
658+
// In case TWI is suspended resume its operation.
659+
nrf_twi_task_trigger(p_twi, NRF_TWI_TASK_RESUME);
660+
nrf_twi_task_trigger(p_twi, NRF_TWI_TASK_STARTRX);
661+
662+
/**
663+
* 4/23/2018 Arm Mbed modification to Nordic SDK 14.2.
664+
* Interrupts must be enabled before transmitting the first byte in asynchronous mode.
665+
*/
666+
if (p_cb->handler == NULL)
648667
{
649668
while ((hw_timeout > 0) &&
650669
twi_transfer(p_twi,

0 commit comments

Comments
 (0)