Skip to content

Instantly share code, notes, and snippets.

Created November 13, 2017 09:14
Show Gist options
  • Save anonymous/f20b78d4280f1de81a803458c418399c to your computer and use it in GitHub Desktop.
Save anonymous/f20b78d4280f1de81a803458c418399c to your computer and use it in GitHub Desktop.
TWI Initialization
bool init_twi (void) {
// Variables
uint32_t err_code;
//NRF_LOG_INFO("twi_init: Initializing TWI....\r\n");
// Main parameters to configure the TWI communication
const nrf_drv_twi_config_t twi_mpu_config = {
.scl = TWI_SCL_PIN,
.sda = TWI_SDA_PIN,
.frequency = NRF_TWI_FREQ_400K,
.interrupt_priority = APP_IRQ_PRIORITY_LOW
};
// Initialize the TWI driver
err_code = nrf_drv_twi_init(&m_twi_instance, &twi_mpu_config, twi_event_handler, NULL);
// Check if error
if ( err_code != NRF_SUCCESS ) return false;
// Enable the TWI driver
nrf_drv_twi_enable(&m_twi_instance);
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment