Hello, i have Nrf52840, here is the code for PWM
APP_PWM_INSTANCE(PWM1, 1);
uint8_t cBuzzer::_PWM_init(uint32_t Time_uS){
app_pwm_uninit(&PWM1);
app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_1CH(Time_uS, Buzzer_Pin);
/* Initialize and enable PWM. */
if (app_pwm_init(&PWM1, &pwm1_cfg, NULL) != Successfully) {return Error ;}
app_pwm_enable(&PWM1);
return Successfully; }
void cBuzzer::Set_DutyCycle(uint8_t xDuty_Cycle)
{
while (app_pwm_channel_duty_set(&PWM1, 0, xDuty_Cycle) == NRF_ERROR_BUSY);
Current_Duty_Cycle = xDuty_Cycle;
}
PWM is working Perfectly.
here is the code for TWI
static const nrf_drv_twi_t I2C_master_Instance = NRF_DRV_TWI_INSTANCE(0);
uint8_t cI2C::inilization()
{
ret_code_t ret;
const nrf_drv_twi_config_t config =
{
.scl = _SCL_PinNumber,
.sda = _SDA_PinNumber,
.frequency = NRF_TWI_FREQ_100K,
.interrupt_priority = APP_IRQ_PRIORITY_HIGH
};
do
{
ret = nrf_drv_twi_init(&I2C_master_Instance, &config, NULL, NULL);
if (NRF_SUCCESS != ret)
{
break;
}
nrf_drv_twi_enable(&I2C_master_Instance);
} while (0);
_Error = ret;
return ret;
}
uint8_t cI2C::Write(uint8_t Slave_addr, uint8_t * Data_TO_Write, uint32_t Number_of_bytes_TO_Writes)
{
ret_code_t ret_code;
ret_code = nrf_drv_twi_tx(&I2C_master_Instance, Slave_addr, Data_TO_Write, Number_of_bytes_TO_Writes, false);
_Error = ret_code;
return ret_code;
}
uint8_t cI2C::Read(uint8_t Slave_addr, uint8_t Address_to_Read ,uint8_t * Data_TO_Read)
{
ret_code_t ret_code;
ret_code = Write(Slave_addr, &Address_to_Read,1);
if (ret_code != NRF_SUCCESS)
{
_Error = ret_code;
return ret_code;
}
ret_code = nrf_drv_twi_rx(&I2C_master_Instance, Slave_addr, Data_TO_Read, 1);
_Error = ret_code;
return ret_code;
}
TWI is also working.
when i combine the both then PWM is working but TWI is not. i connect the BME280 temperature sensor with TWI. i thought may be both of library share the same timer ? any solution will be appreciated.