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

nRF52 bug

Hello!

Apologies in advance for my english.

I already asked a similar question, here is the link to it

When trying to connect a PWM driver PCA9685, I ran into problems that are software

Here are my user files that I used

I also use the development kit nRF52-DK & SDK17

My problem is this:

I have a function

void pca9685_write_u8 (uint8_t reg,uint8_t val)
{
  uint8_t buff[2] = {reg,val};
    nrf_drv_twi_tx(&m_pcah.twi_handle,m_pcah.device_address,buff, 2, false);
}

I think it's not worth explaining what she does.I use it quite often to initialize a PWM driver. But if I copy the body of the function and replace it at the place of its use, then everything stops working. For example; 

void pca9685_sleep(void)
{
	// Read the current state of the mode 1 register.
	uint8_t mode1_reg;
	 pca9685_read_u8( PCA9685_REGISTER_MODE1, &mode1_reg);

	// Don't write the restart bit back and set the sleep bit.
	PCA9685_CLEAR_BIT_MASK(mode1_reg, PCA9685_REGISTER_MODE1_RESTART);
	PCA9685_SET_BIT_MASK(mode1_reg, PCA9685_REGISTER_MODE1_SLEEP);
	 //pca9685_write_u8( PCA9685_REGISTER_MODE1, mode1_reg);
    uint8_t buff[2] = {PCA9685_REGISTER_MODE1, mode1_reg};
    nrf_drv_twi_tx(&m_pcah.twi_handle,m_pcah.device_address,buff, 2, false);
}

And that is not all. All my code looks terrible. But this is the only thing that I got to run through trial and error.

I also collected the above sending function in a similar way 

void pca9685_write_u8 (pca9685_handle_t *m_handle,uint8_t reg,uint8_t val)
{
  uint8_t buff[2] = {reg,val};
    nrf_drv_twi_tx(&m_handle->twi_handle,m_handle->device_address,buff, 2, false);
}

but you guessed it it didn't work

This is the first time I come across such a thing. Please help me

Parents
  • Hello,

    Could you please include the file (main.c maybe?) where these functions are being called as well? I would like to see your TWI initialization.

    Also, please add error checking like Jared suggested your other ticket. This makes it much easier to catch errors.

    err_code = nrf_drv_twi_tx(&m_twi, slave_addr, reg, 1, false);
    APP_ERROR_CHECK(err_code); // Check if error_code == NRF_SUCCESS before continuing

Reply
  • Hello,

    Could you please include the file (main.c maybe?) where these functions are being called as well? I would like to see your TWI initialization.

    Also, please add error checking like Jared suggested your other ticket. This makes it much easier to catch errors.

    err_code = nrf_drv_twi_tx(&m_twi, slave_addr, reg, 1, false);
    APP_ERROR_CHECK(err_code); // Check if error_code == NRF_SUCCESS before continuing

Children
Related