I2C err

Discussions and support about ChibiOS/HAL, the MCU Hardware Abstraction Layer.
BreederBai
Posts: 19
Joined: Tue Aug 14, 2018 3:57 pm

I2C err

Postby BreederBai » Fri Sep 07, 2018 6:00 am

The system triggers a watchdog restart when using I2C to read and write.And display the following content in the debug port.

Code: Select all

PANIC [mag_ist8310] i2c_lld_master_transmit_timeout

Core registers:
CONTROL 2
IPSR 0
APSR 600000



The code I wrote is as follows,

Code: Select all

static auto& I2C = I2CD1;
int write(std::uint8_t reg, std::uint8_t val)
{
    const std::array<uint8_t, 2> tx{ reg, val};

    return int(i2cMasterTransmitTimeout(&I2C,
                               HAL_COMPASS_IST8310_I2C_ADDR,
                               tx.data(),
                               tx.size(),
                               nullptr,
                               0,
                               TIME_INFINITE));
}

User avatar
Giovanni
Site Admin
Posts: 14455
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: I2C err

Postby Giovanni » Fri Sep 07, 2018 7:44 am

Are I2C pins programmed in the right way? do you have external pull up resistors? there are several possible causes for the I2C to hang, how you call that function is not very important.

Giovanni

BreederBai
Posts: 19
Joined: Tue Aug 14, 2018 3:57 pm

Re: I2C err

Postby BreederBai » Fri Sep 07, 2018 8:42 am

Giovanni wrote:Are I2C pins programmed in the right way? do you have external pull up resistors? there are several possible causes for the I2C to hang, how you call that function is not very important.

Giovanni


Hello, I am using PB6, 7 pins, configured as ‘Alternate Open Drain output 2MHz’ Mode, initial level is high.

Code: Select all

#define VAL_GPIOBCRL            0xEE222888
#define VAL_GPIOBCRH            0x88488A48
#define VAL_GPIOBODR            ((1 << 6) | (1 << 7))

The submission number of the ChibiOS I am using is 7d187a140e64db297eb5ef788f0f5dc0dd0d3fde, November 21, 2016 4:52 PM.
I have an external pull-up resistor and the pull-up resistor is 1K.

Polux
Posts: 27
Joined: Thu Apr 28, 2016 11:52 am
Been thanked: 7 times

Re: I2C err

Postby Polux » Fri Sep 07, 2018 11:10 am

Resistors needed on both I2C pins.

Angelo

BreederBai
Posts: 19
Joined: Tue Aug 14, 2018 3:57 pm

Re: I2C err

Postby BreederBai » Fri Sep 07, 2018 12:05 pm

Polux wrote:Resistors needed on both I2C pins.

Angelo


Sorry, it is my typo,that both pins have pull-up resistors.

User avatar
Giovanni
Site Admin
Posts: 14455
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: I2C err

Postby Giovanni » Fri Sep 07, 2018 12:13 pm

Is the driver started?

Giovanni

BreederBai
Posts: 19
Joined: Tue Aug 14, 2018 3:57 pm

Re: I2C err

Postby BreederBai » Fri Sep 07, 2018 12:34 pm

Giovanni wrote:Is the driver started?

Giovanni


yes

BreederBai
Posts: 19
Joined: Tue Aug 14, 2018 3:57 pm

Re: I2C err

Postby BreederBai » Fri Sep 07, 2018 2:41 pm

Giovanni wrote:Is the driver started?

Giovanni


This is my code to enable I2C bus.

Code: Select all

static const I2CConfig I2CCfg =
{
    OPMODE_I2C,
    400000,
    FAST_DUTY_CYCLE_2
};

Code: Select all

i2cStart(&I2CD1,&I2CCfg);

steved
Posts: 825
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 12 times
Been thanked: 135 times

Re: I2C err

Postby steved » Fri Sep 07, 2018 5:29 pm

Which processor?

BreederBai
Posts: 19
Joined: Tue Aug 14, 2018 3:57 pm

Re: I2C err

Postby BreederBai » Sat Sep 08, 2018 1:18 am

steved wrote:Which processor?


STM32F105RCT6


Return to “ChibiOS/HAL”

Who is online

Users browsing this forum: No registered users and 8 guests