cancel
Showing results for 
Search instead for 
Did you mean: 

I2C slave not ACK

Nickname925_O
Associate II
Posted on January 14, 2014 at 21:59

</p>

I have an issue with STM32F0 Discovery. I am using I2C1 (like master) to send start condition and address to I2C2 (slave) on the same board. I am able to generate propertly the signal but the IC2 (slave) is not able to generate an ACK on 9th clk

What's wrong? Here my code about the setup:

</div> </div> </td> </tr> </tbody> </table>

void set_I2C(void){

  GPIO_InitTypeDef GPIO_InitStructure;

  I2C_InitTypeDef I2C_InitStructure;

  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);

     RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);

     /* Configure the I2C clock source. The clock is derived from the HSI */

     RCC_I2CCLKConfig(RCC_I2C1CLK_SYSCLK);

     GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_1);

     GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_1);

     //Configure pins: SCL and SDA ------------------

     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;

     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

     GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

     GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;

     GPIO_Init(GPIOB, &GPIO_InitStructure);

     I2C_DeInit(I2C1);

     I2C_Cmd(I2C1, DISABLE);

     I2C_InitStructure.I2C_AnalogFilter = I2C_AnalogFilter_Enable;

     I2C_InitStructure.I2C_DigitalFilter = 0x00;

     I2C_InitStructure.I2C_OwnAddress1 = 0x40;

     I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;

     I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;

     //I2C_InitStructure.I2C_Timing = 0xA0120227;

     //I2C_InitStructure.I2C_Timing = 0x20310A0D;

     I2C_InitStructure.I2C_Timing =0xB0420F13; //100KHz (see page 529 - table 73 in the manual reference)

     I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;

     I2C_Init(I2C1, &I2C_InitStructure);

     //I2C_NumberOfBytesConfig(I2C1, 8);

     //I2C_AutoEndCmd(I2C1, ENABLE);

     I2C_Cmd(I2C1, ENABLE);

     //I2C_ITConfig(I2C1, I2C_FLAG_TXE, ENABLE);

     //Set up of I2C2

  RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C2, ENABLE);

     RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);

        // Configure the I2C clock source. The clock is derived from the HSI

        //RCC_I2CCLKConfig(RCC_PCLKConfig());

        GPIO_PinAFConfig(GPIOB, GPIO_PinSource11, GPIO_AF_1);

        GPIO_PinAFConfig(GPIOB, GPIO_PinSource10, GPIO_AF_1);

        //Configure pins: SCL and SDA ------------------

        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_10;

        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

        GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

        GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;

        GPIO_Init(GPIOB, &GPIO_InitStructure);

        I2C_DeInit(I2C2);

        I2C_Cmd(I2C2, DISABLE);

        I2C_InitStructure.I2C_AnalogFilter = I2C_AnalogFilter_Disable;

        I2C_InitStructure.I2C_DigitalFilter = 0x00;

        I2C_InitStructure.I2C_OwnAddress1 = 0x30; // MPU6050 7-bit adress = 0x68, 8-bit adress = 0xD0;

     I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;

     I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;

     I2C_InitStructure.I2C_Timing =0xB0420F13;

     I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;

        I2C_Init(I2C2, &I2C_InitStructure);

        //I2C_NumberOfBytesConfig(I2C1, 8);

        //I2C_AutoEndCmd(I2C1, ENABLE);

     I2C_Cmd(I2C2, ENABLE);

     /*I2C2->CR1&=~I2C_OAR1_OA1EN;

    I2C2->CR1&=~I2C_OAR2_OA2EN;

    I2C2->CR1|=I2C_CR1_SBC; //Slave Byte Control

    I2C_GeneralCallCmd(I2C2, ENABLE);

    I2C2->CR1|=I2C_CR1_ADDRIE;

    I2C2->CR2&=~I2C_CR2_NACK;

    I2C2->OAR1|=I2C_OAR1_OA1EN;*/

         /*I2C_Cmd(I2C2, DISABLE);

          I2C2->CR1|=I2C_CR1_SBC; //Slave Byte Control

          I2C_Cmd(I2C2, ENABLE);

          I2C_StretchClockCmd(I2C1, DISABLE);*/

    I2C_ITConfig(I2C2, I2C_AcknowledgedAddress_7bit, ENABLE);

    /*I2C_ITConfig(I2C2, I2C_ISR_ADDR, ENABLE);

    I2C_ITConfig(I2C2, IS_I2C_ACKNOWLEDGE_ADDRESS(0x30), ENABLE);

    I2C_AcknowledgeConfig(I2C2, ENABLE);

*/

      NVIC_InitTypeDef NVIC_InitStructure;

     /* Configure the I2C2 interrupt priority */

     NVIC_InitStructure.NVIC_IRQChannel = I2C2_IRQn;

     NVIC_InitStructure.NVIC_IRQChannelPriority=1;

     NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

     NVIC_Init(&NVIC_InitStructure);

}

#i2c-stm32f0discovery
7 REPLIES 7
chen
Associate II
Posted on January 15, 2014 at 11:04

Hi

I am not familiar with the F0 Discovery board. If it is like the F4 Discovery board, the I2C device has a reset line controlled from the STM32.

You must take the device out of reset before you can communicate with it.

Nickname925_O
Associate II
Posted on January 16, 2014 at 23:38

Hi,

can you tell me where is the reset line for the discovery F4? In this way I can try to find out that line in discoveryF0.

chen
Associate II
Posted on January 17, 2014 at 10:45

Hi

''can you tell me where is the reset line for the discovery F4? In this way I can try to find out that line in discoveryF0. ''

Yes but it is not going to help you.

There is no guarantee the F0 board is wired in the same way as the F4 board.

Download the datasheet for the F0 discovery board - the circuit diagram/schematic should be in there. Find the I2C device on the circuit diagram/schematic and see how it is connected to the STM32F0.

Nickname925_O
Associate II
Posted on January 17, 2014 at 17:03

Hi,

I've just seen the F0_Discovery board and I think it's not connected to reset line (if you want to have a look I have to tell you that I am using PB10 and PB11 as I2C2).

I hope to read you soon :)

chen
Associate II
Posted on January 17, 2014 at 17:45

Hi

OK, so I have just looked at the schematic for the F0 Discovery.

It does not have an on board I2C device.

'' If it is like the F4 Discovery board, the I2C device has a reset line controlled from the STM32.''

is no relevant in your case!

The F0 Discovery is NOT like the F4 Discovery.

It appears in another thread you have this working.

Nickname925_O
Associate II
Posted on January 17, 2014 at 17:57

I am asking in another post because some weeks ago nobody seemed to note my old post :)

Have you ever used the I2C in STM32F0?

Nickname925_O
Associate II
Posted on January 17, 2014 at 17:58

I am asking in another post because some weeks ago nobody seemed to note my old post :)

Have you ever used the I2C in STM32F0?