cancel
Showing results for 
Search instead for 
Did you mean: 

I2C Problem - STM32F4 DISCOVERY

mrblueblue
Associate II
Posted on August 03, 2016 at 08:33

Hello everyone. I have searched the forums but could not figure this out.

I am using the STM32 F4 Discovery, AC6 (System Workbench), and the standard peripheral libraries.

On the Discovery Kit PA8 (pin 100) should be SCL,  PC9 (pin 99) should be SDA.

1.) The problem is that before I call  I2C3_Init() both SDA and SCL lines are high as expected.  But, after I call  I2C3_Init();  The clock line is held low and the SDA is high.  This doesn't look right so I wanted to see if there was anything obvious that I was doing wrong.

#include ''stm32f4xx.h''

#include ''stm32f4xx_gpio.h''

void I2C3_Init(){

    /* Enable Peripheral Clock for I2C3 */

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C3, ENABLE);

    /* Enable Peripheral Clock for SDA (PC9) SCL (PA8)  */

    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOC  , ENABLE);

    GPIO_InitTypeDef GPIO_InitStructure_1;

    GPIO_InitStructure_1.GPIO_Pin = GPIO_Pin_8;

    GPIO_InitStructure_1.GPIO_Mode = GPIO_Mode_AF;

    GPIO_InitStructure_1.GPIO_Speed = GPIO_Speed_2MHz;

    GPIO_InitStructure_1.GPIO_OType = GPIO_OType_OD;

    GPIO_InitStructure_1.GPIO_PuPd = GPIO_PuPd_NOPULL;

    GPIO_Init(GPIOA, &GPIO_InitStructure_1);

    GPIO_InitTypeDef GPIO_InitStructure_2;

    GPIO_InitStructure_2.GPIO_Pin = GPIO_Pin_9;

    GPIO_InitStructure_2.GPIO_Mode = GPIO_Mode_AF;

    GPIO_InitStructure_2.GPIO_Speed = GPIO_Speed_2MHz;

    GPIO_InitStructure_2.GPIO_OType = GPIO_OType_OD;

    GPIO_InitStructure_2.GPIO_PuPd = GPIO_PuPd_NOPULL;

    GPIO_Init(GPIOC, &GPIO_InitStructure_2);

    /* Connect I2C1 pins to AF */

    GPIO_PinAFConfig(GPIOA, GPIO_Pin_8, GPIO_AF_I2C3);

    GPIO_PinAFConfig(GPIOC, GPIO_Pin_9, GPIO_AF_I2C3);

    /* configure I2C1 */

    I2C_InitTypeDef I2C_InitStruct;

    I2C_InitStruct.I2C_ClockSpeed = 100000;

    I2C_InitStruct.I2C_Mode = I2C_Mode_I2C;

    I2C_InitStruct.I2C_DutyCycle = I2C_DutyCycle_2;

    I2C_InitStruct.I2C_OwnAddress1 = 0x00;

    I2C_InitStruct.I2C_Ack = I2C_Ack_Disable;

    I2C_InitStruct.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;

    I2C_Init(I2C1, &I2C_InitStruct);

    /* enable I2C3 */

    I2C_Cmd(I2C3, ENABLE);

}

int main(void)

{

I2C1_Init();

    // Even at this point things don't look right.

    while(1)

    {

    I2C_GenerateSTART(I2C3, ENABLE);

    I2C_Send7bitAddress(I2C3, 0x41, I2C_Direction_Transmitter);

    I2C_SendData(I2C3, 0xAA);

    }

4 REPLIES 4
mrblueblue
Associate II
Posted on August 04, 2016 at 05:23

Anyone?  I am totally stuck here.

Thanks.

mrblueblue
Associate II
Posted on August 07, 2016 at 06:03

Can someone please tell me me what is wrong with my init()? Am I missing something?

Thank you.

Rosiney Silva
Associate II
Posted on August 07, 2016 at 17:27

In main

function

I2C1_Init();  ?

should not be I2C3_Init (); ?

LMI2
Lead
Posted on August 07, 2016 at 18:46

You have one answer. But it is weekend, so there probably will be more on monday.

By the way, IIC protocol is easy, you know what the signals should be, you can drive pins ''manually'' bit banging.

Then there was the all too common problem with logins in the morning.