This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

TWI + softDevice s132 on nRF52832 not works

Hi guys, I'm working on an nRF52832 chip (PCA 10040) with softdevice s132 (v3.0.0) and I'm facing with a big problem; in my project I use an spi (instance index 0) and an i2c bus (instance index 1) with a UART, used for debug (instance index 0). Both spi and uart work perfectly but the i2c (or twi) doesn't work at all. I read on this forum many other people had problems like this trying to work with i2c and softdevice so I'm wondering if anyone could help me. This is my simple code for the init:

const nrf_drv_twi_t i2c_bus_instance = NRF_DRV_TWI_INSTANCE(1);



uint32_t err_code;
    const nrf_drv_twi_config_t twi_config = {
   .scl                = RACE_I2C_CLOCK,
   .sda                = RACE_I2C_DATA,
   .frequency          = NRF_TWI_FREQ_100K,
   .interrupt_priority = APP_IRQ_PRIORITY_HIGH
};
/* i2c_event_handler è necessaria perché in caso contrario le istruzioni I2C diventerebbero bloccanti */
err_code = nrf_drv_twi_init(&i2c_bus_instance, &twi_config, i2c_event_handler, NULL);
APP_ERROR_CHECK(err_code);

nrf_drv_twi_enable(&i2c_bus_instance);        

for the i2c handler:

    if ((p_event->type == NRF_DRV_TWI_EVT_DONE) && (p_event->xfer_desc.type == NRF_DRV_TWI_XFER_TX))
    {
        xfer_completed = true;
        set_gpio_pin(TEST_PIN, false);  
    }
else
    {
       xfer_completed = false;
    }

and the main:

    uint32_t err_code;
bool     erase_bonds;
uint8_t  data[2] = {DRV2604L_MODE_REG, 0x00};

// Initialize.
err_code = NRF_LOG_INIT(NULL);
APP_ERROR_CHECK(err_code);

timers_init(); 
buttons_leds_init(&erase_bonds);

gpio_init();    

ble_stack_init();
peer_manager_init(erase_bonds);
if (erase_bonds == true)
{
    NRF_LOG_INFO("Bonds erased!\r\n");
}
gap_params_init();
advertising_init();
services_init();
conn_params_init();


// Start execution.
NRF_LOG_INFO("Template started\r\n");
application_timers_start();
err_code = ble_advertising_start(BLE_ADV_MODE_FAST);
APP_ERROR_CHECK(err_code);

spi_init(DISPLAY);        
i2c_init(); 
   

// Abilitazione tutte le sorgenti di alimentazione 
delay_ms(2000u);
set_gpio_pin(RACE_VCC_ENABLE_PIN, true);
set_gpio_pin(RACE_5V_ENABLE_PIN, true);
NRF_LOG_INFO("\r\n>>>>> START 'VCC' AND '+5V' VOLTAGE\r\n");


// Test su display
delay_ms(2000u);    
drawInit();              // Init display 
NRF_LOG_INFO("\r\n>>>>> CHECK DISPLAY - MUST BE COMPLETELY CLEAR !!!!\r\n");
delay_ms(4000u);
drawCheckDisplayPixel(); // Controllo pixel display 
NRF_LOG_INFO("\r\n>>>>> CHECK DISPLAY - MUST BE COMPLETELY BLACK !!!!\r\n");
delay_ms(4000u);
drawInit();              // Pulizia display

// Test su vibrazione
//delay_ms(2000u);   

set_gpio_pin(TEST_PIN, true);    

   
err_code = nrf_drv_twi_tx(&i2c_bus_instance, 0x5A, data, 2, false);
APP_ERROR_CHECK(err_code);



// Enter main loop.
for (;;)
{
    if (NRF_LOG_PROCESS() == false)
    {
        power_manage();
    }
}

Please, could anyone suggest me any solution to solve my i2c problem ? Regards

Parents
  • anything works? how is this a problem?

    Try run only the TWI code in another project and see if it works. Connect a logic analyzer or oscilloscope to the pins to see if anything happens on the hardware level. The problem may be that you use pins on PCA10040 that are used for something else on the board, then it will not work no matter if the SoftDevice is used or not. Take a look at the back of the board to see which pins are used for what.

Reply
  • anything works? how is this a problem?

    Try run only the TWI code in another project and see if it works. Connect a logic analyzer or oscilloscope to the pins to see if anything happens on the hardware level. The problem may be that you use pins on PCA10040 that are used for something else on the board, then it will not work no matter if the SoftDevice is used or not. Take a look at the back of the board to see which pins are used for what.

Children
No Data
Related